zod-openapi
Advanced tools
Comparing version 2.4.0 to 2.5.0
@@ -142,9 +142,11 @@ "use strict"; | ||
const createSchemaComponents = (componentsObject, components) => { | ||
Array.from(components.schemas).forEach(([schema, { type }]) => { | ||
Array.from(components.schemas).forEach(([schema, { type }], index) => { | ||
if (type === 'partial') { | ||
const state = { | ||
const state = (0, schema_1.newSchemaState)({ | ||
components, | ||
type: schema._def.openapi?.refType ?? 'output', | ||
}; | ||
(0, schema_1.createSchemaOrRef)(schema, state); | ||
path: [], | ||
visited: new Set(), | ||
}); | ||
(0, schema_1.createSchemaOrRef)(schema, state, [`component schema index ${index}`]); | ||
} | ||
@@ -174,5 +176,5 @@ }); | ||
const createParamComponents = (componentsObject, components) => { | ||
Array.from(components.parameters).forEach(([schema, component]) => { | ||
Array.from(components.parameters).forEach(([schema, component], index) => { | ||
if (component.type === 'partial') { | ||
(0, parameters_1.createParamOrRef)(schema, components, component.in, component.ref); | ||
(0, parameters_1.createParamOrRef)(schema, components, [`component parameter index ${index}`], component.in, component.ref); | ||
} | ||
@@ -228,5 +230,5 @@ }); | ||
const createResponseComponents = (components) => { | ||
Array.from(components.responses).forEach(([schema, component]) => { | ||
Array.from(components.responses).forEach(([schema, component], index) => { | ||
if (component.type === 'partial') { | ||
(0, responses_1.createResponse)(schema, components); | ||
(0, responses_1.createResponse)(schema, components, [`component response index ${index}`]); | ||
} | ||
@@ -246,5 +248,7 @@ }); | ||
const createRequestBodiesComponents = (components) => { | ||
Array.from(components.requestBodies).forEach(([schema, component]) => { | ||
Array.from(components.requestBodies).forEach(([schema, component], index) => { | ||
if (component.type === 'partial') { | ||
(0, paths_1.createRequestBody)(schema, components); | ||
(0, paths_1.createRequestBody)(schema, components, [ | ||
`component request body ${index}`, | ||
]); | ||
} | ||
@@ -251,0 +255,0 @@ }); |
@@ -6,3 +6,3 @@ "use strict"; | ||
const schema_1 = require("./schema"); | ||
const createMediaTypeSchema = (schemaObject, components, type) => { | ||
const createMediaTypeSchema = (schemaObject, components, type, subpath) => { | ||
if (!schemaObject) { | ||
@@ -14,8 +14,10 @@ return undefined; | ||
} | ||
return (0, schema_1.createSchemaOrRef)(schemaObject, { | ||
return (0, schema_1.createSchemaOrRef)(schemaObject, (0, schema_1.newSchemaState)({ | ||
components, | ||
type, | ||
}); | ||
path: [], | ||
visited: new Set(), | ||
}), subpath); | ||
}; | ||
const createMediaTypeObject = (mediaTypeObject, components, type) => { | ||
const createMediaTypeObject = (mediaTypeObject, components, type, subpath) => { | ||
if (!mediaTypeObject) { | ||
@@ -26,9 +28,12 @@ return undefined; | ||
...mediaTypeObject, | ||
schema: createMediaTypeSchema(mediaTypeObject.schema, components, type), | ||
schema: createMediaTypeSchema(mediaTypeObject.schema, components, type, [ | ||
...subpath, | ||
'schema', | ||
]), | ||
}; | ||
}; | ||
const createContent = (contentObject, components, type) => Object.entries(contentObject).reduce((acc, [path, zodOpenApiMediaTypeObject]) => { | ||
const mediaTypeObject = createMediaTypeObject(zodOpenApiMediaTypeObject, components, type); | ||
const createContent = (contentObject, components, type, subpath) => Object.entries(contentObject).reduce((acc, [mediaType, zodOpenApiMediaTypeObject]) => { | ||
const mediaTypeObject = createMediaTypeObject(zodOpenApiMediaTypeObject, components, type, [...subpath, mediaType]); | ||
if (mediaTypeObject) { | ||
acc[path] = mediaTypeObject; | ||
acc[mediaType] = mediaTypeObject; | ||
} | ||
@@ -35,0 +40,0 @@ return acc; |
@@ -9,9 +9,11 @@ "use strict"; | ||
exports.createComponentParamRef = createComponentParamRef; | ||
const createBaseParameter = (schema, components) => { | ||
const createBaseParameter = (schema, components, subpath) => { | ||
const { ref, ...rest } = schema._def.openapi?.param ?? {}; | ||
const state = { | ||
const state = (0, schema_1.newSchemaState)({ | ||
components, | ||
type: 'input', | ||
}; | ||
const schemaOrRef = (0, schema_1.createSchemaOrRef)(schema, state); | ||
path: [], | ||
visited: new Set(), | ||
}); | ||
const schemaOrRef = (0, schema_1.createSchemaOrRef)(schema, state, [...subpath, 'schema']); | ||
const required = !(0, optional_1.isOptionalSchema)(schema, state); | ||
@@ -25,3 +27,3 @@ return { | ||
exports.createBaseParameter = createBaseParameter; | ||
const createParamOrRef = (zodSchema, components, type, name) => { | ||
const createParamOrRef = (zodSchema, components, subpath, type, name) => { | ||
const component = components.parameters.get(zodSchema); | ||
@@ -46,3 +48,3 @@ const paramType = zodSchema._def?.openapi?.param?.in ?? component?.in ?? type; | ||
// Optional Objects can return a reference object | ||
const baseParamOrRef = (0, exports.createBaseParameter)(zodSchema, components); | ||
const baseParamOrRef = (0, exports.createBaseParameter)(zodSchema, components, subpath); | ||
if ('$ref' in baseParamOrRef) { | ||
@@ -72,21 +74,27 @@ throw new Error('Unexpected Error: received a reference object'); | ||
exports.createParamOrRef = createParamOrRef; | ||
const createParameters = (type, zodObject, components) => { | ||
const createParameters = (type, zodObject, components, subpath) => { | ||
if (!zodObject) { | ||
return []; | ||
} | ||
return Object.entries(zodObject.shape).map(([key, zodSchema]) => (0, exports.createParamOrRef)(zodSchema, components, type, key)); | ||
return Object.entries(zodObject.shape).map(([key, zodSchema]) => (0, exports.createParamOrRef)(zodSchema, components, [...subpath, key], type, key)); | ||
}; | ||
const createRequestParams = (requestParams, components) => { | ||
const createRequestParams = (requestParams, components, subpath) => { | ||
if (!requestParams) { | ||
return []; | ||
} | ||
const pathParams = createParameters('path', requestParams.path, components); | ||
const queryParams = createParameters('query', requestParams.query, components); | ||
const cookieParams = createParameters('cookie', requestParams.cookie, components); | ||
const headerParams = createParameters('header', requestParams.header, components); | ||
const pathParams = createParameters('path', requestParams.path, components, [ | ||
...subpath, | ||
'path', | ||
]); | ||
const queryParams = createParameters('query', requestParams.query, components, [...subpath, 'query']); | ||
const cookieParams = createParameters('cookie', requestParams.cookie, components, [...subpath, 'cookie']); | ||
const headerParams = createParameters('header', requestParams.header, components, [...subpath, 'header']); | ||
return [...pathParams, ...queryParams, ...cookieParams, ...headerParams]; | ||
}; | ||
const createManualParameters = (parameters, components) => parameters?.map((param) => { | ||
const createManualParameters = (parameters, components, subpath) => parameters?.map((param, index) => { | ||
if (param instanceof zod_1.ZodType) { | ||
return (0, exports.createParamOrRef)(param, components); | ||
return (0, exports.createParamOrRef)(param, components, [ | ||
...subpath, | ||
`param index ${index}`, | ||
]); | ||
} | ||
@@ -96,5 +104,5 @@ return param; | ||
exports.createManualParameters = createManualParameters; | ||
const createParametersObject = (parameters, requestParams, components) => { | ||
const manualParameters = (0, exports.createManualParameters)(parameters, components); | ||
const createdParams = createRequestParams(requestParams, components); | ||
const createParametersObject = (parameters, requestParams, components, subpath) => { | ||
const manualParameters = (0, exports.createManualParameters)(parameters, components, subpath); | ||
const createdParams = createRequestParams(requestParams, components, subpath); | ||
const combinedParameters = [ | ||
@@ -101,0 +109,0 @@ ...manualParameters, |
@@ -9,3 +9,3 @@ "use strict"; | ||
const specificationExtension_1 = require("./specificationExtension"); | ||
const createRequestBody = (requestBodyObject, components) => { | ||
const createRequestBody = (requestBodyObject, components, subpath) => { | ||
if (!requestBodyObject) { | ||
@@ -23,3 +23,6 @@ return undefined; | ||
...requestBodyObject, | ||
content: (0, content_1.createContent)(requestBodyObject.content, components, 'input'), | ||
content: (0, content_1.createContent)(requestBodyObject.content, components, 'input', [ | ||
...subpath, | ||
'content', | ||
]), | ||
}; | ||
@@ -39,10 +42,7 @@ if (ref) { | ||
exports.createRequestBody = createRequestBody; | ||
const createOperation = (operationObject, components) => { | ||
if (!operationObject) { | ||
return undefined; | ||
} | ||
const createOperation = (operationObject, components, subpath) => { | ||
const { parameters, requestParams, requestBody, responses, ...rest } = operationObject; | ||
const maybeParameters = (0, parameters_1.createParametersObject)(parameters, requestParams, components); | ||
const maybeRequestBody = (0, exports.createRequestBody)(operationObject.requestBody, components); | ||
const maybeResponses = (0, responses_1.createResponses)(operationObject.responses, components); | ||
const maybeParameters = (0, parameters_1.createParametersObject)(parameters, requestParams, components, [...subpath, 'parameters']); | ||
const maybeRequestBody = (0, exports.createRequestBody)(operationObject.requestBody, components, [...subpath, 'request body']); | ||
const maybeResponses = (0, responses_1.createResponses)(operationObject.responses, components, [...subpath, 'responses']); | ||
return { | ||
@@ -55,24 +55,21 @@ ...rest, | ||
}; | ||
const createPathItem = (pathObject, components) => { | ||
const { get, put, post, delete: del, options, head, patch, trace, ...rest } = pathObject; | ||
const maybeGet = createOperation(get, components); | ||
const maybePut = createOperation(put, components); | ||
const maybePost = createOperation(post, components); | ||
const maybeDelete = createOperation(del, components); | ||
const maybeOptions = createOperation(options, components); | ||
const maybeHead = createOperation(head, components); | ||
const maybePatch = createOperation(patch, components); | ||
const maybeTrace = createOperation(trace, components); | ||
return { | ||
...rest, | ||
...(get && { get: maybeGet }), | ||
...(put && { put: maybePut }), | ||
...(post && { post: maybePost }), | ||
...(del && { delete: maybeDelete }), | ||
...(options && { options: maybeOptions }), | ||
...(head && { head: maybeHead }), | ||
...(patch && { patch: maybePatch }), | ||
...(trace && { trace: maybeTrace }), | ||
}; | ||
}; | ||
const createPathItem = (pathObject, components, path) => Object.entries(pathObject).reduce((acc, [key, value]) => { | ||
if (!value) { | ||
return acc; | ||
} | ||
if (key === 'get' || | ||
key === 'put' || | ||
key === 'post' || | ||
key === 'delete' || | ||
key === 'options' || | ||
key === 'head' || | ||
key === 'patch' || | ||
key === 'trace') { | ||
acc[key] = createOperation(value, components, [path, key]); | ||
return acc; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
acc[key] = value; | ||
return acc; | ||
}, {}); | ||
const createPaths = (pathsObject, components) => { | ||
@@ -87,3 +84,3 @@ if (!pathsObject) { | ||
} | ||
acc[path] = createPathItem(pathItemObject, components); | ||
acc[path] = createPathItem(pathItemObject, components, path); | ||
return acc; | ||
@@ -90,0 +87,0 @@ }, {}); |
@@ -51,7 +51,9 @@ "use strict"; | ||
const { ref, ...rest } = schema._def.openapi?.header ?? {}; | ||
const state = { | ||
const state = (0, schema_1.newSchemaState)({ | ||
components, | ||
type: 'output', | ||
}; | ||
const schemaOrRef = (0, schema_1.createSchemaOrRef)(schema, state); | ||
path: [], | ||
visited: new Set(), | ||
}); | ||
const schemaOrRef = (0, schema_1.createSchemaOrRef)(schema, state, ['header']); | ||
const required = !(0, optional_1.isOptionalSchema)(schema, state); | ||
@@ -67,3 +69,3 @@ return { | ||
exports.createComponentHeaderRef = createComponentHeaderRef; | ||
const createResponse = (responseObject, components) => { | ||
const createResponse = (responseObject, components, subpath) => { | ||
if ('$ref' in responseObject) { | ||
@@ -81,3 +83,8 @@ return responseObject; | ||
...(maybeHeaders && { headers: maybeHeaders }), | ||
...(content && { content: (0, content_1.createContent)(content, components, 'output') }), | ||
...(content && { | ||
content: (0, content_1.createContent)(content, components, 'output', [ | ||
...subpath, | ||
'content', | ||
]), | ||
}), | ||
}; | ||
@@ -98,8 +105,11 @@ const responseRef = ref ?? component?.ref; | ||
exports.createResponse = createResponse; | ||
const createResponses = (responsesObject, components) => Object.entries(responsesObject).reduce((acc, [path, responseObject]) => { | ||
if ((0, specificationExtension_1.isISpecificationExtension)(path)) { | ||
acc[path] = responseObject; | ||
const createResponses = (responsesObject, components, subpath) => Object.entries(responsesObject).reduce((acc, [statusCode, responseObject]) => { | ||
if ((0, specificationExtension_1.isISpecificationExtension)(statusCode)) { | ||
acc[statusCode] = responseObject; | ||
return acc; | ||
} | ||
acc[path] = (0, exports.createResponse)(responseObject, components); | ||
acc[statusCode] = (0, exports.createResponse)(responseObject, components, [ | ||
...subpath, | ||
statusCode, | ||
]); | ||
return acc; | ||
@@ -106,0 +116,0 @@ }, {}); |
@@ -11,3 +11,3 @@ "use strict"; | ||
type: 'array', | ||
items: (0, _1.createSchemaOrRef)(zodType, state), | ||
items: (0, _1.createSchemaOrRef)(zodType, state, ['array items']), | ||
...(minItems !== undefined && { minItems }), | ||
@@ -14,0 +14,0 @@ ...(maxItems !== undefined && { maxItems }), |
@@ -5,4 +5,4 @@ "use strict"; | ||
const _1 = require("."); | ||
const createBrandedSchema = (zodBranded, state) => (0, _1.createSchemaOrRef)(zodBranded._def.type, state); | ||
const createBrandedSchema = (zodBranded, state) => (0, _1.createSchemaOrRef)(zodBranded._def.type, state, ['brand']); | ||
exports.createBrandedSchema = createBrandedSchema; | ||
//# sourceMappingURL=brand.js.map |
@@ -5,4 +5,4 @@ "use strict"; | ||
const _1 = require("."); | ||
const createCatchSchema = (zodCatch, state) => (0, _1.createSchemaOrRef)(zodCatch._def.innerType, state); | ||
const createCatchSchema = (zodCatch, state) => (0, _1.createSchemaOrRef)(zodCatch._def.innerType, state, ['catch']); | ||
exports.createCatchSchema = createCatchSchema; | ||
//# sourceMappingURL=catch.js.map |
@@ -7,3 +7,3 @@ "use strict"; | ||
const createDefaultSchema = (zodDefault, state) => { | ||
const schemaOrRef = (0, _1.createSchemaOrRef)(zodDefault._def.innerType, state); | ||
const schemaOrRef = (0, _1.createSchemaOrRef)(zodDefault._def.innerType, state, ['default']); | ||
return (0, metadata_1.enhanceWithMetadata)(schemaOrRef, { | ||
@@ -10,0 +10,0 @@ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment |
@@ -8,4 +8,4 @@ "use strict"; | ||
const options = zodDiscriminatedUnion.options; | ||
const schemas = options.map((option) => (0, _1.createSchemaOrRef)(option, state)); | ||
const discriminator = (0, exports.mapDiscriminator)(schemas, options, zodDiscriminatedUnion.discriminator); | ||
const schemas = options.map((option, index) => (0, _1.createSchemaOrRef)(option, state, [`discriminated union option ${index}`])); | ||
const discriminator = (0, exports.mapDiscriminator)(schemas, options, zodDiscriminatedUnion.discriminator, state); | ||
return { | ||
@@ -17,3 +17,3 @@ oneOf: schemas, | ||
exports.createDiscriminatedUnionSchema = createDiscriminatedUnionSchema; | ||
const mapDiscriminator = (schemas, zodObjects, discriminator) => { | ||
const mapDiscriminator = (schemas, zodObjects, discriminator, state) => { | ||
if (typeof discriminator !== 'string') { | ||
@@ -38,3 +38,3 @@ return undefined; | ||
if (typeof literalValue !== 'string') { | ||
throw new Error(`Discriminator ${discriminator} could not be found in one of the values of a discriminated union`); | ||
throw new Error(`Discriminator ${discriminator} could not be found in on index ${index} of a discriminated union at ${state.path.join(' > ')}`); | ||
} | ||
@@ -41,0 +41,0 @@ mapping[literalValue] = componentSchemaRef; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createSchemaOrRef = exports.createSchema = void 0; | ||
exports.createSchemaOrRef = exports.createSchemaWithMetadata = exports.createSchema = exports.newSchemaState = void 0; | ||
const zod_1 = require("zod"); | ||
const components_1 = require("../components"); | ||
const errors_1 = require("../errors"); | ||
const array_1 = require("./array"); | ||
@@ -36,5 +35,32 @@ const boolean_1 = require("./boolean"); | ||
const unknown_1 = require("./unknown"); | ||
const createSchema = (zodSchema, state) => { | ||
const newSchemaState = (state) => ({ | ||
type: state.type, | ||
components: state.components, | ||
path: [...state.path], | ||
visited: new Set(state.visited), | ||
}); | ||
exports.newSchemaState = newSchemaState; | ||
const createSchema = (zodSchema, state, subpath) => { | ||
state.path.push(...subpath); | ||
if (state.visited.has(zodSchema)) { | ||
throw new Error(`The schema at ${state.path.join(' > ')} needs to be registered because it's circularly referenced`); | ||
} | ||
state.visited.add(zodSchema); | ||
const schema = (0, exports.createSchemaWithMetadata)(zodSchema, state); | ||
return schema; | ||
}; | ||
exports.createSchema = createSchema; | ||
const createSchemaWithMetadata = (zodSchema, state) => { | ||
const { effectType, param, header, ref, refType, ...additionalMetadata } = zodSchema._def.openapi ?? {}; | ||
const schemaOrRef = createSchemaSwitch(zodSchema, state); | ||
const description = zodSchema.description; | ||
return (0, metadata_1.enhanceWithMetadata)(schemaOrRef, { | ||
...(description && { description }), | ||
...additionalMetadata, | ||
}); | ||
}; | ||
exports.createSchemaWithMetadata = createSchemaWithMetadata; | ||
const createSchemaSwitch = (zodSchema, state) => { | ||
if (zodSchema._def.openapi?.type) { | ||
return (0, manual_1.createManualTypeSchema)(zodSchema); | ||
return (0, manual_1.createManualTypeSchema)(zodSchema, state); | ||
} | ||
@@ -128,6 +154,5 @@ if (zodSchema instanceof zod_1.ZodString) { | ||
} | ||
return (0, manual_1.createManualTypeSchema)(zodSchema); | ||
return (0, manual_1.createManualTypeSchema)(zodSchema, state); | ||
}; | ||
exports.createSchema = createSchema; | ||
const createSchemaOrRef = (zodSchema, state) => { | ||
const createSchemaOrRef = (zodSchema, state, subpath) => { | ||
const component = state.components.schemas.get(zodSchema); | ||
@@ -154,11 +179,7 @@ if (component && component.type === 'complete') { | ||
} | ||
const newState = { | ||
components: state.components, | ||
type: state.type, | ||
lazy: state.lazy, | ||
}; | ||
const schemaOrRef = (0, metadata_1.createSchemaWithMetadata)(zodSchema, newState); | ||
const newState = (0, exports.newSchemaState)(state); | ||
const schemaOrRef = (0, exports.createSchema)(zodSchema, newState, subpath); | ||
if (newState.effectType) { | ||
if (state.effectType && newState.effectType !== state.effectType) { | ||
(0, errors_1.throwTransformError)(zodSchema); | ||
(0, transform_1.throwTransformError)(zodSchema, newState); | ||
} | ||
@@ -165,0 +186,0 @@ state.effectType = newState.effectType; |
@@ -7,4 +7,8 @@ "use strict"; | ||
allOf: [ | ||
(0, _1.createSchemaOrRef)(zodIntersection._def.left, state), | ||
(0, _1.createSchemaOrRef)(zodIntersection._def.right, state), | ||
(0, _1.createSchemaOrRef)(zodIntersection._def.left, state, [ | ||
'intersection left', | ||
]), | ||
(0, _1.createSchemaOrRef)(zodIntersection._def.right, state, [ | ||
'intersection right', | ||
]), | ||
], | ||
@@ -11,0 +15,0 @@ }); |
@@ -7,10 +7,5 @@ "use strict"; | ||
const innerSchema = zodLazy._def.getter(); | ||
if (state.lazy?.get(zodLazy)) { | ||
throw new Error(`The ZodLazy Schema ${JSON.stringify(zodLazy._def)} or inner ZodLazy Schema ${JSON.stringify(innerSchema._def)} must be registered`); | ||
} | ||
state.lazy ??= new Map(); | ||
state.lazy.set(zodLazy, true); | ||
return (0, _1.createSchemaOrRef)(innerSchema, state); | ||
return (0, _1.createSchemaOrRef)(innerSchema, state, ['lazy schema']); | ||
}; | ||
exports.createLazySchema = createLazySchema; | ||
//# sourceMappingURL=lazy.js.map |
@@ -5,3 +5,3 @@ "use strict"; | ||
const zod_1 = require("zod"); | ||
const createManualTypeSchema = (zodSchema) => { | ||
const createManualTypeSchema = (zodSchema, state) => { | ||
if (!zodSchema._def.openapi?.type) { | ||
@@ -11,3 +11,3 @@ const zodType = zodSchema.constructor.name; | ||
const schemaName = `${zodType} - ${zodSchema._def.effect.type}`; | ||
throw new Error(`Unknown schema ${schemaName}. Please assign it a manual 'type', wrap it in a ZodPipeline or change the 'effectType'.`); | ||
throw new Error(`Unknown schema ${schemaName} at ${state.path.join(' > ')}. Please assign it a manual 'type', wrap it in a ZodPipeline or change the 'effectType'.`); | ||
} | ||
@@ -14,0 +14,0 @@ throw new Error(`Unknown schema ${zodType}. Please assign it a manual 'type'.`); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.enhanceWithMetadata = exports.createSchemaWithMetadata = void 0; | ||
const _1 = require("."); | ||
const createSchemaWithMetadata = (zodSchema, state) => { | ||
const { effectType, param, header, ref, refType, ...additionalMetadata } = zodSchema._def.openapi ?? {}; | ||
const schemaOrRef = (0, _1.createSchema)(zodSchema, state); | ||
const description = zodSchema.description; | ||
return (0, exports.enhanceWithMetadata)(schemaOrRef, { | ||
...(description && { description }), | ||
...additionalMetadata, | ||
}); | ||
}; | ||
exports.createSchemaWithMetadata = createSchemaWithMetadata; | ||
exports.enhanceWithMetadata = void 0; | ||
const enhanceWithMetadata = (schemaOrRef, metadata) => { | ||
@@ -16,0 +5,0 @@ if ('$ref' in schemaOrRef) { |
@@ -7,3 +7,3 @@ "use strict"; | ||
const createNullableSchema = (zodNullable, state) => { | ||
const schemaOrReference = (0, _1.createSchemaOrRef)(zodNullable.unwrap(), state); | ||
const schemaOrReference = (0, _1.createSchemaOrRef)(zodNullable.unwrap(), state, ['nullable']); | ||
if ('$ref' in schemaOrReference || schemaOrReference.allOf) { | ||
@@ -10,0 +10,0 @@ return { |
@@ -25,3 +25,3 @@ "use strict"; | ||
if (component || baseZodObject._def.openapi?.ref) { | ||
(0, _1.createSchemaOrRef)(baseZodObject, state); | ||
(0, _1.createSchemaOrRef)(baseZodObject, state, ['extended schema']); | ||
} | ||
@@ -83,3 +83,5 @@ const completeComponent = state.components.schemas.get(baseZodObject); | ||
...(!(catchAll instanceof zod_1.ZodNever) && { | ||
additionalProperties: (0, _1.createSchemaOrRef)(catchAll, state), | ||
additionalProperties: (0, _1.createSchemaOrRef)(catchAll, state, [ | ||
'additional properties', | ||
]), | ||
}), | ||
@@ -99,3 +101,3 @@ }); | ||
const mapProperties = (shape, state) => Object.entries(shape).reduce((acc, [key, zodSchema]) => { | ||
acc[key] = (0, _1.createSchemaOrRef)(zodSchema, state); | ||
acc[key] = (0, _1.createSchemaOrRef)(zodSchema, state, [`property: ${key}`]); | ||
return acc; | ||
@@ -102,0 +104,0 @@ }, {}); |
@@ -6,5 +6,4 @@ "use strict"; | ||
const _1 = require("."); | ||
const createOptionalSchema = (zodOptional, state) => | ||
// Optional doesn't change OpenAPI schema | ||
(0, _1.createSchemaOrRef)(zodOptional.unwrap(), state); | ||
const createOptionalSchema = (zodOptional, state) => // Optional doesn't change OpenAPI schema | ||
(0, _1.createSchemaOrRef)(zodOptional.unwrap(), state, ['optional']); | ||
exports.createOptionalSchema = createOptionalSchema; | ||
@@ -11,0 +10,0 @@ const isOptionalSchema = (zodSchema, state) => { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createPipelineSchema = void 0; | ||
const errors_1 = require("../errors"); | ||
const transform_1 = require("./transform"); | ||
const _1 = require("."); | ||
const createPipelineSchema = (zodPipeline, state) => { | ||
if (zodPipeline._def.openapi?.effectType === 'input') { | ||
return (0, _1.createSchemaOrRef)(zodPipeline._def.in, state); | ||
return (0, _1.createSchemaOrRef)(zodPipeline._def.in, state, [ | ||
'pipeline input', | ||
]); | ||
} | ||
if (zodPipeline._def.openapi?.effectType === 'output') { | ||
return (0, _1.createSchemaOrRef)(zodPipeline._def.out, state); | ||
return (0, _1.createSchemaOrRef)(zodPipeline._def.out, state, [ | ||
'pipeline output', | ||
]); | ||
} | ||
if (state.type === 'input') { | ||
if (state.effectType === 'output') { | ||
(0, errors_1.throwTransformError)(zodPipeline); | ||
(0, transform_1.throwTransformError)(zodPipeline, state); | ||
} | ||
state.effectType = 'input'; | ||
return (0, _1.createSchemaOrRef)(zodPipeline._def.in, state); | ||
return (0, _1.createSchemaOrRef)(zodPipeline._def.in, state, [ | ||
'pipeline input', | ||
]); | ||
} | ||
if (state.effectType === 'input') { | ||
(0, errors_1.throwTransformError)(zodPipeline); | ||
(0, transform_1.throwTransformError)(zodPipeline, state); | ||
} | ||
state.effectType = 'output'; | ||
return (0, _1.createSchemaOrRef)(zodPipeline._def.out, state); | ||
return (0, _1.createSchemaOrRef)(zodPipeline._def.out, state, [ | ||
'pipeline output', | ||
]); | ||
}; | ||
exports.createPipelineSchema = createPipelineSchema; | ||
//# sourceMappingURL=pipeline.js.map |
@@ -5,4 +5,6 @@ "use strict"; | ||
const _1 = require("."); | ||
const createPreprocessSchema = (zodPreprocess, state) => (0, _1.createSchemaOrRef)(zodPreprocess._def.schema, state); | ||
const createPreprocessSchema = (zodPreprocess, state) => (0, _1.createSchemaOrRef)(zodPreprocess._def.schema, state, [ | ||
'preprocess schema', | ||
]); | ||
exports.createPreprocessSchema = createPreprocessSchema; | ||
//# sourceMappingURL=preprocess.js.map |
@@ -7,5 +7,5 @@ "use strict"; | ||
type: 'object', | ||
additionalProperties: (0, _1.createSchemaOrRef)(zodRecord.valueSchema, state), | ||
additionalProperties: (0, _1.createSchemaOrRef)(zodRecord.valueSchema, state, ['record value']), | ||
}); | ||
exports.createRecordSchema = createRecordSchema; | ||
//# sourceMappingURL=record.js.map |
@@ -5,4 +5,4 @@ "use strict"; | ||
const _1 = require("."); | ||
const createRefineSchema = (zodRefine, state) => (0, _1.createSchemaOrRef)(zodRefine._def.schema, state); | ||
const createRefineSchema = (zodRefine, state) => (0, _1.createSchemaOrRef)(zodRefine._def.schema, state, ['refine schema']); | ||
exports.createRefineSchema = createRefineSchema; | ||
//# sourceMappingURL=refine.js.map |
@@ -11,3 +11,3 @@ "use strict"; | ||
type: 'array', | ||
items: (0, _1.createSchemaOrRef)(schema, state), | ||
items: (0, _1.createSchemaOrRef)(schema, state, ['set items']), | ||
uniqueItems: true, | ||
@@ -14,0 +14,0 @@ ...(minItems !== undefined && { minItems }), |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createTransformSchema = void 0; | ||
const errors_1 = require("../errors"); | ||
exports.throwTransformError = exports.createTransformSchema = void 0; | ||
const manual_1 = require("./manual"); | ||
@@ -9,17 +8,25 @@ const _1 = require("."); | ||
if (zodTransform._def.openapi?.effectType === 'output') { | ||
return (0, manual_1.createManualTypeSchema)(zodTransform); | ||
return (0, manual_1.createManualTypeSchema)(zodTransform, state); | ||
} | ||
if (zodTransform._def.openapi?.effectType === 'input') { | ||
return (0, _1.createSchemaOrRef)(zodTransform._def.schema, state); | ||
return (0, _1.createSchemaOrRef)(zodTransform._def.schema, state, [ | ||
'transform input', | ||
]); | ||
} | ||
if (state.type === 'output') { | ||
return (0, manual_1.createManualTypeSchema)(zodTransform); | ||
return (0, manual_1.createManualTypeSchema)(zodTransform, state); | ||
} | ||
if (state.effectType === 'output') { | ||
(0, errors_1.throwTransformError)(zodTransform); | ||
(0, exports.throwTransformError)(zodTransform, state); | ||
} | ||
state.effectType = 'input'; | ||
return (0, _1.createSchemaOrRef)(zodTransform._def.schema, state); | ||
return (0, _1.createSchemaOrRef)(zodTransform._def.schema, state, [ | ||
'transform input', | ||
]); | ||
}; | ||
exports.createTransformSchema = createTransformSchema; | ||
const throwTransformError = (zodType, state) => { | ||
throw new Error(`${JSON.stringify(zodType)} at ${state.path.join(' > ')} contains a transform but is used in both an input and an output. This is likely a mistake. Set an \`effectType\` to resolve`); | ||
}; | ||
exports.throwTransformError = throwTransformError; | ||
//# sourceMappingURL=transform.js.map |
@@ -17,3 +17,3 @@ "use strict"; | ||
if (items.length) { | ||
return items.map((item) => (0, _1.createSchemaOrRef)(item, state)); | ||
return items.map((item, index) => (0, _1.createSchemaOrRef)(item, state, [`tuple item ${index}`])); | ||
} | ||
@@ -33,3 +33,3 @@ return undefined; | ||
return { | ||
items: (0, _1.createSchemaOrRef)(rest, state), | ||
items: (0, _1.createSchemaOrRef)(rest, state, ['tuple items']), | ||
...(prefixItems && { prefixItems }), | ||
@@ -48,3 +48,6 @@ }; | ||
items: { | ||
oneOf: [...prefixItems, (0, _1.createSchemaOrRef)(rest, state)], | ||
oneOf: [ | ||
...prefixItems, | ||
(0, _1.createSchemaOrRef)(rest, state, ['tuple items']), | ||
], | ||
}, | ||
@@ -51,0 +54,0 @@ }), |
@@ -7,3 +7,3 @@ "use strict"; | ||
const options = zodUnion.options; | ||
const schemas = options.map((option) => (0, _1.createSchemaOrRef)(option, state)); | ||
const schemas = options.map((option, index) => (0, _1.createSchemaOrRef)(option, state, [`union option ${index}`])); | ||
return { | ||
@@ -10,0 +10,0 @@ anyOf: schemas, |
@@ -5,6 +5,6 @@ "use strict"; | ||
function extendZodWithOpenApi(zod) { | ||
if (typeof zod.ZodSchema.prototype.openapi !== 'undefined') { | ||
if (typeof zod.ZodType.prototype.openapi !== 'undefined') { | ||
return; | ||
} | ||
zod.ZodSchema.prototype.openapi = function (openapi) { | ||
zod.ZodType.prototype.openapi = function (openapi) { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment | ||
@@ -11,0 +11,0 @@ const result = new this.constructor({ |
@@ -5,3 +5,3 @@ import { ZodType } from 'zod'; | ||
import { createHeaderOrRef, createResponse } from './responses'; | ||
import { createSchemaOrRef } from './schema'; | ||
import { createSchemaOrRef, newSchemaState } from './schema'; | ||
export const getDefaultComponents = (componentsObject, openapi = '3.1.0') => { | ||
@@ -135,9 +135,11 @@ const defaultComponents = { | ||
const createSchemaComponents = (componentsObject, components) => { | ||
Array.from(components.schemas).forEach(([schema, { type }]) => { | ||
Array.from(components.schemas).forEach(([schema, { type }], index) => { | ||
if (type === 'partial') { | ||
const state = { | ||
const state = newSchemaState({ | ||
components, | ||
type: schema._def.openapi?.refType ?? 'output', | ||
}; | ||
createSchemaOrRef(schema, state); | ||
path: [], | ||
visited: new Set(), | ||
}); | ||
createSchemaOrRef(schema, state, [`component schema index ${index}`]); | ||
} | ||
@@ -167,5 +169,5 @@ }); | ||
const createParamComponents = (componentsObject, components) => { | ||
Array.from(components.parameters).forEach(([schema, component]) => { | ||
Array.from(components.parameters).forEach(([schema, component], index) => { | ||
if (component.type === 'partial') { | ||
createParamOrRef(schema, components, component.in, component.ref); | ||
createParamOrRef(schema, components, [`component parameter index ${index}`], component.in, component.ref); | ||
} | ||
@@ -221,5 +223,5 @@ }); | ||
const createResponseComponents = (components) => { | ||
Array.from(components.responses).forEach(([schema, component]) => { | ||
Array.from(components.responses).forEach(([schema, component], index) => { | ||
if (component.type === 'partial') { | ||
createResponse(schema, components); | ||
createResponse(schema, components, [`component response index ${index}`]); | ||
} | ||
@@ -239,5 +241,7 @@ }); | ||
const createRequestBodiesComponents = (components) => { | ||
Array.from(components.requestBodies).forEach(([schema, component]) => { | ||
Array.from(components.requestBodies).forEach(([schema, component], index) => { | ||
if (component.type === 'partial') { | ||
createRequestBody(schema, components); | ||
createRequestBody(schema, components, [ | ||
`component request body ${index}`, | ||
]); | ||
} | ||
@@ -244,0 +248,0 @@ }); |
import { ZodType } from 'zod'; | ||
import { createSchemaOrRef } from './schema'; | ||
const createMediaTypeSchema = (schemaObject, components, type) => { | ||
import { createSchemaOrRef, newSchemaState } from './schema'; | ||
const createMediaTypeSchema = (schemaObject, components, type, subpath) => { | ||
if (!schemaObject) { | ||
@@ -10,8 +10,10 @@ return undefined; | ||
} | ||
return createSchemaOrRef(schemaObject, { | ||
return createSchemaOrRef(schemaObject, newSchemaState({ | ||
components, | ||
type, | ||
}); | ||
path: [], | ||
visited: new Set(), | ||
}), subpath); | ||
}; | ||
const createMediaTypeObject = (mediaTypeObject, components, type) => { | ||
const createMediaTypeObject = (mediaTypeObject, components, type, subpath) => { | ||
if (!mediaTypeObject) { | ||
@@ -22,9 +24,12 @@ return undefined; | ||
...mediaTypeObject, | ||
schema: createMediaTypeSchema(mediaTypeObject.schema, components, type), | ||
schema: createMediaTypeSchema(mediaTypeObject.schema, components, type, [ | ||
...subpath, | ||
'schema', | ||
]), | ||
}; | ||
}; | ||
export const createContent = (contentObject, components, type) => Object.entries(contentObject).reduce((acc, [path, zodOpenApiMediaTypeObject]) => { | ||
const mediaTypeObject = createMediaTypeObject(zodOpenApiMediaTypeObject, components, type); | ||
export const createContent = (contentObject, components, type, subpath) => Object.entries(contentObject).reduce((acc, [mediaType, zodOpenApiMediaTypeObject]) => { | ||
const mediaTypeObject = createMediaTypeObject(zodOpenApiMediaTypeObject, components, type, [...subpath, mediaType]); | ||
if (mediaTypeObject) { | ||
acc[path] = mediaTypeObject; | ||
acc[mediaType] = mediaTypeObject; | ||
} | ||
@@ -31,0 +36,0 @@ return acc; |
import { ZodType } from 'zod'; | ||
import { createSchemaOrRef } from './schema'; | ||
import { createSchemaOrRef, newSchemaState } from './schema'; | ||
import { isOptionalSchema } from './schema/optional'; | ||
export const createComponentParamRef = (ref) => `#/components/parameters/${ref}`; | ||
export const createBaseParameter = (schema, components) => { | ||
export const createBaseParameter = (schema, components, subpath) => { | ||
const { ref, ...rest } = schema._def.openapi?.param ?? {}; | ||
const state = { | ||
const state = newSchemaState({ | ||
components, | ||
type: 'input', | ||
}; | ||
const schemaOrRef = createSchemaOrRef(schema, state); | ||
path: [], | ||
visited: new Set(), | ||
}); | ||
const schemaOrRef = createSchemaOrRef(schema, state, [...subpath, 'schema']); | ||
const required = !isOptionalSchema(schema, state); | ||
@@ -19,3 +21,3 @@ return { | ||
}; | ||
export const createParamOrRef = (zodSchema, components, type, name) => { | ||
export const createParamOrRef = (zodSchema, components, subpath, type, name) => { | ||
const component = components.parameters.get(zodSchema); | ||
@@ -40,3 +42,3 @@ const paramType = zodSchema._def?.openapi?.param?.in ?? component?.in ?? type; | ||
// Optional Objects can return a reference object | ||
const baseParamOrRef = createBaseParameter(zodSchema, components); | ||
const baseParamOrRef = createBaseParameter(zodSchema, components, subpath); | ||
if ('$ref' in baseParamOrRef) { | ||
@@ -65,27 +67,33 @@ throw new Error('Unexpected Error: received a reference object'); | ||
}; | ||
const createParameters = (type, zodObject, components) => { | ||
const createParameters = (type, zodObject, components, subpath) => { | ||
if (!zodObject) { | ||
return []; | ||
} | ||
return Object.entries(zodObject.shape).map(([key, zodSchema]) => createParamOrRef(zodSchema, components, type, key)); | ||
return Object.entries(zodObject.shape).map(([key, zodSchema]) => createParamOrRef(zodSchema, components, [...subpath, key], type, key)); | ||
}; | ||
const createRequestParams = (requestParams, components) => { | ||
const createRequestParams = (requestParams, components, subpath) => { | ||
if (!requestParams) { | ||
return []; | ||
} | ||
const pathParams = createParameters('path', requestParams.path, components); | ||
const queryParams = createParameters('query', requestParams.query, components); | ||
const cookieParams = createParameters('cookie', requestParams.cookie, components); | ||
const headerParams = createParameters('header', requestParams.header, components); | ||
const pathParams = createParameters('path', requestParams.path, components, [ | ||
...subpath, | ||
'path', | ||
]); | ||
const queryParams = createParameters('query', requestParams.query, components, [...subpath, 'query']); | ||
const cookieParams = createParameters('cookie', requestParams.cookie, components, [...subpath, 'cookie']); | ||
const headerParams = createParameters('header', requestParams.header, components, [...subpath, 'header']); | ||
return [...pathParams, ...queryParams, ...cookieParams, ...headerParams]; | ||
}; | ||
export const createManualParameters = (parameters, components) => parameters?.map((param) => { | ||
export const createManualParameters = (parameters, components, subpath) => parameters?.map((param, index) => { | ||
if (param instanceof ZodType) { | ||
return createParamOrRef(param, components); | ||
return createParamOrRef(param, components, [ | ||
...subpath, | ||
`param index ${index}`, | ||
]); | ||
} | ||
return param; | ||
}) ?? []; | ||
export const createParametersObject = (parameters, requestParams, components) => { | ||
const manualParameters = createManualParameters(parameters, components); | ||
const createdParams = createRequestParams(requestParams, components); | ||
export const createParametersObject = (parameters, requestParams, components, subpath) => { | ||
const manualParameters = createManualParameters(parameters, components, subpath); | ||
const createdParams = createRequestParams(requestParams, components, subpath); | ||
const combinedParameters = [ | ||
@@ -92,0 +100,0 @@ ...manualParameters, |
@@ -6,3 +6,3 @@ import { createComponentRequestBodyRef, } from './components'; | ||
import { isISpecificationExtension } from './specificationExtension'; | ||
export const createRequestBody = (requestBodyObject, components) => { | ||
export const createRequestBody = (requestBodyObject, components, subpath) => { | ||
if (!requestBodyObject) { | ||
@@ -20,3 +20,6 @@ return undefined; | ||
...requestBodyObject, | ||
content: createContent(requestBodyObject.content, components, 'input'), | ||
content: createContent(requestBodyObject.content, components, 'input', [ | ||
...subpath, | ||
'content', | ||
]), | ||
}; | ||
@@ -35,10 +38,7 @@ if (ref) { | ||
}; | ||
const createOperation = (operationObject, components) => { | ||
if (!operationObject) { | ||
return undefined; | ||
} | ||
const createOperation = (operationObject, components, subpath) => { | ||
const { parameters, requestParams, requestBody, responses, ...rest } = operationObject; | ||
const maybeParameters = createParametersObject(parameters, requestParams, components); | ||
const maybeRequestBody = createRequestBody(operationObject.requestBody, components); | ||
const maybeResponses = createResponses(operationObject.responses, components); | ||
const maybeParameters = createParametersObject(parameters, requestParams, components, [...subpath, 'parameters']); | ||
const maybeRequestBody = createRequestBody(operationObject.requestBody, components, [...subpath, 'request body']); | ||
const maybeResponses = createResponses(operationObject.responses, components, [...subpath, 'responses']); | ||
return { | ||
@@ -51,24 +51,21 @@ ...rest, | ||
}; | ||
const createPathItem = (pathObject, components) => { | ||
const { get, put, post, delete: del, options, head, patch, trace, ...rest } = pathObject; | ||
const maybeGet = createOperation(get, components); | ||
const maybePut = createOperation(put, components); | ||
const maybePost = createOperation(post, components); | ||
const maybeDelete = createOperation(del, components); | ||
const maybeOptions = createOperation(options, components); | ||
const maybeHead = createOperation(head, components); | ||
const maybePatch = createOperation(patch, components); | ||
const maybeTrace = createOperation(trace, components); | ||
return { | ||
...rest, | ||
...(get && { get: maybeGet }), | ||
...(put && { put: maybePut }), | ||
...(post && { post: maybePost }), | ||
...(del && { delete: maybeDelete }), | ||
...(options && { options: maybeOptions }), | ||
...(head && { head: maybeHead }), | ||
...(patch && { patch: maybePatch }), | ||
...(trace && { trace: maybeTrace }), | ||
}; | ||
}; | ||
const createPathItem = (pathObject, components, path) => Object.entries(pathObject).reduce((acc, [key, value]) => { | ||
if (!value) { | ||
return acc; | ||
} | ||
if (key === 'get' || | ||
key === 'put' || | ||
key === 'post' || | ||
key === 'delete' || | ||
key === 'options' || | ||
key === 'head' || | ||
key === 'patch' || | ||
key === 'trace') { | ||
acc[key] = createOperation(value, components, [path, key]); | ||
return acc; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
acc[key] = value; | ||
return acc; | ||
}, {}); | ||
export const createPaths = (pathsObject, components) => { | ||
@@ -83,3 +80,3 @@ if (!pathsObject) { | ||
} | ||
acc[path] = createPathItem(pathItemObject, components); | ||
acc[path] = createPathItem(pathItemObject, components, path); | ||
return acc; | ||
@@ -86,0 +83,0 @@ }, {}); |
import { ZodType } from 'zod'; | ||
import { createComponentResponseRef, } from './components'; | ||
import { createContent } from './content'; | ||
import { createSchemaOrRef } from './schema'; | ||
import { createSchemaOrRef, newSchemaState } from './schema'; | ||
import { isOptionalSchema } from './schema/optional'; | ||
@@ -46,7 +46,9 @@ import { isISpecificationExtension } from './specificationExtension'; | ||
const { ref, ...rest } = schema._def.openapi?.header ?? {}; | ||
const state = { | ||
const state = newSchemaState({ | ||
components, | ||
type: 'output', | ||
}; | ||
const schemaOrRef = createSchemaOrRef(schema, state); | ||
path: [], | ||
visited: new Set(), | ||
}); | ||
const schemaOrRef = createSchemaOrRef(schema, state, ['header']); | ||
const required = !isOptionalSchema(schema, state); | ||
@@ -60,3 +62,3 @@ return { | ||
export const createComponentHeaderRef = (ref) => `#/components/headers/${ref}`; | ||
export const createResponse = (responseObject, components) => { | ||
export const createResponse = (responseObject, components, subpath) => { | ||
if ('$ref' in responseObject) { | ||
@@ -74,3 +76,8 @@ return responseObject; | ||
...(maybeHeaders && { headers: maybeHeaders }), | ||
...(content && { content: createContent(content, components, 'output') }), | ||
...(content && { | ||
content: createContent(content, components, 'output', [ | ||
...subpath, | ||
'content', | ||
]), | ||
}), | ||
}; | ||
@@ -90,10 +97,13 @@ const responseRef = ref ?? component?.ref; | ||
}; | ||
export const createResponses = (responsesObject, components) => Object.entries(responsesObject).reduce((acc, [path, responseObject]) => { | ||
if (isISpecificationExtension(path)) { | ||
acc[path] = responseObject; | ||
export const createResponses = (responsesObject, components, subpath) => Object.entries(responsesObject).reduce((acc, [statusCode, responseObject]) => { | ||
if (isISpecificationExtension(statusCode)) { | ||
acc[statusCode] = responseObject; | ||
return acc; | ||
} | ||
acc[path] = createResponse(responseObject, components); | ||
acc[statusCode] = createResponse(responseObject, components, [ | ||
...subpath, | ||
statusCode, | ||
]); | ||
return acc; | ||
}, {}); | ||
//# sourceMappingURL=responses.js.map |
@@ -8,3 +8,3 @@ import { createSchemaOrRef } from '.'; | ||
type: 'array', | ||
items: createSchemaOrRef(zodType, state), | ||
items: createSchemaOrRef(zodType, state, ['array items']), | ||
...(minItems !== undefined && { minItems }), | ||
@@ -11,0 +11,0 @@ ...(maxItems !== undefined && { maxItems }), |
import { createSchemaOrRef } from '.'; | ||
export const createBrandedSchema = (zodBranded, state) => createSchemaOrRef(zodBranded._def.type, state); | ||
export const createBrandedSchema = (zodBranded, state) => createSchemaOrRef(zodBranded._def.type, state, ['brand']); | ||
//# sourceMappingURL=brand.js.map |
import { createSchemaOrRef } from '.'; | ||
export const createCatchSchema = (zodCatch, state) => createSchemaOrRef(zodCatch._def.innerType, state); | ||
export const createCatchSchema = (zodCatch, state) => createSchemaOrRef(zodCatch._def.innerType, state, ['catch']); | ||
//# sourceMappingURL=catch.js.map |
import { enhanceWithMetadata } from './metadata'; | ||
import { createSchemaOrRef } from '.'; | ||
export const createDefaultSchema = (zodDefault, state) => { | ||
const schemaOrRef = createSchemaOrRef(zodDefault._def.innerType, state); | ||
const schemaOrRef = createSchemaOrRef(zodDefault._def.innerType, state, ['default']); | ||
return enhanceWithMetadata(schemaOrRef, { | ||
@@ -6,0 +6,0 @@ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment |
@@ -5,4 +5,4 @@ import { ZodEnum, } from 'zod'; | ||
const options = zodDiscriminatedUnion.options; | ||
const schemas = options.map((option) => createSchemaOrRef(option, state)); | ||
const discriminator = mapDiscriminator(schemas, options, zodDiscriminatedUnion.discriminator); | ||
const schemas = options.map((option, index) => createSchemaOrRef(option, state, [`discriminated union option ${index}`])); | ||
const discriminator = mapDiscriminator(schemas, options, zodDiscriminatedUnion.discriminator, state); | ||
return { | ||
@@ -13,3 +13,3 @@ oneOf: schemas, | ||
}; | ||
export const mapDiscriminator = (schemas, zodObjects, discriminator) => { | ||
export const mapDiscriminator = (schemas, zodObjects, discriminator, state) => { | ||
if (typeof discriminator !== 'string') { | ||
@@ -34,3 +34,3 @@ return undefined; | ||
if (typeof literalValue !== 'string') { | ||
throw new Error(`Discriminator ${discriminator} could not be found in one of the values of a discriminated union`); | ||
throw new Error(`Discriminator ${discriminator} could not be found in on index ${index} of a discriminated union at ${state.path.join(' > ')}`); | ||
} | ||
@@ -37,0 +37,0 @@ mapping[literalValue] = componentSchemaRef; |
import { ZodArray, ZodBoolean, ZodBranded, ZodCatch, ZodDate, ZodDefault, ZodDiscriminatedUnion, ZodEffects, ZodEnum, ZodIntersection, ZodLazy, ZodLiteral, ZodNativeEnum, ZodNull, ZodNullable, ZodNumber, ZodObject, ZodOptional, ZodPipeline, ZodRecord, ZodSet, ZodString, ZodTuple, ZodUnion, ZodUnknown, } from 'zod'; | ||
import { createComponentSchemaRef, } from '../components'; | ||
import { throwTransformError } from '../errors'; | ||
import { createArraySchema } from './array'; | ||
@@ -16,3 +15,3 @@ import { createBooleanSchema } from './boolean'; | ||
import { createManualTypeSchema } from './manual'; | ||
import { createSchemaWithMetadata } from './metadata'; | ||
import { enhanceWithMetadata } from './metadata'; | ||
import { createNativeEnumSchema } from './nativeEnum'; | ||
@@ -30,9 +29,33 @@ import { createNullSchema } from './null'; | ||
import { createStringSchema } from './string'; | ||
import { createTransformSchema } from './transform'; | ||
import { createTransformSchema, throwTransformError } from './transform'; | ||
import { createTupleSchema } from './tuple'; | ||
import { createUnionSchema } from './union'; | ||
import { createUnknownSchema } from './unknown'; | ||
export const createSchema = (zodSchema, state) => { | ||
export const newSchemaState = (state) => ({ | ||
type: state.type, | ||
components: state.components, | ||
path: [...state.path], | ||
visited: new Set(state.visited), | ||
}); | ||
export const createSchema = (zodSchema, state, subpath) => { | ||
state.path.push(...subpath); | ||
if (state.visited.has(zodSchema)) { | ||
throw new Error(`The schema at ${state.path.join(' > ')} needs to be registered because it's circularly referenced`); | ||
} | ||
state.visited.add(zodSchema); | ||
const schema = createSchemaWithMetadata(zodSchema, state); | ||
return schema; | ||
}; | ||
export const createSchemaWithMetadata = (zodSchema, state) => { | ||
const { effectType, param, header, ref, refType, ...additionalMetadata } = zodSchema._def.openapi ?? {}; | ||
const schemaOrRef = createSchemaSwitch(zodSchema, state); | ||
const description = zodSchema.description; | ||
return enhanceWithMetadata(schemaOrRef, { | ||
...(description && { description }), | ||
...additionalMetadata, | ||
}); | ||
}; | ||
const createSchemaSwitch = (zodSchema, state) => { | ||
if (zodSchema._def.openapi?.type) { | ||
return createManualTypeSchema(zodSchema); | ||
return createManualTypeSchema(zodSchema, state); | ||
} | ||
@@ -126,5 +149,5 @@ if (zodSchema instanceof ZodString) { | ||
} | ||
return createManualTypeSchema(zodSchema); | ||
return createManualTypeSchema(zodSchema, state); | ||
}; | ||
export const createSchemaOrRef = (zodSchema, state) => { | ||
export const createSchemaOrRef = (zodSchema, state, subpath) => { | ||
const component = state.components.schemas.get(zodSchema); | ||
@@ -151,11 +174,7 @@ if (component && component.type === 'complete') { | ||
} | ||
const newState = { | ||
components: state.components, | ||
type: state.type, | ||
lazy: state.lazy, | ||
}; | ||
const schemaOrRef = createSchemaWithMetadata(zodSchema, newState); | ||
const newState = newSchemaState(state); | ||
const schemaOrRef = createSchema(zodSchema, newState, subpath); | ||
if (newState.effectType) { | ||
if (state.effectType && newState.effectType !== state.effectType) { | ||
throwTransformError(zodSchema); | ||
throwTransformError(zodSchema, newState); | ||
} | ||
@@ -162,0 +181,0 @@ state.effectType = newState.effectType; |
import { createSchemaOrRef } from '.'; | ||
export const createIntersectionSchema = (zodIntersection, state) => ({ | ||
allOf: [ | ||
createSchemaOrRef(zodIntersection._def.left, state), | ||
createSchemaOrRef(zodIntersection._def.right, state), | ||
createSchemaOrRef(zodIntersection._def.left, state, [ | ||
'intersection left', | ||
]), | ||
createSchemaOrRef(zodIntersection._def.right, state, [ | ||
'intersection right', | ||
]), | ||
], | ||
}); | ||
//# sourceMappingURL=intersection.js.map |
import { createSchemaOrRef } from '.'; | ||
export const createLazySchema = (zodLazy, state) => { | ||
const innerSchema = zodLazy._def.getter(); | ||
if (state.lazy?.get(zodLazy)) { | ||
throw new Error(`The ZodLazy Schema ${JSON.stringify(zodLazy._def)} or inner ZodLazy Schema ${JSON.stringify(innerSchema._def)} must be registered`); | ||
} | ||
state.lazy ??= new Map(); | ||
state.lazy.set(zodLazy, true); | ||
return createSchemaOrRef(innerSchema, state); | ||
return createSchemaOrRef(innerSchema, state, ['lazy schema']); | ||
}; | ||
//# sourceMappingURL=lazy.js.map |
import { ZodEffects } from 'zod'; | ||
export const createManualTypeSchema = (zodSchema) => { | ||
export const createManualTypeSchema = (zodSchema, state) => { | ||
if (!zodSchema._def.openapi?.type) { | ||
@@ -7,3 +7,3 @@ const zodType = zodSchema.constructor.name; | ||
const schemaName = `${zodType} - ${zodSchema._def.effect.type}`; | ||
throw new Error(`Unknown schema ${schemaName}. Please assign it a manual 'type', wrap it in a ZodPipeline or change the 'effectType'.`); | ||
throw new Error(`Unknown schema ${schemaName} at ${state.path.join(' > ')}. Please assign it a manual 'type', wrap it in a ZodPipeline or change the 'effectType'.`); | ||
} | ||
@@ -10,0 +10,0 @@ throw new Error(`Unknown schema ${zodType}. Please assign it a manual 'type'.`); |
@@ -1,11 +0,1 @@ | ||
import { createSchema } from '.'; | ||
export const createSchemaWithMetadata = (zodSchema, state) => { | ||
const { effectType, param, header, ref, refType, ...additionalMetadata } = zodSchema._def.openapi ?? {}; | ||
const schemaOrRef = createSchema(zodSchema, state); | ||
const description = zodSchema.description; | ||
return enhanceWithMetadata(schemaOrRef, { | ||
...(description && { description }), | ||
...additionalMetadata, | ||
}); | ||
}; | ||
export const enhanceWithMetadata = (schemaOrRef, metadata) => { | ||
@@ -12,0 +2,0 @@ if ('$ref' in schemaOrRef) { |
import { satisfiesVersion } from '../../openapi'; | ||
import { createSchemaOrRef } from '.'; | ||
export const createNullableSchema = (zodNullable, state) => { | ||
const schemaOrReference = createSchemaOrRef(zodNullable.unwrap(), state); | ||
const schemaOrReference = createSchemaOrRef(zodNullable.unwrap(), state, ['nullable']); | ||
if ('$ref' in schemaOrReference || schemaOrReference.allOf) { | ||
@@ -6,0 +6,0 @@ return { |
@@ -21,3 +21,3 @@ import { ZodNever, } from 'zod'; | ||
if (component || baseZodObject._def.openapi?.ref) { | ||
createSchemaOrRef(baseZodObject, state); | ||
createSchemaOrRef(baseZodObject, state, ['extended schema']); | ||
} | ||
@@ -78,3 +78,5 @@ const completeComponent = state.components.schemas.get(baseZodObject); | ||
...(!(catchAll instanceof ZodNever) && { | ||
additionalProperties: createSchemaOrRef(catchAll, state), | ||
additionalProperties: createSchemaOrRef(catchAll, state, [ | ||
'additional properties', | ||
]), | ||
}), | ||
@@ -92,5 +94,5 @@ }); | ||
export const mapProperties = (shape, state) => Object.entries(shape).reduce((acc, [key, zodSchema]) => { | ||
acc[key] = createSchemaOrRef(zodSchema, state); | ||
acc[key] = createSchemaOrRef(zodSchema, state, [`property: ${key}`]); | ||
return acc; | ||
}, {}); | ||
//# sourceMappingURL=object.js.map |
import { ZodCatch, ZodDefault, ZodDiscriminatedUnion, ZodEffects, ZodIntersection, ZodLazy, ZodNullable, ZodOptional, ZodPipeline, ZodUnion, } from 'zod'; | ||
import { createSchemaOrRef } from '.'; | ||
export const createOptionalSchema = (zodOptional, state) => | ||
// Optional doesn't change OpenAPI schema | ||
createSchemaOrRef(zodOptional.unwrap(), state); | ||
export const createOptionalSchema = (zodOptional, state) => // Optional doesn't change OpenAPI schema | ||
createSchemaOrRef(zodOptional.unwrap(), state, ['optional']); | ||
export const isOptionalSchema = (zodSchema, state) => { | ||
@@ -7,0 +6,0 @@ if (zodSchema instanceof ZodOptional || zodSchema instanceof ZodDefault) { |
@@ -1,23 +0,31 @@ | ||
import { throwTransformError } from '../errors'; | ||
import { throwTransformError } from './transform'; | ||
import { createSchemaOrRef } from '.'; | ||
export const createPipelineSchema = (zodPipeline, state) => { | ||
if (zodPipeline._def.openapi?.effectType === 'input') { | ||
return createSchemaOrRef(zodPipeline._def.in, state); | ||
return createSchemaOrRef(zodPipeline._def.in, state, [ | ||
'pipeline input', | ||
]); | ||
} | ||
if (zodPipeline._def.openapi?.effectType === 'output') { | ||
return createSchemaOrRef(zodPipeline._def.out, state); | ||
return createSchemaOrRef(zodPipeline._def.out, state, [ | ||
'pipeline output', | ||
]); | ||
} | ||
if (state.type === 'input') { | ||
if (state.effectType === 'output') { | ||
throwTransformError(zodPipeline); | ||
throwTransformError(zodPipeline, state); | ||
} | ||
state.effectType = 'input'; | ||
return createSchemaOrRef(zodPipeline._def.in, state); | ||
return createSchemaOrRef(zodPipeline._def.in, state, [ | ||
'pipeline input', | ||
]); | ||
} | ||
if (state.effectType === 'input') { | ||
throwTransformError(zodPipeline); | ||
throwTransformError(zodPipeline, state); | ||
} | ||
state.effectType = 'output'; | ||
return createSchemaOrRef(zodPipeline._def.out, state); | ||
return createSchemaOrRef(zodPipeline._def.out, state, [ | ||
'pipeline output', | ||
]); | ||
}; | ||
//# sourceMappingURL=pipeline.js.map |
import { createSchemaOrRef } from '.'; | ||
export const createPreprocessSchema = (zodPreprocess, state) => createSchemaOrRef(zodPreprocess._def.schema, state); | ||
export const createPreprocessSchema = (zodPreprocess, state) => createSchemaOrRef(zodPreprocess._def.schema, state, [ | ||
'preprocess schema', | ||
]); | ||
//# sourceMappingURL=preprocess.js.map |
import { createSchemaOrRef } from '.'; | ||
export const createRecordSchema = (zodRecord, state) => ({ | ||
type: 'object', | ||
additionalProperties: createSchemaOrRef(zodRecord.valueSchema, state), | ||
additionalProperties: createSchemaOrRef(zodRecord.valueSchema, state, ['record value']), | ||
}); | ||
//# sourceMappingURL=record.js.map |
import { createSchemaOrRef } from '.'; | ||
export const createRefineSchema = (zodRefine, state) => createSchemaOrRef(zodRefine._def.schema, state); | ||
export const createRefineSchema = (zodRefine, state) => createSchemaOrRef(zodRefine._def.schema, state, ['refine schema']); | ||
//# sourceMappingURL=refine.js.map |
@@ -8,3 +8,3 @@ import { createSchemaOrRef } from '.'; | ||
type: 'array', | ||
items: createSchemaOrRef(schema, state), | ||
items: createSchemaOrRef(schema, state, ['set items']), | ||
uniqueItems: true, | ||
@@ -11,0 +11,0 @@ ...(minItems !== undefined && { minItems }), |
@@ -1,2 +0,1 @@ | ||
import { throwTransformError } from '../errors'; | ||
import { createManualTypeSchema } from './manual'; | ||
@@ -6,16 +5,23 @@ import { createSchemaOrRef } from '.'; | ||
if (zodTransform._def.openapi?.effectType === 'output') { | ||
return createManualTypeSchema(zodTransform); | ||
return createManualTypeSchema(zodTransform, state); | ||
} | ||
if (zodTransform._def.openapi?.effectType === 'input') { | ||
return createSchemaOrRef(zodTransform._def.schema, state); | ||
return createSchemaOrRef(zodTransform._def.schema, state, [ | ||
'transform input', | ||
]); | ||
} | ||
if (state.type === 'output') { | ||
return createManualTypeSchema(zodTransform); | ||
return createManualTypeSchema(zodTransform, state); | ||
} | ||
if (state.effectType === 'output') { | ||
throwTransformError(zodTransform); | ||
throwTransformError(zodTransform, state); | ||
} | ||
state.effectType = 'input'; | ||
return createSchemaOrRef(zodTransform._def.schema, state); | ||
return createSchemaOrRef(zodTransform._def.schema, state, [ | ||
'transform input', | ||
]); | ||
}; | ||
export const throwTransformError = (zodType, state) => { | ||
throw new Error(`${JSON.stringify(zodType)} at ${state.path.join(' > ')} contains a transform but is used in both an input and an output. This is likely a mistake. Set an \`effectType\` to resolve`); | ||
}; | ||
//# sourceMappingURL=transform.js.map |
@@ -13,3 +13,3 @@ import { satisfiesVersion } from '../../openapi'; | ||
if (items.length) { | ||
return items.map((item) => createSchemaOrRef(item, state)); | ||
return items.map((item, index) => createSchemaOrRef(item, state, [`tuple item ${index}`])); | ||
} | ||
@@ -29,3 +29,3 @@ return undefined; | ||
return { | ||
items: createSchemaOrRef(rest, state), | ||
items: createSchemaOrRef(rest, state, ['tuple items']), | ||
...(prefixItems && { prefixItems }), | ||
@@ -44,3 +44,6 @@ }; | ||
items: { | ||
oneOf: [...prefixItems, createSchemaOrRef(rest, state)], | ||
oneOf: [ | ||
...prefixItems, | ||
createSchemaOrRef(rest, state, ['tuple items']), | ||
], | ||
}, | ||
@@ -47,0 +50,0 @@ }), |
import { createSchemaOrRef } from '.'; | ||
export const createUnionSchema = (zodUnion, state) => { | ||
const options = zodUnion.options; | ||
const schemas = options.map((option) => createSchemaOrRef(option, state)); | ||
const schemas = options.map((option, index) => createSchemaOrRef(option, state, [`union option ${index}`])); | ||
return { | ||
@@ -6,0 +6,0 @@ anyOf: schemas, |
export function extendZodWithOpenApi(zod) { | ||
if (typeof zod.ZodSchema.prototype.openapi !== 'undefined') { | ||
if (typeof zod.ZodType.prototype.openapi !== 'undefined') { | ||
return; | ||
} | ||
zod.ZodSchema.prototype.openapi = function (openapi) { | ||
zod.ZodType.prototype.openapi = function (openapi) { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment | ||
@@ -7,0 +7,0 @@ const result = new this.constructor({ |
import type { oas31 } from '../openapi3-ts/dist'; | ||
import type { ComponentsObject, CreationType } from './components'; | ||
import type { ZodOpenApiContentObject } from './document'; | ||
export declare const createContent: (contentObject: ZodOpenApiContentObject, components: ComponentsObject, type: CreationType) => oas31.ContentObject; | ||
export declare const createContent: (contentObject: ZodOpenApiContentObject, components: ComponentsObject, type: CreationType, subpath: string[]) => oas31.ContentObject; |
@@ -6,5 +6,5 @@ import { ZodType } from 'zod'; | ||
export declare const createComponentParamRef: (ref: string) => string; | ||
export declare const createBaseParameter: (schema: ZodType, components: ComponentsObject) => oas31.BaseParameterObject; | ||
export declare const createParamOrRef: (zodSchema: ZodType, components: ComponentsObject, type?: keyof ZodOpenApiParameters, name?: string) => oas31.ParameterObject | oas31.ReferenceObject; | ||
export declare const createManualParameters: (parameters: (oas31.ParameterObject | oas31.ReferenceObject | oas30.ParameterObject | oas30.ReferenceObject | ZodType)[] | undefined, components: ComponentsObject) => (oas31.ParameterObject | oas31.ReferenceObject)[]; | ||
export declare const createParametersObject: (parameters: (oas31.ParameterObject | oas31.ReferenceObject | oas30.ParameterObject | oas30.ReferenceObject | ZodType)[] | undefined, requestParams: ZodOpenApiParameters | undefined, components: ComponentsObject) => (oas31.ParameterObject | oas31.ReferenceObject)[] | undefined; | ||
export declare const createBaseParameter: (schema: ZodType, components: ComponentsObject, subpath: string[]) => oas31.BaseParameterObject; | ||
export declare const createParamOrRef: (zodSchema: ZodType, components: ComponentsObject, subpath: string[], type?: keyof ZodOpenApiParameters, name?: string) => oas31.ParameterObject | oas31.ReferenceObject; | ||
export declare const createManualParameters: (parameters: (oas31.ParameterObject | oas31.ReferenceObject | oas30.ParameterObject | oas30.ReferenceObject | ZodType)[] | undefined, components: ComponentsObject, subpath: string[]) => (oas31.ParameterObject | oas31.ReferenceObject)[]; | ||
export declare const createParametersObject: (parameters: (oas31.ParameterObject | oas31.ReferenceObject | oas30.ParameterObject | oas30.ReferenceObject | ZodType)[] | undefined, requestParams: ZodOpenApiParameters | undefined, components: ComponentsObject, subpath: string[]) => (oas31.ParameterObject | oas31.ReferenceObject)[] | undefined; |
import type { oas31 } from '../openapi3-ts/dist'; | ||
import { type ComponentsObject } from './components'; | ||
import type { ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject } from './document'; | ||
export declare const createRequestBody: (requestBodyObject: ZodOpenApiRequestBodyObject | undefined, components: ComponentsObject) => oas31.ReferenceObject | oas31.RequestBodyObject | undefined; | ||
export declare const createRequestBody: (requestBodyObject: ZodOpenApiRequestBodyObject | undefined, components: ComponentsObject, subpath: string[]) => oas31.ReferenceObject | oas31.RequestBodyObject | undefined; | ||
export declare const createPaths: (pathsObject: ZodOpenApiPathsObject | undefined, components: ComponentsObject) => oas31.PathsObject | undefined; |
@@ -9,3 +9,3 @@ import { type AnyZodObject, ZodType } from 'zod'; | ||
export declare const createComponentHeaderRef: (ref: string) => string; | ||
export declare const createResponse: (responseObject: ZodOpenApiResponseObject | oas31.ReferenceObject, components: ComponentsObject) => oas31.ResponseObject | oas31.ReferenceObject; | ||
export declare const createResponses: (responsesObject: ZodOpenApiResponsesObject, components: ComponentsObject) => oas31.ResponsesObject; | ||
export declare const createResponse: (responseObject: ZodOpenApiResponseObject | oas31.ReferenceObject, components: ComponentsObject, subpath: string[]) => oas31.ResponseObject | oas31.ReferenceObject; | ||
export declare const createResponses: (responsesObject: ZodOpenApiResponsesObject, components: ComponentsObject, subpath: string[]) => oas31.ResponsesObject; |
@@ -5,2 +5,2 @@ import { type AnyZodObject, type ZodDiscriminatedUnion } from 'zod'; | ||
export declare const createDiscriminatedUnionSchema: (zodDiscriminatedUnion: ZodDiscriminatedUnion<any, any>, state: SchemaState) => oas31.SchemaObject; | ||
export declare const mapDiscriminator: (schemas: (oas31.SchemaObject | oas31.ReferenceObject)[], zodObjects: AnyZodObject[], discriminator: unknown) => oas31.SchemaObject['discriminator']; | ||
export declare const mapDiscriminator: (schemas: (oas31.SchemaObject | oas31.ReferenceObject)[], zodObjects: AnyZodObject[], discriminator: unknown, state: SchemaState) => oas31.SchemaObject['discriminator']; |
@@ -9,5 +9,8 @@ import { type ZodType, type ZodTypeDef } from 'zod'; | ||
effectType?: CreationType; | ||
lazy?: LazyMap; | ||
path: string[]; | ||
visited: Set<ZodType>; | ||
} | ||
export declare const createSchema: <Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, state: SchemaState) => oas31.SchemaObject | oas31.ReferenceObject; | ||
export declare const createSchemaOrRef: <Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, state: SchemaState) => oas31.ReferenceObject | oas31.SchemaObject; | ||
export declare const newSchemaState: (state: SchemaState) => SchemaState; | ||
export declare const createSchema: <Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, state: SchemaState, subpath: string[]) => oas31.SchemaObject | oas31.ReferenceObject; | ||
export declare const createSchemaWithMetadata: <Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, state: SchemaState) => oas31.SchemaObject | oas31.ReferenceObject; | ||
export declare const createSchemaOrRef: <Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, state: SchemaState, subpath: string[]) => oas31.ReferenceObject | oas31.SchemaObject; |
import { type ZodType, type ZodTypeDef } from 'zod'; | ||
import type { oas31 } from '../../openapi3-ts/dist'; | ||
export declare const createManualTypeSchema: <Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>) => oas31.SchemaObject; | ||
import type { SchemaState } from '.'; | ||
export declare const createManualTypeSchema: <Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, state: SchemaState) => oas31.SchemaObject; |
@@ -1,5 +0,2 @@ | ||
import type { ZodType, ZodTypeDef } from 'zod'; | ||
import type { oas31 } from '../../openapi3-ts/dist'; | ||
import { type SchemaState } from '.'; | ||
export declare const createSchemaWithMetadata: <Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, state: SchemaState) => oas31.SchemaObject | oas31.ReferenceObject; | ||
export declare const enhanceWithMetadata: (schemaOrRef: oas31.SchemaObject | oas31.ReferenceObject, metadata: oas31.SchemaObject | oas31.ReferenceObject) => oas31.SchemaObject | oas31.ReferenceObject; |
@@ -1,4 +0,5 @@ | ||
import type { ZodEffects } from 'zod'; | ||
import type { ZodEffects, ZodType } from 'zod'; | ||
import type { oas31 } from '../../openapi3-ts/dist'; | ||
import { type SchemaState } from '.'; | ||
export declare const createTransformSchema: (zodTransform: ZodEffects<any, any, any>, state: SchemaState) => oas31.SchemaObject | oas31.ReferenceObject; | ||
export declare const throwTransformError: (zodType: ZodType, state: SchemaState) => never; |
@@ -44,3 +44,3 @@ import type { UnknownKeysParam, ZodDate, ZodObject, ZodRawShape, ZodTypeAny, z } from 'zod'; | ||
declare module 'zod' { | ||
interface ZodSchema<Output, Def extends ZodTypeDef, Input = Output> { | ||
interface ZodType<Output, Def extends ZodTypeDef, Input = Output> { | ||
openapi<T extends ZodTypeAny>(this: T, metadata: ZodOpenApiMetadata<T>): T; | ||
@@ -47,0 +47,0 @@ } |
{ | ||
"name": "zod-openapi", | ||
"version": "2.4.0", | ||
"version": "2.5.0", | ||
"description": "A library to create full OpenAPI documents from your Zod types", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/samchungy/zod-openapi#readme", |
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
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
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
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
318650
4279
263