zod-openapi 2.2.1 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/lib-commonjs/create/schema/pipeline.js +15 -0
- package/lib-commonjs/create/schema/pipeline.js.map +1 -1
- package/lib-commonjs/create/schema/transform.js +10 -7
- package/lib-commonjs/create/schema/transform.js.map +1 -1
- package/lib-es2015/create/schema/pipeline.js +15 -0
- package/lib-es2015/create/schema/pipeline.js.map +1 -1
- package/lib-es2015/create/schema/transform.js +10 -7
- package/lib-es2015/create/schema/transform.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -317,7 +317,7 @@ createDocument({
|
|
|
317
317
|
|
|
318
318
|
`.transform()` is complicated because it technically comprises of two types (input & output). This means that we need to understand which type you are creating.
|
|
319
319
|
|
|
320
|
-
If a registered schema with a transform 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`. This will force this library to always generate the input type even if we are creating a response type.
|
|
320
|
+
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.
|
|
321
321
|
|
|
322
322
|
`.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()`.
|
|
323
323
|
|
|
@@ -553,7 +553,7 @@ zod-openapi was created while trying to add a feature to support auto registerin
|
|
|
553
553
|
|
|
554
554
|
3. No transform support or safety. You can use a `type` to override the transform type but what happens when that transform logic changes?
|
|
555
555
|
|
|
556
|
-
4.
|
|
556
|
+
4. No input/output validation with components. What happens when you register a component with a transform which technically comprises of two types in a request and a response?
|
|
557
557
|
|
|
558
558
|
Did I really rewrite an entire library just for this? Absolutely. I believe that creating documentation and types should be as simple and as frictionless as possible.
|
|
559
559
|
|
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createPipelineSchema = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
4
5
|
const _1 = require(".");
|
|
5
6
|
const createPipelineSchema = (zodPipeline, state) => {
|
|
7
|
+
if (zodPipeline._def.openapi?.effectType === 'input') {
|
|
8
|
+
return (0, _1.createSchemaOrRef)(zodPipeline._def.in, state);
|
|
9
|
+
}
|
|
10
|
+
if (zodPipeline._def.openapi?.effectType === 'output') {
|
|
11
|
+
return (0, _1.createSchemaOrRef)(zodPipeline._def.out, state);
|
|
12
|
+
}
|
|
6
13
|
if (state.type === 'input') {
|
|
14
|
+
if (state.effectType === 'output') {
|
|
15
|
+
(0, errors_1.throwTransformError)(zodPipeline);
|
|
16
|
+
}
|
|
17
|
+
state.effectType = 'input';
|
|
7
18
|
return (0, _1.createSchemaOrRef)(zodPipeline._def.in, state);
|
|
8
19
|
}
|
|
20
|
+
if (state.effectType === 'input') {
|
|
21
|
+
(0, errors_1.throwTransformError)(zodPipeline);
|
|
22
|
+
}
|
|
23
|
+
state.effectType = 'output';
|
|
9
24
|
return (0, _1.createSchemaOrRef)(zodPipeline._def.out, state);
|
|
10
25
|
};
|
|
11
26
|
exports.createPipelineSchema = createPipelineSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../../src/create/schema/pipeline.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../../src/create/schema/pipeline.ts"],"names":[],"mappings":";;;AAGA,sCAAgD;AAEhD,wBAAwD;AAEjD,MAAM,oBAAoB,GAAG,CAClC,WAAkC,EAClC,KAAkB,EAC0B,EAAE;IAC9C,IAAI,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,KAAK,OAAO,EAAE;QACpD,OAAO,IAAA,oBAAiB,EAAC,WAAW,CAAC,IAAI,CAAC,EAAgB,EAAE,KAAK,CAAC,CAAC;KACpE;IAED,IAAI,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,KAAK,QAAQ,EAAE;QACrD,OAAO,IAAA,oBAAiB,EAAC,WAAW,CAAC,IAAI,CAAC,GAAiB,EAAE,KAAK,CAAC,CAAC;KACrE;IAED,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE;QAC1B,IAAI,KAAK,CAAC,UAAU,KAAK,QAAQ,EAAE;YACjC,IAAA,4BAAmB,EAAC,WAAW,CAAC,CAAC;SAClC;QACD,KAAK,CAAC,UAAU,GAAG,OAAO,CAAC;QAC3B,OAAO,IAAA,oBAAiB,EAAC,WAAW,CAAC,IAAI,CAAC,EAAgB,EAAE,KAAK,CAAC,CAAC;KACpE;IAED,IAAI,KAAK,CAAC,UAAU,KAAK,OAAO,EAAE;QAChC,IAAA,4BAAmB,EAAC,WAAW,CAAC,CAAC;KAClC;IACD,KAAK,CAAC,UAAU,GAAG,QAAQ,CAAC;IAC5B,OAAO,IAAA,oBAAiB,EAAC,WAAW,CAAC,IAAI,CAAC,GAAiB,EAAE,KAAK,CAAC,CAAC;AACtE,CAAC,CAAC;AAzBW,QAAA,oBAAoB,wBAyB/B"}
|
|
@@ -5,16 +5,19 @@ const errors_1 = require("../errors");
|
|
|
5
5
|
const manual_1 = require("./manual");
|
|
6
6
|
const _1 = require(".");
|
|
7
7
|
const createTransformSchema = (zodTransform, state) => {
|
|
8
|
-
|
|
9
|
-
if (creationType === 'output') {
|
|
8
|
+
if (zodTransform._def.openapi?.effectType === 'output') {
|
|
10
9
|
return (0, manual_1.createManualTypeSchema)(zodTransform);
|
|
11
10
|
}
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
(0, errors_1.throwTransformError)(zodTransform);
|
|
15
|
-
}
|
|
16
|
-
state.effectType = 'input';
|
|
11
|
+
if (zodTransform._def.openapi?.effectType === 'input') {
|
|
12
|
+
return (0, _1.createSchemaOrRef)(zodTransform._def.schema, state);
|
|
17
13
|
}
|
|
14
|
+
if (state.type === 'output') {
|
|
15
|
+
return (0, manual_1.createManualTypeSchema)(zodTransform);
|
|
16
|
+
}
|
|
17
|
+
if (state.effectType === 'output') {
|
|
18
|
+
(0, errors_1.throwTransformError)(zodTransform);
|
|
19
|
+
}
|
|
20
|
+
state.effectType = 'input';
|
|
18
21
|
return (0, _1.createSchemaOrRef)(zodTransform._def.schema, state);
|
|
19
22
|
};
|
|
20
23
|
exports.createTransformSchema = createTransformSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/create/schema/transform.ts"],"names":[],"mappings":";;;AAGA,sCAAgD;AAEhD,qCAAkD;AAElD,wBAAwD;AAEjD,MAAM,qBAAqB,GAAG,CACnC,YAAuC,EACvC,KAAkB,EAC0B,EAAE;IAC9C,
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/create/schema/transform.ts"],"names":[],"mappings":";;;AAGA,sCAAgD;AAEhD,qCAAkD;AAElD,wBAAwD;AAEjD,MAAM,qBAAqB,GAAG,CACnC,YAAuC,EACvC,KAAkB,EAC0B,EAAE;IAC9C,IAAI,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,KAAK,QAAQ,EAAE;QACtD,OAAO,IAAA,+BAAsB,EAAC,YAAY,CAAC,CAAC;KAC7C;IAED,IAAI,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,KAAK,OAAO,EAAE;QACrD,OAAO,IAAA,oBAAiB,EAAC,YAAY,CAAC,IAAI,CAAC,MAAiB,EAAE,KAAK,CAAC,CAAC;KACtE;IAED,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE;QAC3B,OAAO,IAAA,+BAAsB,EAAC,YAAY,CAAC,CAAC;KAC7C;IAED,IAAI,KAAK,CAAC,UAAU,KAAK,QAAQ,EAAE;QACjC,IAAA,4BAAmB,EAAC,YAAY,CAAC,CAAC;KACnC;IACD,KAAK,CAAC,UAAU,GAAG,OAAO,CAAC;IAC3B,OAAO,IAAA,oBAAiB,EAAC,YAAY,CAAC,IAAI,CAAC,MAAiB,EAAE,KAAK,CAAC,CAAC;AACvE,CAAC,CAAC;AArBW,QAAA,qBAAqB,yBAqBhC"}
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
+
import { throwTransformError } from '../errors';
|
|
1
2
|
import { createSchemaOrRef } from '.';
|
|
2
3
|
export const createPipelineSchema = (zodPipeline, state) => {
|
|
4
|
+
if (zodPipeline._def.openapi?.effectType === 'input') {
|
|
5
|
+
return createSchemaOrRef(zodPipeline._def.in, state);
|
|
6
|
+
}
|
|
7
|
+
if (zodPipeline._def.openapi?.effectType === 'output') {
|
|
8
|
+
return createSchemaOrRef(zodPipeline._def.out, state);
|
|
9
|
+
}
|
|
3
10
|
if (state.type === 'input') {
|
|
11
|
+
if (state.effectType === 'output') {
|
|
12
|
+
throwTransformError(zodPipeline);
|
|
13
|
+
}
|
|
14
|
+
state.effectType = 'input';
|
|
4
15
|
return createSchemaOrRef(zodPipeline._def.in, state);
|
|
5
16
|
}
|
|
17
|
+
if (state.effectType === 'input') {
|
|
18
|
+
throwTransformError(zodPipeline);
|
|
19
|
+
}
|
|
20
|
+
state.effectType = 'output';
|
|
6
21
|
return createSchemaOrRef(zodPipeline._def.out, state);
|
|
7
22
|
};
|
|
8
23
|
//# sourceMappingURL=pipeline.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../../src/create/schema/pipeline.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../../src/create/schema/pipeline.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EAAoB,iBAAiB,EAAE,MAAM,GAAG,CAAC;AAExD,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,WAAkC,EAClC,KAAkB,EAC0B,EAAE;IAC9C,IAAI,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,KAAK,OAAO,EAAE;QACpD,OAAO,iBAAiB,CAAC,WAAW,CAAC,IAAI,CAAC,EAAgB,EAAE,KAAK,CAAC,CAAC;KACpE;IAED,IAAI,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,KAAK,QAAQ,EAAE;QACrD,OAAO,iBAAiB,CAAC,WAAW,CAAC,IAAI,CAAC,GAAiB,EAAE,KAAK,CAAC,CAAC;KACrE;IAED,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE;QAC1B,IAAI,KAAK,CAAC,UAAU,KAAK,QAAQ,EAAE;YACjC,mBAAmB,CAAC,WAAW,CAAC,CAAC;SAClC;QACD,KAAK,CAAC,UAAU,GAAG,OAAO,CAAC;QAC3B,OAAO,iBAAiB,CAAC,WAAW,CAAC,IAAI,CAAC,EAAgB,EAAE,KAAK,CAAC,CAAC;KACpE;IAED,IAAI,KAAK,CAAC,UAAU,KAAK,OAAO,EAAE;QAChC,mBAAmB,CAAC,WAAW,CAAC,CAAC;KAClC;IACD,KAAK,CAAC,UAAU,GAAG,QAAQ,CAAC;IAC5B,OAAO,iBAAiB,CAAC,WAAW,CAAC,IAAI,CAAC,GAAiB,EAAE,KAAK,CAAC,CAAC;AACtE,CAAC,CAAC"}
|
|
@@ -2,16 +2,19 @@ import { throwTransformError } from '../errors';
|
|
|
2
2
|
import { createManualTypeSchema } from './manual';
|
|
3
3
|
import { createSchemaOrRef } from '.';
|
|
4
4
|
export const createTransformSchema = (zodTransform, state) => {
|
|
5
|
-
|
|
6
|
-
if (creationType === 'output') {
|
|
5
|
+
if (zodTransform._def.openapi?.effectType === 'output') {
|
|
7
6
|
return createManualTypeSchema(zodTransform);
|
|
8
7
|
}
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
throwTransformError(zodTransform);
|
|
12
|
-
}
|
|
13
|
-
state.effectType = 'input';
|
|
8
|
+
if (zodTransform._def.openapi?.effectType === 'input') {
|
|
9
|
+
return createSchemaOrRef(zodTransform._def.schema, state);
|
|
14
10
|
}
|
|
11
|
+
if (state.type === 'output') {
|
|
12
|
+
return createManualTypeSchema(zodTransform);
|
|
13
|
+
}
|
|
14
|
+
if (state.effectType === 'output') {
|
|
15
|
+
throwTransformError(zodTransform);
|
|
16
|
+
}
|
|
17
|
+
state.effectType = 'input';
|
|
15
18
|
return createSchemaOrRef(zodTransform._def.schema, state);
|
|
16
19
|
};
|
|
17
20
|
//# sourceMappingURL=transform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/create/schema/transform.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD,OAAO,EAAoB,iBAAiB,EAAE,MAAM,GAAG,CAAC;AAExD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,YAAuC,EACvC,KAAkB,EAC0B,EAAE;IAC9C,
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/create/schema/transform.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD,OAAO,EAAoB,iBAAiB,EAAE,MAAM,GAAG,CAAC;AAExD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,YAAuC,EACvC,KAAkB,EAC0B,EAAE;IAC9C,IAAI,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,KAAK,QAAQ,EAAE;QACtD,OAAO,sBAAsB,CAAC,YAAY,CAAC,CAAC;KAC7C;IAED,IAAI,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,KAAK,OAAO,EAAE;QACrD,OAAO,iBAAiB,CAAC,YAAY,CAAC,IAAI,CAAC,MAAiB,EAAE,KAAK,CAAC,CAAC;KACtE;IAED,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE;QAC3B,OAAO,sBAAsB,CAAC,YAAY,CAAC,CAAC;KAC7C;IAED,IAAI,KAAK,CAAC,UAAU,KAAK,QAAQ,EAAE;QACjC,mBAAmB,CAAC,YAAY,CAAC,CAAC;KACnC;IACD,KAAK,CAAC,UAAU,GAAG,OAAO,CAAC;IAC3B,OAAO,iBAAiB,CAAC,YAAY,CAAC,IAAI,CAAC,MAAiB,EAAE,KAAK,CAAC,CAAC;AACvE,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod-openapi",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "A library to create full OpenAPI documents from your Zod types",
|
|
5
5
|
"homepage": "https://github.com/samchungy/zod-openapi#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"dependencies": {},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@redocly/cli": "1.0.0-beta.125",
|
|
38
|
-
"@types/node": "^
|
|
38
|
+
"@types/node": "^20.1.0",
|
|
39
39
|
"eslint-plugin-zod-openapi": "^0.1.0",
|
|
40
40
|
"openapi3-ts": "^4.1.2",
|
|
41
41
|
"skuba": "6.1.0",
|