@dokploy/trpc-openapi 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +369 -0
- package/assets/trpc-openapi-graph.png +0 -0
- package/assets/trpc-openapi-readme.png +0 -0
- package/assets/trpc-openapi.svg +4 -0
- package/dist/adapters/express.d.ts +6 -0
- package/dist/adapters/express.d.ts.map +1 -0
- package/dist/adapters/express.js +12 -0
- package/dist/adapters/express.js.map +1 -0
- package/dist/adapters/index.d.ts +4 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +20 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/next.d.ts +6 -0
- package/dist/adapters/next.d.ts.map +1 -0
- package/dist/adapters/next.js +45 -0
- package/dist/adapters/next.js.map +1 -0
- package/dist/adapters/node-http/core.d.ts +6 -0
- package/dist/adapters/node-http/core.d.ts.map +1 -0
- package/dist/adapters/node-http/core.js +140 -0
- package/dist/adapters/node-http/core.js.map +1 -0
- package/dist/adapters/node-http/errors.d.ts +4 -0
- package/dist/adapters/node-http/errors.d.ts.map +1 -0
- package/dist/adapters/node-http/errors.js +43 -0
- package/dist/adapters/node-http/errors.js.map +1 -0
- package/dist/adapters/node-http/input.d.ts +4 -0
- package/dist/adapters/node-http/input.d.ts.map +1 -0
- package/dist/adapters/node-http/input.js +76 -0
- package/dist/adapters/node-http/input.js.map +1 -0
- package/dist/adapters/node-http/procedures.d.ts +12 -0
- package/dist/adapters/node-http/procedures.d.ts.map +1 -0
- package/dist/adapters/node-http/procedures.js +51 -0
- package/dist/adapters/node-http/procedures.js.map +1 -0
- package/dist/adapters/standalone.d.ts +6 -0
- package/dist/adapters/standalone.d.ts.map +1 -0
- package/dist/adapters/standalone.js +12 -0
- package/dist/adapters/standalone.js.map +1 -0
- package/dist/generator/index.d.ts +14 -0
- package/dist/generator/index.d.ts.map +1 -0
- package/dist/generator/index.js +39 -0
- package/dist/generator/index.js.map +1 -0
- package/dist/generator/paths.d.ts +4 -0
- package/dist/generator/paths.d.ts.map +1 -0
- package/dist/generator/paths.js +76 -0
- package/dist/generator/paths.js.map +1 -0
- package/dist/generator/schema.d.ts +7 -0
- package/dist/generator/schema.d.ts.map +1 -0
- package/dist/generator/schema.js +195 -0
- package/dist/generator/schema.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +53 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/method.d.ts +3 -0
- package/dist/utils/method.d.ts.map +1 -0
- package/dist/utils/method.js +11 -0
- package/dist/utils/method.js.map +1 -0
- package/dist/utils/path.d.ts +4 -0
- package/dist/utils/path.d.ts.map +1 -0
- package/dist/utils/path.js +17 -0
- package/dist/utils/path.js.map +1 -0
- package/dist/utils/procedure.d.ts +14 -0
- package/dist/utils/procedure.d.ts.map +1 -0
- package/dist/utils/procedure.js +39 -0
- package/dist/utils/procedure.js.map +1 -0
- package/dist/utils/zod.d.ts +19 -0
- package/dist/utils/zod.d.ts.map +1 -0
- package/dist/utils/zod.js +87 -0
- package/dist/utils/zod.js.map +1 -0
- package/examples/with-express/README.md +11 -0
- package/examples/with-express/package.json +28 -0
- package/examples/with-express/src/database.ts +67 -0
- package/examples/with-express/src/index.ts +27 -0
- package/examples/with-express/src/openapi.ts +13 -0
- package/examples/with-express/src/router.ts +424 -0
- package/examples/with-express/tsconfig.json +102 -0
- package/examples/with-interop/README.md +10 -0
- package/examples/with-interop/package.json +13 -0
- package/examples/with-interop/src/index.ts +17 -0
- package/examples/with-interop/tsconfig.json +103 -0
- package/examples/with-nextjs/.eslintrc.json +3 -0
- package/examples/with-nextjs/README.md +12 -0
- package/examples/with-nextjs/next-env.d.ts +5 -0
- package/examples/with-nextjs/next.config.js +6 -0
- package/examples/with-nextjs/package.json +33 -0
- package/examples/with-nextjs/public/favicon.ico +0 -0
- package/examples/with-nextjs/src/pages/_app.tsx +7 -0
- package/examples/with-nextjs/src/pages/api/[...trpc].ts +18 -0
- package/examples/with-nextjs/src/pages/api/openapi.json.ts +10 -0
- package/examples/with-nextjs/src/pages/api/trpc/[...trpc].ts +9 -0
- package/examples/with-nextjs/src/pages/index.tsx +12 -0
- package/examples/with-nextjs/src/server/database.ts +67 -0
- package/examples/with-nextjs/src/server/openapi.ts +13 -0
- package/examples/with-nextjs/src/server/router.ts +426 -0
- package/examples/with-nextjs/tsconfig.json +24 -0
- package/jest.config.ts +12 -0
- package/package.json +74 -0
- package/pnpm-workspace.yaml +7 -0
- package/src/adapters/express.ts +20 -0
- package/src/adapters/index.ts +3 -0
- package/src/adapters/next.ts +64 -0
- package/src/adapters/node-http/core.ts +203 -0
- package/src/adapters/node-http/errors.ts +45 -0
- package/src/adapters/node-http/input.ts +76 -0
- package/src/adapters/node-http/procedures.ts +64 -0
- package/src/adapters/standalone.ts +19 -0
- package/src/generator/index.ts +51 -0
- package/src/generator/paths.ts +127 -0
- package/src/generator/schema.ts +238 -0
- package/src/index.ts +42 -0
- package/src/types.ts +79 -0
- package/src/utils/method.ts +8 -0
- package/src/utils/path.ts +12 -0
- package/src/utils/procedure.ts +45 -0
- package/src/utils/zod.ts +115 -0
- package/test/adapters/express.test.ts +150 -0
- package/test/adapters/next.test.ts +162 -0
- package/test/adapters/standalone.test.ts +1335 -0
- package/test/generator.test.ts +2897 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.eslint.json +5 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createOpenApiNodeHttpHandler = void 0;
|
|
7
|
+
// @ts-nocheck
|
|
8
|
+
const server_1 = require("@trpc/server");
|
|
9
|
+
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
|
|
10
|
+
const generator_1 = require("../../generator");
|
|
11
|
+
const method_1 = require("../../utils/method");
|
|
12
|
+
const path_1 = require("../../utils/path");
|
|
13
|
+
const procedure_1 = require("../../utils/procedure");
|
|
14
|
+
const zod_1 = require("../../utils/zod");
|
|
15
|
+
const errors_1 = require("./errors");
|
|
16
|
+
const input_1 = require("./input");
|
|
17
|
+
const procedures_1 = require("./procedures");
|
|
18
|
+
const createOpenApiNodeHttpHandler = (opts) => {
|
|
19
|
+
const router = (0, lodash_clonedeep_1.default)(opts.router);
|
|
20
|
+
// Validate router
|
|
21
|
+
if (process.env.NODE_ENV !== "production") {
|
|
22
|
+
(0, generator_1.generateOpenApiDocument)(router, { title: "", version: "", baseUrl: "" });
|
|
23
|
+
}
|
|
24
|
+
const { createContext, responseMeta, onError, maxBodySize } = opts;
|
|
25
|
+
const getProcedure = (0, procedures_1.createProcedureCache)(router);
|
|
26
|
+
return async (req, res, next) => {
|
|
27
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
28
|
+
const sendResponse = (statusCode, headers, body) => {
|
|
29
|
+
res.statusCode = statusCode;
|
|
30
|
+
res.setHeader("Content-Type", "application/json");
|
|
31
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
32
|
+
if (typeof value !== "undefined") {
|
|
33
|
+
res.setHeader(key, value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
res.end(JSON.stringify(body));
|
|
37
|
+
};
|
|
38
|
+
const method = req.method;
|
|
39
|
+
const reqUrl = req.url;
|
|
40
|
+
const url = new URL(reqUrl.startsWith("/") ? `http://127.0.0.1${reqUrl}` : reqUrl);
|
|
41
|
+
const path = (0, path_1.normalizePath)(url.pathname);
|
|
42
|
+
const { procedure, pathInput } = (_a = getProcedure(method, path)) !== null && _a !== void 0 ? _a : {};
|
|
43
|
+
let input = undefined;
|
|
44
|
+
let ctx = undefined;
|
|
45
|
+
let data = undefined;
|
|
46
|
+
try {
|
|
47
|
+
if (!procedure) {
|
|
48
|
+
if (next) {
|
|
49
|
+
return next();
|
|
50
|
+
}
|
|
51
|
+
// Can be used for warmup
|
|
52
|
+
if (method === "HEAD") {
|
|
53
|
+
sendResponse(204, {}, undefined);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
throw new server_1.TRPCError({
|
|
57
|
+
message: "Not found",
|
|
58
|
+
code: "NOT_FOUND",
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const useBody = (0, method_1.acceptsRequestBody)(method);
|
|
62
|
+
const schema = (0, procedure_1.getInputOutputParsers)(procedure.procedure)
|
|
63
|
+
.inputParser;
|
|
64
|
+
const unwrappedSchema = (0, zod_1.unwrapZodType)(schema, true);
|
|
65
|
+
// input should stay undefined if z.void()
|
|
66
|
+
if (!(0, zod_1.instanceofZodTypeLikeVoid)(unwrappedSchema)) {
|
|
67
|
+
input = Object.assign(Object.assign({}, (useBody ? await (0, input_1.getBody)(req, maxBodySize) : (0, input_1.getQuery)(req, url))), pathInput);
|
|
68
|
+
}
|
|
69
|
+
// if supported, coerce all string values to correct types
|
|
70
|
+
if (zod_1.zodSupportsCoerce) {
|
|
71
|
+
if ((0, zod_1.instanceofZodTypeObject)(unwrappedSchema)) {
|
|
72
|
+
Object.values(unwrappedSchema.shape).forEach((shapeSchema) => {
|
|
73
|
+
const unwrappedShapeSchema = (0, zod_1.unwrapZodType)(shapeSchema, false);
|
|
74
|
+
if ((0, zod_1.instanceofZodTypeCoercible)(unwrappedShapeSchema)) {
|
|
75
|
+
unwrappedShapeSchema._def.coerce = true;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
ctx = await (createContext === null || createContext === void 0 ? void 0 : createContext({ req, res }));
|
|
81
|
+
const caller = router.createCaller(ctx);
|
|
82
|
+
const segments = procedure.path.split(".");
|
|
83
|
+
const procedureFn = segments.reduce((acc, curr) => acc[curr], caller);
|
|
84
|
+
data = await procedureFn(input);
|
|
85
|
+
const meta = responseMeta === null || responseMeta === void 0 ? void 0 : responseMeta({
|
|
86
|
+
type: procedure.type,
|
|
87
|
+
paths: [procedure.path],
|
|
88
|
+
ctx,
|
|
89
|
+
data: [data],
|
|
90
|
+
errors: [],
|
|
91
|
+
});
|
|
92
|
+
const statusCode = (_b = meta === null || meta === void 0 ? void 0 : meta.status) !== null && _b !== void 0 ? _b : 200;
|
|
93
|
+
const headers = (_c = meta === null || meta === void 0 ? void 0 : meta.headers) !== null && _c !== void 0 ? _c : {};
|
|
94
|
+
const body = data;
|
|
95
|
+
sendResponse(statusCode, headers, body);
|
|
96
|
+
}
|
|
97
|
+
catch (cause) {
|
|
98
|
+
const error = (0, errors_1.getErrorFromUnknown)(cause);
|
|
99
|
+
onError === null || onError === void 0 ? void 0 : onError({
|
|
100
|
+
error,
|
|
101
|
+
type: (_d = procedure === null || procedure === void 0 ? void 0 : procedure.type) !== null && _d !== void 0 ? _d : "unknown",
|
|
102
|
+
path: procedure === null || procedure === void 0 ? void 0 : procedure.path,
|
|
103
|
+
input,
|
|
104
|
+
ctx,
|
|
105
|
+
req,
|
|
106
|
+
});
|
|
107
|
+
const meta = responseMeta === null || responseMeta === void 0 ? void 0 : responseMeta({
|
|
108
|
+
type: (_e = procedure === null || procedure === void 0 ? void 0 : procedure.type) !== null && _e !== void 0 ? _e : "unknown",
|
|
109
|
+
paths: (procedure === null || procedure === void 0 ? void 0 : procedure.path) ? [procedure === null || procedure === void 0 ? void 0 : procedure.path] : undefined,
|
|
110
|
+
ctx,
|
|
111
|
+
data: [data],
|
|
112
|
+
errors: [error],
|
|
113
|
+
});
|
|
114
|
+
const errorShape = router.getErrorShape({
|
|
115
|
+
error,
|
|
116
|
+
type: (_f = procedure === null || procedure === void 0 ? void 0 : procedure.type) !== null && _f !== void 0 ? _f : "unknown",
|
|
117
|
+
path: procedure === null || procedure === void 0 ? void 0 : procedure.path,
|
|
118
|
+
input,
|
|
119
|
+
ctx,
|
|
120
|
+
});
|
|
121
|
+
const isInputValidationError = error.code === "BAD_REQUEST" &&
|
|
122
|
+
error.cause instanceof Error &&
|
|
123
|
+
error.cause.name === "ZodError";
|
|
124
|
+
const statusCode = (_h = (_g = meta === null || meta === void 0 ? void 0 : meta.status) !== null && _g !== void 0 ? _g : errors_1.TRPC_ERROR_CODE_HTTP_STATUS[error.code]) !== null && _h !== void 0 ? _h : 500;
|
|
125
|
+
const headers = (_j = meta === null || meta === void 0 ? void 0 : meta.headers) !== null && _j !== void 0 ? _j : {};
|
|
126
|
+
const body = {
|
|
127
|
+
message: isInputValidationError
|
|
128
|
+
? "Input validation failed"
|
|
129
|
+
: (_l = (_k = errorShape === null || errorShape === void 0 ? void 0 : errorShape.message) !== null && _k !== void 0 ? _k : error.message) !== null && _l !== void 0 ? _l : "An error occurred",
|
|
130
|
+
code: error.code,
|
|
131
|
+
issues: isInputValidationError
|
|
132
|
+
? error.cause.errors
|
|
133
|
+
: undefined,
|
|
134
|
+
};
|
|
135
|
+
sendResponse(statusCode, headers, body);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
exports.createOpenApiNodeHttpHandler = createOpenApiNodeHttpHandler;
|
|
140
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../src/adapters/node-http/core.ts"],"names":[],"mappings":";;;;;;AAAA,cAAc;AACd,yCAA4D;AAM5D,wEAAyC;AAGzC,+CAA0D;AAQ1D,+CAAwD;AACxD,2CAAiD;AACjD,qDAA8D;AAC9D,yCAMyB;AACzB,qCAA4E;AAC5E,mCAA4C;AAC5C,6CAAoD;AAa7C,MAAM,4BAA4B,GAAG,CAK3C,IAAuE,EACtE,EAAE;IACH,MAAM,MAAM,GAAG,IAAA,0BAAS,EAAC,IAAI,CAAC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defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TRPC_ERROR_CODE_HTTP_STATUS = void 0;
|
|
4
|
+
exports.getErrorFromUnknown = getErrorFromUnknown;
|
|
5
|
+
const server_1 = require("@trpc/server");
|
|
6
|
+
exports.TRPC_ERROR_CODE_HTTP_STATUS = {
|
|
7
|
+
PARSE_ERROR: 400,
|
|
8
|
+
BAD_REQUEST: 400,
|
|
9
|
+
NOT_FOUND: 404,
|
|
10
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
11
|
+
UNAUTHORIZED: 401,
|
|
12
|
+
FORBIDDEN: 403,
|
|
13
|
+
TIMEOUT: 408,
|
|
14
|
+
CONFLICT: 409,
|
|
15
|
+
CLIENT_CLOSED_REQUEST: 499,
|
|
16
|
+
PRECONDITION_FAILED: 412,
|
|
17
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
18
|
+
METHOD_NOT_SUPPORTED: 405,
|
|
19
|
+
TOO_MANY_REQUESTS: 429,
|
|
20
|
+
UNPROCESSABLE_CONTENT: 422,
|
|
21
|
+
NOT_IMPLEMENTED: 501,
|
|
22
|
+
};
|
|
23
|
+
function getErrorFromUnknown(cause) {
|
|
24
|
+
if (cause instanceof Error && cause.name === "TRPCError") {
|
|
25
|
+
return cause;
|
|
26
|
+
}
|
|
27
|
+
let errorCause = undefined;
|
|
28
|
+
let stack = undefined;
|
|
29
|
+
if (cause instanceof Error) {
|
|
30
|
+
errorCause = cause;
|
|
31
|
+
stack = cause.stack;
|
|
32
|
+
}
|
|
33
|
+
const error = new server_1.TRPCError({
|
|
34
|
+
message: "Internal server error",
|
|
35
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
36
|
+
cause: errorCause,
|
|
37
|
+
});
|
|
38
|
+
if (stack) {
|
|
39
|
+
error.stack = stack;
|
|
40
|
+
}
|
|
41
|
+
return error;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/adapters/node-http/errors.ts"],"names":[],"mappings":";;;AAoBA,kDAwBC;AA5CD,yCAAyC;AAE5B,QAAA,2BAA2B,GAAsC;IAC7E,WAAW,EAAE,GAAG;IAChB,WAAW,EAAE,GAAG;IAChB,SAAS,EAAE,GAAG;IACd,qBAAqB,EAAE,GAAG;IAC1B,YAAY,EAAE,GAAG;IACjB,SAAS,EAAE,GAAG;IACd,OAAO,EAAE,GAAG;IACZ,QAAQ,EAAE,GAAG;IACb,qBAAqB,EAAE,GAAG;IAC1B,mBAAmB,EAAE,GAAG;IACxB,iBAAiB,EAAE,GAAG;IACtB,oBAAoB,EAAE,GAAG;IACzB,iBAAiB,EAAE,GAAG;IACtB,qBAAqB,EAAE,GAAG;IAC1B,eAAe,EAAE,GAAG;CACpB,CAAC;AAEF,SAAgB,mBAAmB,CAAC,KAAc;IACjD,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QAC1D,OAAO,KAAkB,CAAC;IAC3B,CAAC;IAED,IAAI,UAAU,GAAsB,SAAS,CAAC;IAC9C,IAAI,KAAK,GAAuB,SAAS,CAAC;IAE1C,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC5B,UAAU,GAAG,KAAK,CAAC;QACnB,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IACrB,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,kBAAS,CAAC;QAC3B,OAAO,EAAE,uBAAuB;QAChC,IAAI,EAAE,uBAAuB;QAC7B,KAAK,EAAE,UAAU;KACjB,CAAC,CAAC;IAEH,IAAI,KAAK,EAAE,CAAC;QACX,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { NodeHTTPRequest } from '@trpc/server/dist/adapters/node-http';
|
|
2
|
+
export declare const getQuery: (req: NodeHTTPRequest, url: URL) => Record<string, string>;
|
|
3
|
+
export declare const getBody: (req: NodeHTTPRequest, maxBodySize?: number) => Promise<any>;
|
|
4
|
+
//# sourceMappingURL=input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/input.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAGvE,eAAO,MAAM,QAAQ,QAAS,eAAe,OAAO,GAAG,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CA6B9E,CAAC;AAGF,eAAO,MAAM,OAAO,QAAe,eAAe,2BAA8B,OAAO,CAAC,GAAG,CAuC1F,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getBody = exports.getQuery = void 0;
|
|
7
|
+
const server_1 = require("@trpc/server");
|
|
8
|
+
const co_body_1 = __importDefault(require("co-body"));
|
|
9
|
+
const getQuery = (req, url) => {
|
|
10
|
+
const query = {};
|
|
11
|
+
if (!req.query) {
|
|
12
|
+
const parsedQs = {};
|
|
13
|
+
url.searchParams.forEach((value, key) => {
|
|
14
|
+
if (!parsedQs[key]) {
|
|
15
|
+
parsedQs[key] = [];
|
|
16
|
+
}
|
|
17
|
+
parsedQs[key].push(value);
|
|
18
|
+
});
|
|
19
|
+
req.query = parsedQs;
|
|
20
|
+
}
|
|
21
|
+
// normalize first value in array
|
|
22
|
+
Object.keys(req.query).forEach((key) => {
|
|
23
|
+
const value = req.query[key];
|
|
24
|
+
if (value) {
|
|
25
|
+
if (typeof value === 'string') {
|
|
26
|
+
query[key] = value;
|
|
27
|
+
}
|
|
28
|
+
else if (Array.isArray(value)) {
|
|
29
|
+
if (typeof value[0] === 'string') {
|
|
30
|
+
query[key] = value[0];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return query;
|
|
36
|
+
};
|
|
37
|
+
exports.getQuery = getQuery;
|
|
38
|
+
const BODY_100_KB = 100000;
|
|
39
|
+
const getBody = async (req, maxBodySize = BODY_100_KB) => {
|
|
40
|
+
if ('body' in req) {
|
|
41
|
+
return req.body;
|
|
42
|
+
}
|
|
43
|
+
req.body = undefined;
|
|
44
|
+
const contentType = req.headers['content-type'];
|
|
45
|
+
if (contentType === 'application/json' || contentType === 'application/x-www-form-urlencoded') {
|
|
46
|
+
try {
|
|
47
|
+
const { raw, parsed } = await (0, co_body_1.default)(req, {
|
|
48
|
+
limit: maxBodySize,
|
|
49
|
+
strict: false,
|
|
50
|
+
returnRawBody: true,
|
|
51
|
+
});
|
|
52
|
+
req.body = raw ? parsed : undefined;
|
|
53
|
+
}
|
|
54
|
+
catch (cause) {
|
|
55
|
+
if (cause instanceof Error && cause.name === 'PayloadTooLargeError') {
|
|
56
|
+
throw new server_1.TRPCError({
|
|
57
|
+
message: 'Request body too large',
|
|
58
|
+
code: 'PAYLOAD_TOO_LARGE',
|
|
59
|
+
cause: cause,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
let errorCause = undefined;
|
|
63
|
+
if (cause instanceof Error) {
|
|
64
|
+
errorCause = cause;
|
|
65
|
+
}
|
|
66
|
+
throw new server_1.TRPCError({
|
|
67
|
+
message: 'Failed to parse request body',
|
|
68
|
+
code: 'PARSE_ERROR',
|
|
69
|
+
cause: errorCause,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return req.body;
|
|
74
|
+
};
|
|
75
|
+
exports.getBody = getBody;
|
|
76
|
+
//# sourceMappingURL=input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","s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AO,GAAG,CAAC,IAAI,CAAC;AAClB,CAAC,CAAC;AAvCW,QAAA,OAAO,WAuClB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OpenApiMethod, OpenApiProcedure, OpenApiRouter } from '../../types';
|
|
2
|
+
export declare const createProcedureCache: (router: OpenApiRouter) => (method: OpenApiMethod, path: string) => {
|
|
3
|
+
procedure: {
|
|
4
|
+
type: "query" | "mutation";
|
|
5
|
+
path: string;
|
|
6
|
+
procedure: OpenApiProcedure;
|
|
7
|
+
};
|
|
8
|
+
pathInput: {
|
|
9
|
+
[key: string]: string;
|
|
10
|
+
};
|
|
11
|
+
} | undefined;
|
|
12
|
+
//# sourceMappingURL=procedures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procedures.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/procedures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAI7E,eAAO,MAAM,oBAAoB,WAAY,aAAa,cA2CxC,aAAa,QAAQ,MAAM;;cArC/B,OAAO,GAAG,UAAU;cACpB,MAAM;mBACD,gBAAgB;;;;;aAmDlC,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createProcedureCache = void 0;
|
|
4
|
+
const path_1 = require("../../utils/path");
|
|
5
|
+
const procedure_1 = require("../../utils/procedure");
|
|
6
|
+
const createProcedureCache = (router) => {
|
|
7
|
+
const procedureCache = new Map();
|
|
8
|
+
const { queries, mutations } = router._def;
|
|
9
|
+
(0, procedure_1.forEachOpenApiProcedure)(queries, ({ path: queryPath, procedure, openapi }) => {
|
|
10
|
+
const { method } = openapi;
|
|
11
|
+
if (!procedureCache.has(method)) {
|
|
12
|
+
procedureCache.set(method, new Map());
|
|
13
|
+
}
|
|
14
|
+
const path = (0, path_1.normalizePath)(openapi.path);
|
|
15
|
+
const pathRegExp = (0, path_1.getPathRegExp)(path);
|
|
16
|
+
procedureCache.get(method).set(pathRegExp, {
|
|
17
|
+
type: 'query',
|
|
18
|
+
path: queryPath,
|
|
19
|
+
procedure,
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
(0, procedure_1.forEachOpenApiProcedure)(mutations, ({ path: mutationPath, procedure, openapi }) => {
|
|
23
|
+
const { method } = openapi;
|
|
24
|
+
if (!procedureCache.has(method)) {
|
|
25
|
+
procedureCache.set(method, new Map());
|
|
26
|
+
}
|
|
27
|
+
const path = (0, path_1.normalizePath)(openapi.path);
|
|
28
|
+
const pathRegExp = (0, path_1.getPathRegExp)(path);
|
|
29
|
+
procedureCache.get(method).set(pathRegExp, {
|
|
30
|
+
type: 'mutation',
|
|
31
|
+
path: mutationPath,
|
|
32
|
+
procedure,
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
return (method, path) => {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
const procedureMethodCache = procedureCache.get(method);
|
|
38
|
+
if (!procedureMethodCache) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
const procedureRegExp = Array.from(procedureMethodCache.keys()).find((re) => re.test(path));
|
|
42
|
+
if (!procedureRegExp) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
const procedure = procedureMethodCache.get(procedureRegExp);
|
|
46
|
+
const pathInput = (_b = (_a = procedureRegExp.exec(path)) === null || _a === void 0 ? void 0 : _a.groups) !== null && _b !== void 0 ? _b : {};
|
|
47
|
+
return { procedure, pathInput };
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
exports.createProcedureCache = createProcedureCache;
|
|
51
|
+
//# sourceMappingURL=procedures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procedures.js","sourceRoot":"","sources":["../../../src/adapters/node-http/procedures.ts"],"names":[],"mappings":";;;AACA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BAAa,EAAC,IAAI,CAAC,CAAC;QACvC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAE,CAAC,GAAG,CAAC,UAAU,EAAE;YAC1C,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,YAAY;YAClB,SAAS;SACV,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,MAAqB,EAAE,IAAY,EAAE,EAAE;;QAC7C,MAAM,oBAAoB,GAAG,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACxD,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC1B,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5F,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,SAAS,GAAG,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAE,CAAC;QAC7D,MAAM,SAAS,GAAG,MAAA,MAAA,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,0CAAE,MAAM,mCAAI,EAAE,CAAC;QAE3D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC,CAAC;AA3DW,QAAA,oBAAoB,wBA2D/B"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { OpenApiRouter } from "../types";
|
|
3
|
+
import { type CreateOpenApiNodeHttpHandlerOptions } from "./node-http/core";
|
|
4
|
+
export type CreateOpenApiHttpHandlerOptions<TRouter extends OpenApiRouter> = CreateOpenApiNodeHttpHandlerOptions<TRouter, IncomingMessage, ServerResponse>;
|
|
5
|
+
export declare const createOpenApiHttpHandler: <TRouter extends OpenApiRouter>(opts: CreateOpenApiHttpHandlerOptions<TRouter>) => (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
6
|
+
//# sourceMappingURL=standalone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standalone.d.ts","sourceRoot":"","sources":["../../src/adapters/standalone.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EACN,KAAK,mCAAmC,EAExC,MAAM,kBAAkB,CAAC;AAE1B,MAAM,MAAM,+BAA+B,CAAC,OAAO,SAAS,aAAa,IACxE,mCAAmC,CAAC,OAAO,EAAE,eAAe,EAAE,cAAc,CAAC,CAAC;AAE/E,eAAO,MAAM,wBAAwB,GAAI,OAAO,SAAS,aAAa,QAC/D,+BAA+B,CAAC,OAAO,CAAC,WAG3B,eAAe,OAAO,cAAc,kBAGvD,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createOpenApiHttpHandler = void 0;
|
|
4
|
+
const core_1 = require("./node-http/core");
|
|
5
|
+
const createOpenApiHttpHandler = (opts) => {
|
|
6
|
+
const openApiHttpHandler = (0, core_1.createOpenApiNodeHttpHandler)(opts);
|
|
7
|
+
return async (req, res) => {
|
|
8
|
+
await openApiHttpHandler(req, res);
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
exports.createOpenApiHttpHandler = createOpenApiHttpHandler;
|
|
12
|
+
//# sourceMappingURL=standalone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standalone.js","sourceRoot":"","sources":["../../src/adapters/standalone.ts"],"names":[],"mappings":";;;AAGA,2CAG0B;AAKnB,MAAM,wBAAwB,GAAG,CACvC,IAA8C,EAC7C,EAAE;IACH,MAAM,kBAAkB,GAAG,IAAA,mCAA4B,EAAC,IAAI,CAAC,CAAC;IAC9D,OAAO,KAAK,EAAE,GAAoB,EAAE,GAAmB,EAAE,EAAE;QAC1D,MAAM,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACpC,CAAC,CAAC;AACH,CAAC,CAAC;AAPW,QAAA,wBAAwB,4BAOnC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
2
|
+
import { OpenApiRouter } from '../types';
|
|
3
|
+
export declare const openApiVersion = "3.0.3";
|
|
4
|
+
export type GenerateOpenApiDocumentOptions = {
|
|
5
|
+
title: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
version: string;
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
docsUrl?: string;
|
|
10
|
+
tags?: string[];
|
|
11
|
+
securitySchemes?: OpenAPIV3.ComponentsObject['securitySchemes'];
|
|
12
|
+
};
|
|
13
|
+
export declare const generateOpenApiDocument: (appRouter: OpenApiRouter, opts: GenerateOpenApiDocumentOptions) => OpenAPIV3.Document;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAIzC,eAAO,MAAM,cAAc,UAAU,CAAC;AAEtC,MAAM,MAAM,8BAA8B,GAAG;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,eAAe,CAAC,EAAE,SAAS,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;CACjE,CAAC;AAEF,eAAO,MAAM,uBAAuB,cACvB,aAAa,QAClB,8BAA8B,KACnC,SAAS,CAAC,QA6BZ,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateOpenApiDocument = exports.openApiVersion = void 0;
|
|
4
|
+
const paths_1 = require("./paths");
|
|
5
|
+
const schema_1 = require("./schema");
|
|
6
|
+
exports.openApiVersion = '3.0.3';
|
|
7
|
+
const generateOpenApiDocument = (appRouter, opts) => {
|
|
8
|
+
var _a;
|
|
9
|
+
const securitySchemes = opts.securitySchemes || {
|
|
10
|
+
Authorization: {
|
|
11
|
+
type: 'http',
|
|
12
|
+
scheme: 'bearer',
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
openapi: exports.openApiVersion,
|
|
17
|
+
info: {
|
|
18
|
+
title: opts.title,
|
|
19
|
+
description: opts.description,
|
|
20
|
+
version: opts.version,
|
|
21
|
+
},
|
|
22
|
+
servers: [
|
|
23
|
+
{
|
|
24
|
+
url: opts.baseUrl,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
paths: (0, paths_1.getOpenApiPathsObject)(appRouter, Object.keys(securitySchemes)),
|
|
28
|
+
components: {
|
|
29
|
+
securitySchemes,
|
|
30
|
+
responses: {
|
|
31
|
+
error: schema_1.errorResponseObject,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
tags: (_a = opts.tags) === null || _a === void 0 ? void 0 : _a.map((tag) => ({ name: tag })),
|
|
35
|
+
externalDocs: opts.docsUrl ? { url: opts.docsUrl } : undefined,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
exports.generateOpenApiDocument = generateOpenApiDocument;
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":";;;AAGA,mCAAgD;AAChD,qCAA+C;AAElC,QAAA,cAAc,GAAG,OAAO,CAAC;AAY/B,MAAM,uBAAuB,GAAG,CACrC,SAAwB,EACxB,IAAoC,EAChB,EAAE;;IACtB,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,IAAI;QAC9C,aAAa,EAAE;YACb,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,QAAQ;SACjB;KACF,CAAC;IACF,OAAO;QACL,OAAO,EAAE,sBAAc;QACvB,IAAI,EAAE;YACJ,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB;QACD,OAAO,EAAE;YACP;gBACE,GAAG,EAAE,IAAI,CAAC,OAAO;aAClB;SACF;QACD,KAAK,EAAE,IAAA,6BAAqB,EAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACrE,UAAU,EAAE;YACV,eAAe;YACf,SAAS,EAAE;gBACT,KAAK,EAAE,4BAAmB;aAC3B;SACF;QACD,IAAI,EAAE,MAAA,IAAI,CAAC,IAAI,0CAAE,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;QAC9C,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS;KAC/D,CAAC;AACJ,CAAC,CAAC;AAhCW,QAAA,uBAAuB,2BAgClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/generator/paths.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAA0B,aAAa,EAAE,MAAM,UAAU,CAAC;AAajE,eAAO,MAAM,qBAAqB,cACtB,aAAa,uBACH,MAAM,EAAE,KAC3B,SAAS,CAAC,WA2GZ,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOpenApiPathsObject = void 0;
|
|
4
|
+
const server_1 = require("@trpc/server");
|
|
5
|
+
const openapi_types_1 = require("openapi-types");
|
|
6
|
+
const method_1 = require("../utils/method");
|
|
7
|
+
const path_1 = require("../utils/path");
|
|
8
|
+
const procedure_1 = require("../utils/procedure");
|
|
9
|
+
const schema_1 = require("./schema");
|
|
10
|
+
const getOpenApiPathsObject = (appRouter, securitySchemeNames) => {
|
|
11
|
+
const pathsObject = {};
|
|
12
|
+
const procedures = appRouter._def.procedures;
|
|
13
|
+
(0, procedure_1.forEachOpenApiProcedure)(procedures, ({ path: procedurePath, type, procedure, openapi }) => {
|
|
14
|
+
var _a, _b, _c, _d, _e;
|
|
15
|
+
const procedureName = `${type}.${procedurePath}`;
|
|
16
|
+
try {
|
|
17
|
+
if (type === "subscription") {
|
|
18
|
+
throw new server_1.TRPCError({
|
|
19
|
+
message: "Subscriptions are not supported by OpenAPI v3",
|
|
20
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const { method, protect, summary, description, tags, headers } = openapi;
|
|
24
|
+
const path = (0, path_1.normalizePath)(openapi.path);
|
|
25
|
+
const pathParameters = (0, path_1.getPathParameters)(path);
|
|
26
|
+
const headerParameters = (headers === null || headers === void 0 ? void 0 : headers.map((header) => (Object.assign(Object.assign({}, header), { in: "header" })))) || [];
|
|
27
|
+
const httpMethod = openapi_types_1.OpenAPIV3.HttpMethods[method];
|
|
28
|
+
if (!httpMethod) {
|
|
29
|
+
throw new server_1.TRPCError({
|
|
30
|
+
message: "Method must be GET, POST, PATCH, PUT or DELETE",
|
|
31
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if ((_a = pathsObject[path]) === null || _a === void 0 ? void 0 : _a[httpMethod]) {
|
|
35
|
+
throw new server_1.TRPCError({
|
|
36
|
+
message: `Duplicate procedure defined for route ${method} ${path}`,
|
|
37
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const contentTypes = openapi.contentTypes || ["application/json"];
|
|
41
|
+
if (contentTypes.length === 0) {
|
|
42
|
+
throw new server_1.TRPCError({
|
|
43
|
+
message: "At least one content type must be specified",
|
|
44
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const { inputParser, outputParser } = (0, procedure_1.getInputOutputParsers)(procedure);
|
|
48
|
+
pathsObject[path] = Object.assign(Object.assign({}, pathsObject[path]), { [httpMethod]: Object.assign(Object.assign({ operationId: procedurePath.replace(/\./g, "-"), summary,
|
|
49
|
+
description, tags: tags, security: protect
|
|
50
|
+
? securitySchemeNames.map((name) => ({ [name]: [] }))
|
|
51
|
+
: undefined }, ((0, method_1.acceptsRequestBody)(method)
|
|
52
|
+
? {
|
|
53
|
+
requestBody: (0, schema_1.getRequestBodyObject)(inputParser, pathParameters, contentTypes, (_b = openapi.example) === null || _b === void 0 ? void 0 : _b.request),
|
|
54
|
+
parameters: [
|
|
55
|
+
...headerParameters,
|
|
56
|
+
...((0, schema_1.getParameterObjects)(inputParser, pathParameters, "path", (_c = openapi.example) === null || _c === void 0 ? void 0 : _c.request) || []),
|
|
57
|
+
],
|
|
58
|
+
}
|
|
59
|
+
: {
|
|
60
|
+
requestBody: undefined,
|
|
61
|
+
parameters: [
|
|
62
|
+
...headerParameters,
|
|
63
|
+
...((0, schema_1.getParameterObjects)(inputParser, pathParameters, "all", (_d = openapi.example) === null || _d === void 0 ? void 0 : _d.request) || []),
|
|
64
|
+
],
|
|
65
|
+
})), { responses: (0, schema_1.getResponsesObject)(outputParser, (_e = openapi.example) === null || _e === void 0 ? void 0 : _e.response, openapi.responseHeaders) }) });
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
69
|
+
error.message = `[${procedureName}] - ${error.message}`;
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return pathsObject;
|
|
74
|
+
};
|
|
75
|
+
exports.getOpenApiPathsObject = getOpenApiPathsObject;
|
|
76
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/generator/paths.ts"],"names":[],"mappings":";;;AAAA,yCAAyC;AACzC,iDAA0C;AAG1C,4CAAqD;AACrD,wCAAiE;AACjE,kDAG4B;AAC5B,qCAIkB;AAEX,MAAM,qBAAqB,GAAG,CACpC,SAAwB,EACxB,mBAA6B,EACL,EAAE;IAC1B,MAAM,WAAW,GAA0B,EAAE,CAAC;IAC9C,MAAM,UAAU,GAAG,SAAS,CAAC,IAAI,CAAC,UAAoC,CAAC;IAEvE,IAAA,mCAAuB,EACtB,UAAU,EACV,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE;;QACrD,MAAM,aAAa,GAAG,GAAG,IAAI,IAAI,aAAa,EAAE,CAAC;QAEjD,IAAI,CAAC;YACJ,IAAI,IAAI,KAAK,cAAc,EAAE,CAAC;gBAC7B,MAAM,IAAI,kBAAS,CAAC;oBACnB,OAAO,EAAE,+CAA+C;oBACxD,IAAI,EAAE,uBAAuB;iBAC7B,CAAC,CAAC;YACJ,CAAC;YAED,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,GAC7D,OAAO,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qB,yBA8GhC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { OpenAPIV3 } from "openapi-types";
|
|
2
|
+
import { OpenApiContentType } from "../types";
|
|
3
|
+
export declare const getParameterObjects: (currentSchema: unknown, pathParameters: string[], inType: "all" | "path" | "query", example: Record<string, any> | undefined) => OpenAPIV3.ParameterObject[] | undefined;
|
|
4
|
+
export declare const getRequestBodyObject: (currentSchema: unknown, pathParameters: string[], contentTypes: OpenApiContentType[], example: Record<string, any> | undefined) => OpenAPIV3.RequestBodyObject | undefined;
|
|
5
|
+
export declare const errorResponseObject: OpenAPIV3.ResponseObject;
|
|
6
|
+
export declare const getResponsesObject: (schema: unknown, example: Record<string, any> | undefined, headers: Record<string, OpenAPIV3.HeaderObject | OpenAPIV3.ReferenceObject> | undefined) => OpenAPIV3.ResponsesObject;
|
|
7
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/generator/schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAI1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAsB9C,eAAO,MAAM,mBAAmB,kBAChB,OAAO,kBACN,MAAM,EAAE,UAChB,KAAK,GAAG,MAAM,GAAG,OAAO,WACvB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,KACtC,SAAS,CAAC,eAAe,EAAE,GAAG,SAoFhC,CAAC;AAEF,eAAO,MAAM,oBAAoB,kBACjB,OAAO,kBACN,MAAM,EAAE,gBACV,kBAAkB,EAAE,WACzB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,KACtC,SAAS,CAAC,iBAAiB,GAAG,SA2DhC,CAAC;AACF,eAAO,MAAM,mBAAmB,EAAE,SAAS,CAAC,cAa3C,CAAC;AAEF,eAAO,MAAM,kBAAkB,WACtB,OAAO,WACN,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,WAErC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,YAAY,GAAG,SAAS,CAAC,eAAe,CAAC,GAClE,SAAS,KACV,SAAS,CAAC,eAgCZ,CAAC"}
|