@asteasolutions/zod-to-openapi
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -252,4 +252,6 @@ "use strict"; | ||
}); | ||
const parameters = this.getParameters(request); | ||
const requestBody = this.getRequestBody(request === null || request === void 0 ? void 0 : request.body); | ||
const routeDoc = { | ||
[method]: Object.assign(Object.assign({}, pathItemConfig), { parameters: this.getParameters(request), requestBody: this.getRequestBody(request === null || request === void 0 ? void 0 : request.body), responses: generatedResponses }), | ||
[method]: Object.assign(Object.assign(Object.assign(Object.assign({}, pathItemConfig), (parameters.length > 0 ? { parameters } : {})), (requestBody ? { requestBody } : {})), { responses: generatedResponses }), | ||
}; | ||
@@ -357,3 +359,10 @@ this.pathRefs[path] = Object.assign(Object.assign({}, this.pathRefs[path]), routeDoc); | ||
} | ||
if (hasOpenAPIType) { | ||
if (zodSchema instanceof zod_1.ZodRecord) { | ||
const propertiesType = zodSchema._def.valueType; | ||
return { | ||
type: 'object', | ||
additionalProperties: this.generateInnerSchema(propertiesType), | ||
}; | ||
} | ||
if (zodSchema instanceof zod_1.ZodUnknown || hasOpenAPIType) { | ||
return {}; | ||
@@ -360,0 +369,0 @@ } |
import { ParameterObject, SchemaObject } from 'openapi3-ts'; | ||
import { z } from 'zod'; | ||
export interface ZodOpenAPIMetadata extends SchemaObject { | ||
export interface ZodOpenAPIMetadata<T = any> extends SchemaObject { | ||
refId?: string; | ||
param?: Partial<ParameterObject>; | ||
param?: Partial<ParameterObject> & { | ||
example?: T; | ||
}; | ||
example?: T; | ||
} | ||
@@ -12,5 +15,5 @@ declare module 'zod' { | ||
abstract class ZodSchema<Output, Def extends ZodTypeDef, Input = Output> { | ||
openapi<T extends ZodSchema<any>>(this: T, metadata: Partial<ZodOpenAPIMetadata>): T; | ||
openapi<T extends ZodSchema<any>>(this: T, metadata: Partial<ZodOpenAPIMetadata<z.infer<T>>>): T; | ||
} | ||
} | ||
export declare function extendZodWithOpenApi(zod: typeof z): void; |
{ | ||
"name": "@asteasolutions/zod-to-openapi", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Builds OpenAPI schemas from Zod schemas", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
43507
769