@anatine/zod-openapi
Advanced tools
Comparing version 1.14.1 to 1.14.2
@@ -5,2 +5,4 @@ # Changelog | ||
### [1.14.2](https://github.com/anatine/zod-plugins/compare/zod-openapi-1.14.1...zod-openapi-1.14.2) (2023-06-16) | ||
### [1.14.1](https://github.com/anatine/zod-plugins/compare/zod-openapi-1.14.0...zod-openapi-1.14.1) (2023-06-16) | ||
@@ -7,0 +9,0 @@ |
{ | ||
"name": "@anatine/zod-openapi", | ||
"version": "1.14.1", | ||
"version": "1.14.2", | ||
"description": "Zod to OpenAPI converter", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -203,4 +203,19 @@ "use strict"; | ||
function parseUnion({ schemas, zodRef, useOutput, }) { | ||
const contents = zodRef._def.options; | ||
if (contents.reduce((prev, content) => prev && content._def.typeName === 'ZodLiteral', true)) { | ||
// special case to transform unions of literals into enums | ||
const literals = contents; | ||
const type = literals | ||
.reduce((prev, content) => !prev || prev === typeof content._def.value ? | ||
typeof content._def.value : | ||
null, null); | ||
if (type) { | ||
return (0, ts_deepmerge_1.default)({ | ||
type: type, | ||
enum: literals.map((literal) => literal._def.value) | ||
}, zodRef.description ? { description: zodRef.description } : {}, ...schemas); | ||
} | ||
} | ||
return (0, ts_deepmerge_1.default)({ | ||
oneOf: zodRef._def.options.map((schema) => generateSchema(schema, useOutput)), | ||
oneOf: contents.map((schema) => generateSchema(schema, useOutput)), | ||
}, zodRef.description ? { description: zodRef.description } : {}, ...schemas); | ||
@@ -207,0 +222,0 @@ } |
Sorry, the diff of this file is not supported yet
40540
351