@ts-rest/open-api
Advanced tools
Comparing version 3.7.0 to 3.8.0
34
index.js
@@ -23,8 +23,8 @@ import { isAppRoute, isZodObject } from '@ts-rest/core'; | ||
}; | ||
const getResponseSchemaFromZod = (response) => { | ||
const isZodObj = isZodObject(response); | ||
const getJsonSchemaFromZod = (zodObject) => { | ||
const isZodObj = isZodObject(zodObject); | ||
if (!isZodObj) { | ||
return null; | ||
} | ||
const schema = zodToJsonSchema(response, { | ||
const schema = zodToJsonSchema(zodObject, { | ||
name: 'zodObject', | ||
@@ -56,8 +56,9 @@ target: 'openApi3', | ||
.match(/{[^}]+}/g)) === null || _a === void 0 ? void 0 : _a.map((param) => param.slice(1, -1)); | ||
const querySchema = getJsonSchemaFromZod(path.route.query); | ||
const bodySchema = ((_b = path.route) === null || _b === void 0 ? void 0 : _b.method) !== 'GET' | ||
? getResponseSchemaFromZod(path.route.body) | ||
? getJsonSchemaFromZod(path.route.body) | ||
: null; | ||
const responses = Object.keys(path.route.responses).reduce((acc, key) => { | ||
const keyAsNumber = Number(key); | ||
const responseSchema = getResponseSchemaFromZod(path.route.responses[keyAsNumber]); | ||
const responseSchema = getJsonSchemaFromZod(path.route.responses[keyAsNumber]); | ||
return Object.assign(Object.assign({}, acc), { [keyAsNumber]: Object.assign({ description: `${keyAsNumber}` }, (responseSchema | ||
@@ -73,7 +74,20 @@ ? { | ||
}, {}); | ||
const newPath = Object.assign(Object.assign(Object.assign({ description: path.route.description, summary: path.route.summary, deprecated: path.route.deprecated, tags: path.paths, parameters: paramsFromPath === null || paramsFromPath === void 0 ? void 0 : paramsFromPath.map((param) => ({ | ||
name: param, | ||
in: 'path', | ||
required: true, | ||
})) }, (options.setOperationId ? { operationId: path.id } : {})), (bodySchema | ||
const newPath = Object.assign(Object.assign(Object.assign({ description: path.route.description, summary: path.route.summary, deprecated: path.route.deprecated, tags: path.paths, parameters: [ | ||
...(paramsFromPath | ||
? paramsFromPath.map((param) => ({ | ||
name: param, | ||
in: 'path', | ||
required: true, | ||
})) | ||
: []), | ||
...(querySchema | ||
? [ | ||
{ | ||
name: 'query', | ||
in: 'query', | ||
schema: querySchema, | ||
}, | ||
] | ||
: []), | ||
] }, (options.setOperationId ? { operationId: path.id } : {})), (bodySchema | ||
? { | ||
@@ -80,0 +94,0 @@ requestBody: { |
{ | ||
"name": "@ts-rest/open-api", | ||
"version": "3.7.0", | ||
"version": "3.8.0", | ||
"peerDependenciesMeta": { | ||
@@ -17,3 +17,3 @@ "zod": { | ||
"zod-to-json-schema": "^3.x.x", | ||
"@ts-rest/core": "3.7.0" | ||
"@ts-rest/core": "3.8.0" | ||
}, | ||
@@ -20,0 +20,0 @@ "module": "./index.js", |
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
10874
222