@asteasolutions/zod-to-openapi
Advanced tools
Comparing version 5.1.0 to 5.2.0
@@ -82,2 +82,3 @@ import type { PathItemObject as PathItemObject30, OpenAPIObject as OpenAPIObject30, ComponentsObject as ComponentsObject30, SchemaObject as SchemaObject30 } from 'openapi3-ts/oas30'; | ||
private flattenIntersectionTypes; | ||
private unwrapNullable; | ||
private unwrapChained; | ||
@@ -84,0 +85,0 @@ /** |
@@ -511,4 +511,12 @@ "use strict"; | ||
const options = this.flattenUnionTypes(zodSchema); | ||
const schemas = options.map(schema => { | ||
// If any of the underlying schemas of a union is .nullable then the whole union | ||
// would be nullable. `mapNullableOfArray` would place it where it belongs. | ||
// Therefor we are stripping the additional nullables from the inner schemas | ||
// See https://github.com/asteasolutions/zod-to-openapi/issues/149 | ||
const optionToGenerate = this.unwrapNullable(schema); | ||
return this.generateSchemaWithRef(optionToGenerate); | ||
}); | ||
return { | ||
anyOf: this.mapNullableOfArray(options.map(schema => this.generateSchemaWithRef(schema)), isNullable), | ||
anyOf: this.mapNullableOfArray(schemas, isNullable), | ||
default: defaultValue, | ||
@@ -638,2 +646,8 @@ }; | ||
} | ||
unwrapNullable(schema) { | ||
if ((0, zod_is_type_1.isZodType)(schema, 'ZodNullable')) { | ||
return this.unwrapNullable(schema.unwrap()); | ||
} | ||
return schema; | ||
} | ||
unwrapChained(schema) { | ||
@@ -640,0 +654,0 @@ if ((0, zod_is_type_1.isZodType)(schema, 'ZodOptional') || |
{ | ||
"name": "@asteasolutions/zod-to-openapi", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "Builds OpenAPI schemas from Zod schemas", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -140,3 +140,3 @@ # Zod to OpenAPI | ||
The `OpenAPIRegistry` is a utility that can be used to collect definitions which would later be passed to a `OpenAPIGeneratorV3` or `OpenAPIGeneratorV31` instance. | ||
The `OpenAPIRegistry` is a utility that can be used to collect definitions which would later be passed to a `OpenApiGeneratorV3` or `OpenApiGeneratorV31` instance. | ||
@@ -146,3 +146,3 @@ ```ts | ||
OpenAPIRegistry, | ||
OpenAPIGeneratorV3, | ||
OpenApiGeneratorV3, | ||
} from '@asteasolutions/zod-to-openapi'; | ||
@@ -154,3 +154,3 @@ | ||
const generator = new OpenAPIGeneratorV3(registry.definitions); | ||
const generator = new OpenApiGeneratorV3(registry.definitions); | ||
@@ -205,3 +205,3 @@ return generator.generateComponents(); | ||
const generator = new OpenAPIGeneratorV3([UserSchema]); | ||
const generator = new OpenApiGeneratorV3([UserSchema]); | ||
``` | ||
@@ -221,3 +221,3 @@ | ||
const generator = new OpenAPIGeneratorV3(registry.definitions); | ||
const generator = new OpenApiGeneratorV3(registry.definitions); | ||
``` | ||
@@ -378,3 +378,3 @@ | ||
A full OpenAPI document can be generated using the `generateDocument` method of an `OpenAPIGeneratorV3` or `OpenAPIGeneratorV31` instance. It takes one argument - the document config. It may look something like this: | ||
A full OpenAPI document can be generated using the `generateDocument` method of an `OpenApiGeneratorV3` or `OpenApiGeneratorV31` instance. It takes one argument - the document config. It may look something like this: | ||
@@ -447,3 +447,3 @@ ```ts | ||
new OpenAPIGeneratorV3([Schema1, Schema2]) | ||
new OpenApiGeneratorV3([Schema1, Schema2]) | ||
``` | ||
@@ -466,3 +466,3 @@ | ||
new OpenAPIGeneratorV3(registry.definitions) | ||
new OpenApiGeneratorV3(registry.definitions) | ||
``` | ||
@@ -487,3 +487,3 @@ | ||
return new OpenAPIGeneratorV3(schemas.definitions).generateDocument(config); | ||
return new OpenApiGeneratorV3(schemas.definitions).generateDocument(config); | ||
} | ||
@@ -490,0 +490,0 @@ ``` |
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
95622
1694