-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make input, meta and output optional
- Loading branch information
1 parent
8a4d0c5
commit f1e3d6e
Showing
8 changed files
with
133 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
examples/ | ||
examples/with-nextjs/ | ||
examples/with-express/ | ||
examples/with-interop/ | ||
examples/with-serverless/ | ||
examples/with-fastify/ | ||
examples/with-nuxtjs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@dokploy/trpc-openapi", | ||
"version": "0.0.1", | ||
"version": "0.0.4", | ||
"description": "tRPC OpenAPI", | ||
"author": "Mauricio Siu <[email protected]>", | ||
"private": false, | ||
|
@@ -13,9 +13,9 @@ | |
"openapi", | ||
"swagger" | ||
], | ||
"homepage": "https://github.com/jlalmes/trpc-openapi", | ||
"repository": "github:jlalmes/trpc-openapi", | ||
"bugs": "https://github.com/jlalmes/trpc-openapi/issues", | ||
"homepage": "https://github.com/dokploy/trpc-openapi", | ||
"repository": "github:dokploy/trpc-openapi", | ||
"bugs": "https://github.com/dokploy/trpc-openapi/issues", | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"workspaces": [ | ||
|
@@ -24,6 +24,11 @@ | |
"examples/with-express", | ||
"examples/with-interop" | ||
], | ||
"files": [ | ||
"dist", | ||
"README.md", | ||
"LICENSE" | ||
], | ||
"scripts": { | ||
"test": "tsc --noEmit && jest --verbose", | ||
"build": "rimraf dist && tsc -p tsconfig.build.json" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,92 @@ | ||
import { Procedure, ProcedureParams, Router } from '@trpc/server'; | ||
import type { RootConfig } from '@trpc/server/dist/core/internals/config'; | ||
import { TRPC_ERROR_CODE_KEY } from '@trpc/server/rpc'; | ||
import type { RouterDef } from '@trpc/server/src/core/router'; | ||
import { OpenAPIV3 } from 'openapi-types'; | ||
import { ZodIssue } from 'zod'; | ||
import { Procedure, ProcedureParams, Router } from "@trpc/server"; | ||
import type { RootConfig } from "@trpc/server/dist/core/internals/config"; | ||
import { TRPC_ERROR_CODE_KEY } from "@trpc/server/rpc"; | ||
import type { RouterDef } from "@trpc/server/src/core/router"; | ||
import { OpenAPIV3 } from "openapi-types"; | ||
import { ZodIssue } from "zod"; | ||
|
||
export type OpenApiMethod = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE'; | ||
export type OpenApiMethod = "GET" | "POST" | "PATCH" | "PUT" | "DELETE"; | ||
|
||
type TRPCMeta = Record<string, unknown>; | ||
|
||
export type OpenApiContentType = | ||
| 'application/json' | ||
| 'application/x-www-form-urlencoded' | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
| (string & {}); | ||
| "application/json" | ||
| "application/x-www-form-urlencoded" | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
| (string & {}); | ||
|
||
export type OpenApiMeta<TMeta = TRPCMeta> = TMeta & { | ||
openapi?: { | ||
enabled?: boolean; | ||
method: OpenApiMethod; | ||
path: `/${string}`; | ||
summary?: string; | ||
description?: string; | ||
protect?: boolean; | ||
tags?: string[]; | ||
headers?: (OpenAPIV3.ParameterBaseObject & { name: string; in?: 'header' })[]; | ||
contentTypes?: OpenApiContentType[]; | ||
deprecated?: boolean; | ||
example?: { | ||
request?: Record<string, any>; | ||
response?: Record<string, any>; | ||
}; | ||
responseHeaders?: Record<string, OpenAPIV3.HeaderObject | OpenAPIV3.ReferenceObject>; | ||
}; | ||
openapi?: { | ||
override?: boolean; | ||
additional?: boolean; | ||
enabled?: boolean; | ||
method: OpenApiMethod; | ||
path: `/${string}`; | ||
summary?: string; | ||
description?: string; | ||
protect?: boolean; | ||
tags?: string[]; | ||
headers?: (OpenAPIV3.ParameterBaseObject & { | ||
name: string; | ||
in?: "header"; | ||
})[]; | ||
contentTypes?: OpenApiContentType[]; | ||
deprecated?: boolean; | ||
example?: { | ||
request?: Record<string, any>; | ||
response?: Record<string, any>; | ||
}; | ||
responseHeaders?: Record< | ||
string, | ||
OpenAPIV3.HeaderObject | OpenAPIV3.ReferenceObject | ||
>; | ||
}; | ||
}; | ||
|
||
export type OpenApiProcedure<TMeta = TRPCMeta> = Procedure< | ||
'query' | 'mutation', | ||
ProcedureParams< | ||
RootConfig<{ | ||
transformer: any; | ||
errorShape: any; | ||
ctx: any; | ||
meta: OpenApiMeta<TMeta>; | ||
}>, | ||
any, | ||
any, | ||
any, | ||
any, | ||
any, | ||
OpenApiMeta<TMeta> | ||
> | ||
"query" | "mutation", | ||
ProcedureParams< | ||
RootConfig<{ | ||
transformer: any; | ||
errorShape: any; | ||
ctx: any; | ||
meta: OpenApiMeta<TMeta>; | ||
}>, | ||
any, | ||
any, | ||
any, | ||
any, | ||
any, | ||
OpenApiMeta<TMeta> | ||
> | ||
>; | ||
|
||
export type OpenApiProcedureRecord<TMeta = TRPCMeta> = Record<string, OpenApiProcedure<TMeta>>; | ||
export type OpenApiProcedureRecord<TMeta = TRPCMeta> = Record< | ||
string, | ||
OpenApiProcedure<TMeta> | ||
>; | ||
|
||
export type OpenApiRouter<TMeta = TRPCMeta> = Router< | ||
RouterDef< | ||
RootConfig<{ | ||
transformer: any; | ||
errorShape: any; | ||
ctx: any; | ||
meta: OpenApiMeta<TMeta>; | ||
}>, | ||
any, | ||
any | ||
> | ||
RouterDef< | ||
RootConfig<{ | ||
transformer: any; | ||
errorShape: any; | ||
ctx: any; | ||
meta: OpenApiMeta<TMeta>; | ||
}>, | ||
any, | ||
any | ||
> | ||
>; | ||
|
||
export type OpenApiSuccessResponse<D = any> = D; | ||
|
||
export type OpenApiErrorResponse = { | ||
message: string; | ||
code: TRPC_ERROR_CODE_KEY; | ||
issues?: ZodIssue[]; | ||
message: string; | ||
code: TRPC_ERROR_CODE_KEY; | ||
issues?: ZodIssue[]; | ||
}; | ||
|
||
export type OpenApiResponse<D = any> = OpenApiSuccessResponse<D> | OpenApiErrorResponse; | ||
export type OpenApiResponse<D = any> = | ||
| OpenApiSuccessResponse<D> | ||
| OpenApiErrorResponse; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"include": ["src"] | ||
"include": ["src"], | ||
"exclude": [ | ||
"examples/with-nextjs", | ||
"examples/with-express", | ||
"examples/with-interop", | ||
"examples/with-serverless", | ||
"examples/with-fastify", | ||
"examples/with-nuxtjs" | ||
] | ||
} |