trpc-to-openapi
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -11,2 +11,3 @@ "use strict"; | ||
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep")); | ||
const zod_1 = require("zod"); | ||
const generator_1 = require("../../generator"); | ||
@@ -16,3 +17,3 @@ const method_1 = require("../../utils/method"); | ||
const procedure_1 = require("../../utils/procedure"); | ||
const zod_1 = require("../../utils/zod"); | ||
const zod_2 = require("../../utils/zod"); | ||
const errors_1 = require("./errors"); | ||
@@ -78,10 +79,17 @@ const input_1 = require("./input"); | ||
const inputParser = (0, procedure_1.getInputOutputParsers)(procedure.procedure).inputParser; | ||
const unwrappedSchema = (0, zod_1.unwrapZodType)(inputParser, true); | ||
const unwrappedSchema = (0, zod_2.unwrapZodType)(inputParser, true); | ||
// input should stay undefined if z.void() | ||
if (!(0, zod_1.instanceofZodTypeLikeVoid)(unwrappedSchema)) { | ||
if (!(0, zod_2.instanceofZodTypeLikeVoid)(unwrappedSchema)) { | ||
input = Object.assign(Object.assign({}, (useBody ? await (0, input_1.getBody)(req, maxBodySize) : (0, input_1.getQuery)(req, url))), pathInput); | ||
} | ||
// if supported, coerce all string values to correct types | ||
if (zod_1.zodSupportsCoerce && (0, zod_1.instanceofZodTypeObject)(unwrappedSchema)) { | ||
(0, zod_1.coerceSchema)(unwrappedSchema); | ||
if (zod_2.zodSupportsCoerce && (0, zod_2.instanceofZodTypeObject)(unwrappedSchema)) { | ||
if (!useBody) { | ||
for (const [key, shape] of Object.entries(unwrappedSchema.shape)) { | ||
if (shape instanceof zod_1.ZodArray && typeof input[key] === 'string') { | ||
input[key] = [input[key]]; | ||
} | ||
} | ||
} | ||
(0, zod_2.coerceSchema)(unwrappedSchema); | ||
} | ||
@@ -141,3 +149,3 @@ ctx = await (createContext === null || createContext === void 0 ? void 0 : createContext({ req, res, info })); | ||
? 'Input validation failed' | ||
: (_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', code: error.code, issues: isInputValidationError ? error.cause.errors : undefined }); | ||
: ((_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'), code: error.code, issues: isInputValidationError ? error.cause.errors : undefined }); | ||
sendResponse(statusCode, headers, body); | ||
@@ -144,0 +152,0 @@ } |
import { NodeHTTPRequest } from '@trpc/server/adapters/node-http'; | ||
export declare const getQuery: (req: NodeHTTPRequest, url: URL) => Record<string, string>; | ||
export declare const getQuery: (req: NodeHTTPRequest, url: URL) => Record<string, string | string[]>; | ||
export declare const getBody: (req: NodeHTTPRequest, maxBodySize?: number) => Promise<any>; | ||
//# sourceMappingURL=input.d.ts.map |
@@ -26,10 +26,3 @@ "use strict"; | ||
if (value) { | ||
if (typeof value === 'string') { | ||
query[key] = value; | ||
} | ||
else if (Array.isArray(value)) { | ||
if (typeof value[0] === 'string') { | ||
query[key] = value[0]; | ||
} | ||
} | ||
query[key] = Array.isArray(value) && value.length === 1 ? value[0] : value; | ||
} | ||
@@ -36,0 +29,0 @@ }); |
import { NodeHTTPRequest } from '@trpc/server/adapters/node-http'; | ||
export declare const getQuery: (req: NodeHTTPRequest, url: URL) => Record<string, string>; | ||
export declare const getQuery: (req: NodeHTTPRequest, url: URL) => Record<string, string | string[]>; | ||
export declare const getBody: (req: NodeHTTPRequest, maxBodySize?: number) => Promise<any>; | ||
//# sourceMappingURL=input.d.ts.map |
{ | ||
"name": "trpc-to-openapi", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "tRPC OpenAPI", | ||
@@ -45,2 +45,3 @@ "author": "mcampa", | ||
"lint-fix": "eslint . --ext .ts --fix", | ||
"format": "prettier --write ./src ./test ./examples", | ||
"build": "npm test && rimraf dist && npm run build:cjs && npm run build:esm", | ||
@@ -76,9 +77,9 @@ "build:cjs": "tsc -p tsconfig.build.cjs.json", | ||
"express": "^4.18.2", | ||
"fastify": "^4.17.0", | ||
"fastify": "^5.1.0", | ||
"jest": "^29.5.0", | ||
"next": "^13.4.3", | ||
"next": "^14.2.10", | ||
"node-fetch": "^2.6.11", | ||
"openapi-schema-validator": "^12.1.1", | ||
"prettier": "^2.8.8", | ||
"rimraf": "^5.0.1", | ||
"prettier": "^3.4.1", | ||
"rimraf": "^6.0.1", | ||
"superjson": "^1.12.3", | ||
@@ -88,3 +89,6 @@ "ts-jest": "^29.1.0", | ||
"typescript": "5.5.4" | ||
}, | ||
"optionalDependencies": { | ||
"@rollup/rollup-linux-x64-gnu": "4.6.1" | ||
} | ||
} |
@@ -21,2 +21,6 @@ <p align="center"> | ||
## Changelog | ||
- 2.0.3 Added support for array inputs for GET requests | ||
## Usage | ||
@@ -102,4 +106,4 @@ | ||
- [`tRPC`](https://github.com/trpc/trpc) Server v10 (`@trpc/server`) must be installed. | ||
- [`Zod`](https://github.com/colinhacks/zod) v3 (`zod@^3.14.4`) must be installed (recommended `^3.20.0`). | ||
- [`tRPC`](https://github.com/trpc/trpc) Server v11 (`@trpc/server`) must be installed. | ||
- [`Zod`](https://github.com/colinhacks/zod) v3 (`zod@^3.23.8`) must be installed. | ||
@@ -106,0 +110,0 @@ For a procedure to support OpenAPI the following _must_ be true: |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
254791
2665
361
9