@ts-rest/open-api
Advanced tools
Comparing version 3.19.4 to 3.19.5
17
index.js
@@ -1,2 +0,2 @@ | ||
import { isAppRoute, isZodObject } from '@ts-rest/core'; | ||
import { isAppRoute, isZodType, isZodObject, extractZodObjectShape } from '@ts-rest/core'; | ||
import { generateSchema } from '@anatine/zod-openapi'; | ||
@@ -23,8 +23,7 @@ | ||
}; | ||
const getOpenApiSchemaFromZod = (zodObject, useOutput = false) => { | ||
const isZodObj = isZodObject(zodObject); | ||
if (!isZodObj) { | ||
const getOpenApiSchemaFromZod = (zodType, useOutput = false) => { | ||
if (!isZodType(zodType)) { | ||
return null; | ||
} | ||
return generateSchema(zodObject, useOutput); | ||
return generateSchema(zodType, useOutput); | ||
}; | ||
@@ -34,5 +33,6 @@ const getPathParameters = (path, zodObject) => { | ||
const isZodObj = isZodObject(zodObject); | ||
const zodShape = isZodObj ? extractZodObjectShape(zodObject) : {}; | ||
const paramsFromPath = (_a = path | ||
.match(/{[^}]+}/g)) === null || _a === void 0 ? void 0 : _a.map((param) => param.slice(1, -1)).filter((param) => { | ||
return !isZodObj || !zodObject.shape[param]; | ||
return zodShape[param] === undefined; | ||
}); | ||
@@ -48,3 +48,3 @@ const params = (paramsFromPath === null || paramsFromPath === void 0 ? void 0 : paramsFromPath.map((param) => ({ | ||
if (isZodObj) { | ||
const paramsFromZod = Object.entries(zodObject.shape).map(([key, value]) => ({ | ||
const paramsFromZod = Object.entries(zodShape).map(([key, value]) => ({ | ||
name: key, | ||
@@ -64,3 +64,4 @@ in: 'path', | ||
} | ||
return Object.entries(zodObject.shape).map(([key, value]) => { | ||
const zodShape = extractZodObjectShape(zodObject); | ||
return Object.entries(zodShape).map(([key, value]) => { | ||
const schema = getOpenApiSchemaFromZod(value); | ||
@@ -67,0 +68,0 @@ const isObject = value._def.typeName === 'ZodObject'; |
{ | ||
"name": "@ts-rest/open-api", | ||
"version": "3.19.4", | ||
"version": "3.19.5", | ||
"dependencies": { | ||
@@ -10,3 +10,3 @@ "@anatine/zod-openapi": "^1.12.0", | ||
"zod": "^3.0.0", | ||
"@ts-rest/core": "3.19.4" | ||
"@ts-rest/core": "3.19.5" | ||
}, | ||
@@ -13,0 +13,0 @@ "typedoc": { |
Sorry, the diff of this file is not supported yet
20084
336