@anatine/zod-openapi
Advanced tools
Comparing version 1.13.0 to 1.14.0
@@ -5,2 +5,10 @@ # Changelog | ||
## [1.14.0](https://github.com/anatine/zod-plugins/compare/zod-openapi-1.13.0...zod-openapi-1.14.0) (2023-05-23) | ||
### Features | ||
* Dep updates ([156b026](https://github.com/anatine/zod-plugins/commit/156b026391eba70c00df8b0f96ec402db1ceed4c)) | ||
* **zod-openapi:** add option to use extension-method on zod ([fe26a3e](https://github.com/anatine/zod-plugins/commit/fe26a3ed3a0f9a8d62d65ad43b34a7091268aec7)) | ||
## [1.13.0](https://github.com/anatine/zod-plugins/compare/zod-openapi-1.12.0...zod-openapi-1.13.0) (2023-05-13) | ||
@@ -7,0 +15,0 @@ |
{ | ||
"name": "@anatine/zod-openapi", | ||
"version": "1.13.0", | ||
"version": "1.14.0", | ||
"description": "Zod to OpenAPI converter", | ||
@@ -24,3 +24,3 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"ts-deepmerge": "4.0.0" | ||
"ts-deepmerge": "^6.0.3" | ||
}, | ||
@@ -27,0 +27,0 @@ "peerDependencies": { |
@@ -96,4 +96,35 @@ # @anatine/zod-openapi | ||
This will generated an extended schema: | ||
... or via extension of the Zod schema: | ||
```typescript | ||
import { extendApi, generateSchema, extendZodWithOpenApi } from '@anatine/zod-openapi'; | ||
import {z} from 'zod'; | ||
extendZodWithOpenApi(z); | ||
const aZodExtendedSchema = | ||
z.object({ | ||
uid: z.string().nonempty().openapi({ | ||
title: 'Unique ID', | ||
description: 'A UUID generated by the server', | ||
}), | ||
firstName: z.string().min(2), | ||
lastName: z.string().optional(), | ||
email: z.string().email(), | ||
phoneNumber: z.string().min(10).openapi({ | ||
description: 'US Phone numbers only', | ||
example: '555-555-5555', | ||
}), | ||
}).openapi( | ||
{ | ||
title: 'User', | ||
description: 'A user schema', | ||
} | ||
); | ||
const myOpenApiSchema = generateSchema(aZodExtendedSchema); | ||
// ... | ||
``` | ||
This will generate an extended schema: | ||
```json | ||
@@ -100,0 +131,0 @@ { |
export * from './lib/zod-openapi'; | ||
export * from './lib/zod-extensions'; |
@@ -18,2 +18,3 @@ "use strict"; | ||
__exportStar(require("./lib/zod-openapi"), exports); | ||
__exportStar(require("./lib/zod-extensions"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -16,3 +16,2 @@ "use strict"; | ||
const input = generateSchema(zodRef._def.schema, useOutput); | ||
zodRef._def; | ||
let output = 'undefined'; | ||
@@ -55,3 +54,2 @@ if (useOutput && zodRef._def.effect) { | ||
checks.forEach((item) => { | ||
item; //? | ||
switch (item.kind) { | ||
@@ -129,3 +127,4 @@ case 'email': | ||
// So that `undefined` values don't end up in the schema and be weird | ||
additionalProperties = additionalProperties != null ? { additionalProperties } : {}; | ||
additionalProperties = | ||
additionalProperties != null ? { additionalProperties } : {}; | ||
const requiredProperties = Object.keys(zodRef.shape).filter((key) => { | ||
@@ -135,7 +134,6 @@ const item = zodRef.shape[key]; | ||
item instanceof zod_1.z.ZodDefault || | ||
item._def.typeName === 'ZodDefault') && | ||
!(item instanceof zod_1.z.ZodNever || item._def.typeName === 'ZodDefault')); | ||
item._def.typeName === 'ZodDefault') && !(item instanceof zod_1.z.ZodNever || item._def.typeName === 'ZodDefault')); | ||
}); | ||
const required = requiredProperties.length > 0 ? { required: requiredProperties } : {}; | ||
return (0, ts_deepmerge_1.default)(Object.assign(Object.assign({ type: 'object', properties: iterateZodObject({ | ||
const result = (0, ts_deepmerge_1.default)(Object.assign(Object.assign({ type: 'object', properties: iterateZodObject({ | ||
zodRef: zodRef, | ||
@@ -145,2 +143,3 @@ schemas, | ||
}) }, required), additionalProperties), zodRef.description ? { description: zodRef.description } : {}, ...schemas); | ||
return result; | ||
} | ||
@@ -147,0 +146,0 @@ function parseRecord({ zodRef, schemas, useOutput, }) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
38920
13
337
183
+ Addedts-deepmerge@6.2.1(transitive)
- Removedts-deepmerge@4.0.0(transitive)
Updatedts-deepmerge@^6.0.3