zod-openapi
Advanced tools
Comparing version 2.5.1 to 2.6.0
@@ -141,3 +141,3 @@ "use strict"; | ||
} | ||
if (zodSchema instanceof zod_1.ZodUnknown) { | ||
if (zodSchema instanceof zod_1.ZodUnknown || zodSchema instanceof zod_1.ZodAny) { | ||
return (0, unknown_1.createUnknownSchema)(zodSchema); | ||
@@ -144,0 +144,0 @@ } |
@@ -1,2 +0,2 @@ | ||
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 { ZodAny, 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'; | ||
@@ -135,3 +135,3 @@ import { createArraySchema } from './array'; | ||
} | ||
if (zodSchema instanceof ZodUnknown) { | ||
if (zodSchema instanceof ZodUnknown || zodSchema instanceof ZodAny) { | ||
return createUnknownSchema(zodSchema); | ||
@@ -138,0 +138,0 @@ } |
@@ -1,3 +0,3 @@ | ||
import type { ZodUnknown } from 'zod'; | ||
import type { ZodAny, ZodUnknown } from 'zod'; | ||
import type { oas31 } from '../../openapi3-ts/dist'; | ||
export declare const createUnknownSchema: (_zodUnknown: ZodUnknown) => oas31.SchemaObject; | ||
export declare const createUnknownSchema: (_zodUnknown: ZodUnknown | ZodAny) => oas31.SchemaObject; |
{ | ||
"name": "zod-openapi", | ||
"version": "2.5.1", | ||
"description": "A library to create full OpenAPI documents from your Zod types", | ||
"version": "2.6.0", | ||
"description": "Convert Zod Schemas to OpenAPI v3.x documentation", | ||
"keywords": [ | ||
"typescript", | ||
"json-schema", | ||
"swagger", | ||
"openapi", | ||
"openapi3", | ||
"zod", | ||
"zod-openapi" | ||
], | ||
"homepage": "https://github.com/samchungy/zod-openapi#readme", | ||
@@ -31,3 +40,3 @@ "bugs": { | ||
"prepare": "yarn build", | ||
"release": "yarn build && npm publish", | ||
"release": "yarn build && npm publish --provenance", | ||
"test": "skuba test", | ||
@@ -39,8 +48,8 @@ "test:ci": "skuba test --coverage", | ||
"devDependencies": { | ||
"@redocly/cli": "1.0.0-beta.126", | ||
"@types/node": "^20.1.0", | ||
"@redocly/cli": "1.0.0-beta.128", | ||
"@types/node": "^20.3.0", | ||
"eslint-plugin-zod-openapi": "^0.1.0", | ||
"openapi3-ts": "4.1.2", | ||
"skuba": "6.2.0", | ||
"yaml": "2.2.2", | ||
"yaml": "2.3.1", | ||
"zod": "3.21.4" | ||
@@ -47,0 +56,0 @@ }, |
@@ -6,3 +6,3 @@ <p align="center"> | ||
<p align="center"> | ||
A Typescript library to create full OpenAPI 3.x documentation from <a href="https://github.com/colinhacks/zod">Zod</a> Schemas | ||
A Typescript library to use <a href="https://github.com/colinhacks/zod">Zod</a> Schemas to create OpenAPI v3.x documentation | ||
</p> | ||
@@ -210,3 +210,3 @@ <div align="center"> | ||
Where you would normally declare the [media type](https://swagger.io/docs/specification/media-types/), instead declare the `content` as `application/json` and set the `schema` as your Zod Schema as follows. | ||
Where you would normally declare the [media type](https://swagger.io/docs/specification/media-types/), set the `schema` as your Zod Schema as follows. | ||
@@ -320,9 +320,13 @@ ```typescript | ||
`.transform()` is complicated because it technically comprises of two types (input & output). This means that we need to understand which type you are creating. | ||
`.transform()` and `.pipe()` are complicated because they technically comprise of two types (input & output). This means that we need to understand which type you are creating. This library will automatically select which _type_ to use by checking how the schema is used based on the following rules: | ||
If a registered schema with a transform or pipeline is used in both a request and response schema you will receive an error because the created schema for each will be different. To override the creation type for a specific ZodEffect, add an `.openapi()` field and set the `effectType` field to `input` or `output`. This will force this library to always generate the input/output type even if we are creating a response (output) or request (input) type. You typically want to use this when your know your transform has not changed the type. | ||
_Input_: Request Bodies, Request Parameters, Headers | ||
_Output_: Responses, Response Headers | ||
If a registered schema with a transform or pipeline is used in both a request and response schema you will receive an error because the created schema for each will be different. To override the creation type for a specific ZodEffect, add an `.openapi()` field on it and set the `effectType` field to `input` or `output`. This will force this library to always generate the input/output type even if we are creating a response (output) or request (input) type. You typically want to use this when you know your transform has not changed the type. | ||
`.preprocess()` will always return the `output` type even if we are creating an input schema. If a different input type is required you can achieve this with a `.transform()` combined with a `.pipe()` or simply declare a manual `type` in `.openapi()`. | ||
If you are adding a ZodSchema directly to the `components` section which is not referenced anywhere in the document, additional context may be required to create either an input schema or an output schema. You can do this by setting the `refType` field to `input` or `output` in `.openapi()`. This defaults to `output` by default. | ||
If you are adding a ZodSchema directly to the `components` section which is not referenced anywhere in the document, additional context may be required to create either an input or output schema. You can do this by setting the `refType` field to `input` or `output` in `.openapi()`. This defaults to `output` by default. | ||
@@ -489,2 +493,3 @@ #### Parameters | ||
- ZodAny | ||
- ZodArray | ||
@@ -520,2 +525,3 @@ - `minItems`/`maxItems` mapping for `.length()`, `.min()`, `.max()` | ||
- ZodPipeline | ||
- See [Zod Effects](#zod-effects) for more information. | ||
- ZodRecord | ||
@@ -673,3 +679,4 @@ - ZodSet | ||
```shell | ||
yarn install | ||
yarn | ||
yarn build | ||
``` | ||
@@ -676,0 +683,0 @@ |
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
320203
711