@asteasolutions/zod-to-openapi
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -15,6 +15,5 @@ "use strict"; | ||
exports.OpenAPIGenerator = void 0; | ||
const zod_1 = require("zod"); | ||
const lodash_1 = require("./lib/lodash"); | ||
const zod_2 = require("zod"); | ||
const errors_1 = require("./errors"); | ||
const zod_is_type_1 = require("./lib/zod-is-type"); | ||
class OpenAPIGenerator { | ||
@@ -117,3 +116,3 @@ constructor(definitions) { | ||
} | ||
if (zodSchema instanceof zod_1.ZodObject) { | ||
if ((0, zod_is_type_1.isZodType)(zodSchema, 'ZodObject')) { | ||
const propTypes = zodSchema._def.shape(); | ||
@@ -267,3 +266,3 @@ const parameters = Object.entries(propTypes).map(([key, schema]) => { | ||
getResponse(response) { | ||
if (response instanceof zod_2.ZodVoid) { | ||
if ((0, zod_is_type_1.isZodType)(response, 'ZodVoid')) { | ||
const metadata = this.getMetadata(response); | ||
@@ -293,6 +292,6 @@ if (!(metadata === null || metadata === void 0 ? void 0 : metadata.description)) { | ||
var _a, _b, _c, _d, _e; | ||
if (zodSchema instanceof zod_1.ZodNull) { | ||
if ((0, zod_is_type_1.isZodType)(zodSchema, 'ZodNull')) { | ||
return { type: 'null' }; | ||
} | ||
if (zodSchema instanceof zod_1.ZodString) { | ||
if ((0, zod_is_type_1.isZodType)(zodSchema, 'ZodString')) { | ||
return { | ||
@@ -303,3 +302,3 @@ type: 'string', | ||
} | ||
if (zodSchema instanceof zod_1.ZodNumber) { | ||
if ((0, zod_is_type_1.isZodType)(zodSchema, 'ZodNumber')) { | ||
return { | ||
@@ -312,3 +311,3 @@ type: 'number', | ||
} | ||
if (zodSchema instanceof zod_1.ZodBoolean) { | ||
if ((0, zod_is_type_1.isZodType)(zodSchema, 'ZodBoolean')) { | ||
return { | ||
@@ -319,7 +318,7 @@ type: 'boolean', | ||
} | ||
if (zodSchema instanceof zod_1.ZodDefault) { | ||
if ((0, zod_is_type_1.isZodType)(zodSchema, 'ZodDefault')) { | ||
const innerSchema = zodSchema._def.innerType; | ||
return this.generateInnerSchema(innerSchema); | ||
} | ||
if (zodSchema instanceof zod_1.ZodEffects && | ||
if ((0, zod_is_type_1.isZodType)(zodSchema, 'ZodEffects') && | ||
zodSchema._def.effect.type === 'refinement') { | ||
@@ -329,3 +328,3 @@ const innerSchema = zodSchema._def.schema; | ||
} | ||
if (zodSchema instanceof zod_1.ZodLiteral) { | ||
if ((0, zod_is_type_1.isZodType)(zodSchema, 'ZodLiteral')) { | ||
return { | ||
@@ -337,3 +336,3 @@ type: typeof zodSchema._def.value, | ||
} | ||
if (zodSchema instanceof zod_1.ZodEnum) { | ||
if ((0, zod_is_type_1.isZodType)(zodSchema, 'ZodEnum')) { | ||
// ZodEnum only accepts strings | ||
@@ -346,3 +345,3 @@ return { | ||
} | ||
if (zodSchema instanceof zod_1.ZodNativeEnum) { | ||
if ((0, zod_is_type_1.isZodType)(zodSchema, 'ZodNativeEnum')) { | ||
const enumValues = Object.values(zodSchema._def.values); | ||
@@ -357,6 +356,6 @@ // ZodNativeEnum can accepts number values for enum but in odd format | ||
} | ||
if (zodSchema instanceof zod_1.ZodObject) { | ||
if ((0, zod_is_type_1.isZodType)(zodSchema, 'ZodObject')) { | ||
return this.toOpenAPIObjectSchema(zodSchema, isNullable); | ||
} | ||
if (zodSchema instanceof zod_1.ZodArray) { | ||
if ((0, zod_is_type_1.isZodType)(zodSchema, 'ZodArray')) { | ||
const itemType = zodSchema._def.type; | ||
@@ -370,3 +369,3 @@ return { | ||
} | ||
if (zodSchema instanceof zod_1.ZodUnion) { | ||
if ((0, zod_is_type_1.isZodType)(zodSchema, 'ZodUnion')) { | ||
const options = this.flattenUnionTypes(zodSchema); | ||
@@ -377,3 +376,3 @@ return { | ||
} | ||
if (zodSchema instanceof zod_1.ZodIntersection) { | ||
if ((0, zod_is_type_1.isZodType)(zodSchema, 'ZodIntersection')) { | ||
const subtypes = this.flattenIntersectionTypes(zodSchema); | ||
@@ -384,3 +383,3 @@ return { | ||
} | ||
if (zodSchema instanceof zod_1.ZodRecord) { | ||
if ((0, zod_is_type_1.isZodType)(zodSchema, 'ZodRecord')) { | ||
const propertiesType = zodSchema._def.valueType; | ||
@@ -392,3 +391,3 @@ return { | ||
} | ||
if (zodSchema instanceof zod_1.ZodUnknown) { | ||
if ((0, zod_is_type_1.isZodType)(zodSchema, 'ZodUnknown')) { | ||
return {}; | ||
@@ -403,6 +402,6 @@ } | ||
isOptionalSchema(zodSchema) { | ||
if (zodSchema instanceof zod_1.ZodEffects) { | ||
if ((0, zod_is_type_1.isZodType)(zodSchema, 'ZodEffects')) { | ||
return this.isOptionalSchema(zodSchema._def.schema); | ||
} | ||
if (zodSchema instanceof zod_1.ZodDefault) { | ||
if ((0, zod_is_type_1.isZodType)(zodSchema, 'ZodDefault')) { | ||
return this.isOptionalSchema(zodSchema._def.innerType); | ||
@@ -427,3 +426,3 @@ } | ||
flattenUnionTypes(schema) { | ||
if (!(schema instanceof zod_1.ZodUnion)) { | ||
if (!(0, zod_is_type_1.isZodType)(schema, 'ZodUnion')) { | ||
return [schema]; | ||
@@ -435,3 +434,3 @@ } | ||
flattenIntersectionTypes(schema) { | ||
if (!(schema instanceof zod_1.ZodIntersection)) { | ||
if (!(0, zod_is_type_1.isZodType)(schema, 'ZodIntersection')) { | ||
return [schema]; | ||
@@ -444,9 +443,9 @@ } | ||
unwrapChained(schema) { | ||
if (schema instanceof zod_1.ZodOptional || schema instanceof zod_1.ZodNullable) { | ||
if ((0, zod_is_type_1.isZodType)(schema, 'ZodOptional') || (0, zod_is_type_1.isZodType)(schema, 'ZodNullable')) { | ||
return this.unwrapChained(schema.unwrap()); | ||
} | ||
if (schema instanceof zod_1.ZodDefault) { | ||
if ((0, zod_is_type_1.isZodType)(schema, 'ZodDefault')) { | ||
return this.unwrapChained(schema._def.innerType); | ||
} | ||
if (schema instanceof zod_1.ZodEffects && | ||
if ((0, zod_is_type_1.isZodType)(schema, 'ZodEffects') && | ||
schema._def.effect.type === 'refinement') { | ||
@@ -453,0 +452,0 @@ return this.unwrapChained(schema._def.schema); |
import { OperationObject } from 'openapi3-ts'; | ||
import { ZodVoid } from 'zod'; | ||
import { ZodObject } from 'zod'; | ||
import { ZodSchema, ZodType } from 'zod'; | ||
import type { ZodVoid, ZodObject, ZodSchema, ZodType } from 'zod'; | ||
declare type Method = 'get' | 'post' | 'put' | 'delete' | 'patch'; | ||
@@ -6,0 +4,0 @@ export declare type ResponseConfig = { |
import { ParameterObject, SchemaObject } from 'openapi3-ts'; | ||
import { z } from 'zod'; | ||
import type { z } from 'zod'; | ||
export interface ZodOpenAPIMetadata<T = any> extends SchemaObject { | ||
@@ -4,0 +4,0 @@ refId?: string; |
{ | ||
"name": "@asteasolutions/zod-to-openapi", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Builds OpenAPI schemas from Zod schemas", | ||
@@ -36,4 +36,2 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"lodash": "^4.17.21", | ||
"@types/lodash": "^4.14.181", | ||
"@types/jest": "^27.4.1", | ||
@@ -40,0 +38,0 @@ "jest": "^27.5.1", |
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
47240
6
17
829