zod-openapi 0.0.0-semantically-released → 0.2.0
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 +341 -75
- package/lib-commonjs/create/components.js +108 -0
- package/lib-commonjs/create/components.js.map +1 -0
- package/lib-commonjs/create/content.js +32 -0
- package/lib-commonjs/create/content.js.map +1 -0
- package/lib-commonjs/create/document.js +28 -0
- package/lib-commonjs/create/document.js.map +1 -0
- package/lib-commonjs/create/parameters.js +84 -0
- package/lib-commonjs/create/parameters.js.map +1 -0
- package/lib-commonjs/create/paths.js +68 -0
- package/lib-commonjs/create/paths.js.map +1 -0
- package/lib-commonjs/create/responses.js +93 -0
- package/lib-commonjs/create/responses.js.map +1 -0
- package/lib-commonjs/create/schema/array.js +17 -0
- package/lib-commonjs/create/schema/array.js.map +1 -0
- package/lib-commonjs/create/schema/boolean.js +8 -0
- package/lib-commonjs/create/schema/boolean.js.map +1 -0
- package/lib-commonjs/create/schema/date.js +8 -0
- package/lib-commonjs/create/schema/date.js.map +1 -0
- package/lib-commonjs/create/schema/default.js +14 -0
- package/lib-commonjs/create/schema/default.js.map +1 -0
- package/lib-commonjs/create/schema/discriminatedUnion.js +43 -0
- package/lib-commonjs/create/schema/discriminatedUnion.js.map +1 -0
- package/lib-commonjs/create/schema/effects.js +7 -0
- package/lib-commonjs/create/schema/effects.js.map +1 -0
- package/lib-commonjs/create/schema/enum.js +10 -0
- package/lib-commonjs/create/schema/enum.js.map +1 -0
- package/lib-commonjs/create/schema/index.js +127 -0
- package/lib-commonjs/create/schema/index.js.map +1 -0
- package/lib-commonjs/create/schema/intersection.js +12 -0
- package/lib-commonjs/create/schema/intersection.js.map +1 -0
- package/lib-commonjs/create/schema/literal.js +9 -0
- package/lib-commonjs/create/schema/literal.js.map +1 -0
- package/lib-commonjs/create/schema/metadata.js +38 -0
- package/lib-commonjs/create/schema/metadata.js.map +1 -0
- package/lib-commonjs/create/schema/nativeEnum.js +35 -0
- package/lib-commonjs/create/schema/nativeEnum.js.map +1 -0
- package/lib-commonjs/create/schema/null.js +8 -0
- package/lib-commonjs/create/schema/null.js.map +1 -0
- package/lib-commonjs/create/schema/nullable.js +52 -0
- package/lib-commonjs/create/schema/nullable.js.map +1 -0
- package/lib-commonjs/create/schema/number.js +28 -0
- package/lib-commonjs/create/schema/number.js.map +1 -0
- package/lib-commonjs/create/schema/object.js +51 -0
- package/lib-commonjs/create/schema/object.js.map +1 -0
- package/lib-commonjs/create/schema/optional.js +9 -0
- package/lib-commonjs/create/schema/optional.js.map +1 -0
- package/lib-commonjs/create/schema/record.js +10 -0
- package/lib-commonjs/create/schema/record.js.map +1 -0
- package/lib-commonjs/create/schema/string.js +46 -0
- package/lib-commonjs/create/schema/string.js.map +1 -0
- package/lib-commonjs/create/schema/tuple.js +29 -0
- package/lib-commonjs/create/schema/tuple.js.map +1 -0
- package/lib-commonjs/create/schema/union.js +13 -0
- package/lib-commonjs/create/schema/union.js.map +1 -0
- package/lib-commonjs/create/specificationExtension.js +6 -0
- package/lib-commonjs/create/specificationExtension.js.map +1 -0
- package/lib-commonjs/extendZod.js +49 -0
- package/lib-commonjs/extendZod.js.map +1 -0
- package/lib-commonjs/index.js +16 -9
- package/lib-commonjs/index.js.map +1 -1
- package/lib-es2015/create/components.js +102 -0
- package/lib-es2015/create/components.js.map +1 -0
- package/lib-es2015/create/content.js +28 -0
- package/lib-es2015/create/content.js.map +1 -0
- package/lib-es2015/create/document.js +22 -0
- package/lib-es2015/create/document.js.map +1 -0
- package/lib-es2015/create/parameters.js +78 -0
- package/lib-es2015/create/parameters.js.map +1 -0
- package/lib-es2015/create/paths.js +64 -0
- package/lib-es2015/create/paths.js.map +1 -0
- package/lib-es2015/create/responses.js +86 -0
- package/lib-es2015/create/responses.js.map +1 -0
- package/lib-es2015/create/schema/array.js +13 -0
- package/lib-es2015/create/schema/array.js.map +1 -0
- package/lib-es2015/create/schema/boolean.js +4 -0
- package/lib-es2015/create/schema/boolean.js.map +1 -0
- package/lib-es2015/create/schema/date.js +4 -0
- package/lib-es2015/create/schema/date.js.map +1 -0
- package/lib-es2015/create/schema/default.js +10 -0
- package/lib-es2015/create/schema/default.js.map +1 -0
- package/lib-es2015/create/schema/discriminatedUnion.js +38 -0
- package/lib-es2015/create/schema/discriminatedUnion.js.map +1 -0
- package/lib-es2015/create/schema/effects.js +3 -0
- package/lib-es2015/create/schema/effects.js.map +1 -0
- package/lib-es2015/create/schema/enum.js +6 -0
- package/lib-es2015/create/schema/enum.js.map +1 -0
- package/lib-es2015/create/schema/index.js +121 -0
- package/lib-es2015/create/schema/index.js.map +1 -0
- package/lib-es2015/create/schema/intersection.js +8 -0
- package/lib-es2015/create/schema/intersection.js.map +1 -0
- package/lib-es2015/create/schema/literal.js +5 -0
- package/lib-es2015/create/schema/literal.js.map +1 -0
- package/lib-es2015/create/schema/metadata.js +33 -0
- package/lib-es2015/create/schema/metadata.js.map +1 -0
- package/lib-es2015/create/schema/nativeEnum.js +29 -0
- package/lib-es2015/create/schema/nativeEnum.js.map +1 -0
- package/lib-es2015/create/schema/null.js +4 -0
- package/lib-es2015/create/schema/null.js.map +1 -0
- package/lib-es2015/create/schema/nullable.js +47 -0
- package/lib-es2015/create/schema/nullable.js.map +1 -0
- package/lib-es2015/create/schema/number.js +24 -0
- package/lib-es2015/create/schema/number.js.map +1 -0
- package/lib-es2015/create/schema/object.js +43 -0
- package/lib-es2015/create/schema/object.js.map +1 -0
- package/lib-es2015/create/schema/optional.js +5 -0
- package/lib-es2015/create/schema/optional.js.map +1 -0
- package/lib-es2015/create/schema/record.js +6 -0
- package/lib-es2015/create/schema/record.js.map +1 -0
- package/lib-es2015/create/schema/string.js +42 -0
- package/lib-es2015/create/schema/string.js.map +1 -0
- package/lib-es2015/create/schema/tuple.js +25 -0
- package/lib-es2015/create/schema/tuple.js.map +1 -0
- package/lib-es2015/create/schema/union.js +9 -0
- package/lib-es2015/create/schema/union.js.map +1 -0
- package/lib-es2015/create/specificationExtension.js +2 -0
- package/lib-es2015/create/specificationExtension.js.map +1 -0
- package/lib-es2015/extendZod.js +45 -0
- package/lib-es2015/extendZod.js.map +1 -0
- package/lib-es2015/index.js +2 -7
- package/lib-es2015/index.js.map +1 -1
- package/lib-types/create/components.d.ts +33 -0
- package/lib-types/create/content.d.ts +4 -0
- package/lib-types/create/document.d.ts +62 -0
- package/lib-types/create/parameters.d.ts +7 -0
- package/lib-types/create/paths.d.ts +4 -0
- package/lib-types/create/responses.d.ts +8 -0
- package/lib-types/create/schema/array.d.ts +4 -0
- package/lib-types/create/schema/boolean.d.ts +3 -0
- package/lib-types/create/schema/date.d.ts +3 -0
- package/lib-types/create/schema/default.d.ts +4 -0
- package/lib-types/create/schema/discriminatedUnion.d.ts +10 -0
- package/lib-types/create/schema/effects.d.ts +4 -0
- package/lib-types/create/schema/enum.d.ts +3 -0
- package/lib-types/create/schema/index.d.ts +6 -0
- package/lib-types/create/schema/intersection.d.ts +4 -0
- package/lib-types/create/schema/literal.d.ts +3 -0
- package/lib-types/create/schema/metadata.d.ts +5 -0
- package/lib-types/create/schema/nativeEnum.d.ts +10 -0
- package/lib-types/create/schema/null.d.ts +3 -0
- package/lib-types/create/schema/nullable.d.ts +5 -0
- package/lib-types/create/schema/number.d.ts +3 -0
- package/lib-types/create/schema/object.d.ts +8 -0
- package/lib-types/create/schema/optional.d.ts +4 -0
- package/lib-types/create/schema/record.d.ts +4 -0
- package/lib-types/create/schema/string.d.ts +3 -0
- package/lib-types/create/schema/tuple.d.ts +4 -0
- package/lib-types/create/schema/union.d.ts +4 -0
- package/lib-types/create/specificationExtension.d.ts +1 -0
- package/lib-types/extendZod.d.ts +36 -0
- package/lib-types/index.d.ts +2 -5
- package/package.json +14 -7
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createParametersObject = exports.createBaseParameter = exports.createComponentParamRef = void 0;
|
|
4
|
+
const schema_1 = require("./schema");
|
|
5
|
+
const createComponentParamRef = (ref) => `#/components/parameters/${ref}`;
|
|
6
|
+
exports.createComponentParamRef = createComponentParamRef;
|
|
7
|
+
const createBaseParameter = (schema, components) => {
|
|
8
|
+
const { ref, ...rest } = schema._def.openapi?.param ?? {};
|
|
9
|
+
const schemaOrRef = (0, schema_1.createSchemaOrRef)(schema, components);
|
|
10
|
+
const required = !schema.isOptional();
|
|
11
|
+
return {
|
|
12
|
+
...rest,
|
|
13
|
+
...(schema && { schema: schemaOrRef }),
|
|
14
|
+
...(required && { required }),
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
exports.createBaseParameter = createBaseParameter;
|
|
18
|
+
const createRegisteredParam = (zodSchema, ref, type, name, components) => {
|
|
19
|
+
const component = components.parameters[ref];
|
|
20
|
+
if (component) {
|
|
21
|
+
if (!('$ref' in component.paramObject) &&
|
|
22
|
+
(component.zodSchema !== zodSchema ||
|
|
23
|
+
component.paramObject.in !== type ||
|
|
24
|
+
component.paramObject.name !== name)) {
|
|
25
|
+
throw new Error(`parameterRef "${ref}" is already registered`);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
$ref: (0, exports.createComponentParamRef)(ref),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
// Optional Objects can return a reference object
|
|
32
|
+
const baseParamOrRef = (0, exports.createBaseParameter)(zodSchema, components);
|
|
33
|
+
if ('$ref' in baseParamOrRef) {
|
|
34
|
+
throw new Error('Unexpected Error: received a reference object');
|
|
35
|
+
}
|
|
36
|
+
components.parameters[ref] = {
|
|
37
|
+
paramObject: {
|
|
38
|
+
in: type,
|
|
39
|
+
name,
|
|
40
|
+
...baseParamOrRef,
|
|
41
|
+
},
|
|
42
|
+
zodSchema,
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
$ref: (0, exports.createComponentParamRef)(ref),
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
const createParamOrRef = (schema, type, name, components) => {
|
|
49
|
+
const ref = schema?._def?.openapi?.param?.ref;
|
|
50
|
+
if (ref) {
|
|
51
|
+
return createRegisteredParam(schema, ref, type, name, components);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
in: type,
|
|
55
|
+
name,
|
|
56
|
+
...(0, exports.createBaseParameter)(schema, components),
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
const createParameters = (type, zodObject, components) => {
|
|
60
|
+
if (!zodObject) {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
return Object.entries(zodObject.shape).map(([key, zodSchema]) => createParamOrRef(zodSchema, type, key, components));
|
|
64
|
+
};
|
|
65
|
+
const createRequestParams = (requestParams, components) => {
|
|
66
|
+
if (!requestParams) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
const pathParams = createParameters('path', requestParams.path, components);
|
|
70
|
+
const queryParams = createParameters('query', requestParams.query, components);
|
|
71
|
+
const cookieParams = createParameters('cookie', requestParams.cookie, components);
|
|
72
|
+
const headerParams = createParameters('header', requestParams.header, components);
|
|
73
|
+
return [...pathParams, ...queryParams, ...cookieParams, ...headerParams];
|
|
74
|
+
};
|
|
75
|
+
const createParametersObject = (parameters, requestParams, components) => {
|
|
76
|
+
const createdParams = createRequestParams(requestParams, components);
|
|
77
|
+
const combinedParameters = [
|
|
78
|
+
...(parameters ? parameters : []),
|
|
79
|
+
...createdParams,
|
|
80
|
+
];
|
|
81
|
+
return combinedParameters.length ? combinedParameters : undefined;
|
|
82
|
+
};
|
|
83
|
+
exports.createParametersObject = createParametersObject;
|
|
84
|
+
//# sourceMappingURL=parameters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameters.js","sourceRoot":"","sources":["../../src/create/parameters.ts"],"names":[],"mappings":";;;AAKA,qCAA6C;AAEtC,MAAM,uBAAuB,GAAG,CAAC,GAAW,EAAE,EAAE,CACrD,2BAA2B,GAAG,EAAE,CAAC;AADtB,QAAA,uBAAuB,2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,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAC5E,MAAM,WAAW,GAAG,gBAAgB,CAClC,OAAO,EACP,aAAa,CAAC,KAAK,EACnB,UAAU,CACX,CAAC;IACF,MAAM,YAAY,GAAG,gBAAgB,CACnC,QAAQ,EACR,aAAa,CAAC,MAAM,EACpB,UAAU,CACX,CAAC;IACF,MAAM,YAAY,GAAG,gBAAgB,CACnC,QAAQ,EACR,aAAa,CAAC,MAAM,EACpB,UAAU,CACX,CAAC;IAEF,OAAO,CAAC,GAAG,UAAU,EAAE,GAAG,WAAW,EAAE,GAAG,YAAY,EAAE,GAAG,YAAY,CAAC,CAAC;AAC3E,CAAC,CAAC;AAEK,MAAM,sBAAsB,GAAG,CACpC,UAAyE,EACzE,aAA+C,EAC/C,UAA4B,EACmC,EAAE;IACjE,MAAM,aAAa,GAAG,mBAAmB,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;IACrE,MAAM,kBAAkB,GAAwC;QAC9D,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;QACjC,GAAG,aAAa;KACjB,CAAC;IAEF,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAC;AACpE,CAAC,CAAC;AAZW,QAAA,sBAAsB,0BAYjC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPaths = void 0;
|
|
4
|
+
const content_1 = require("./content");
|
|
5
|
+
const parameters_1 = require("./parameters");
|
|
6
|
+
const responses_1 = require("./responses");
|
|
7
|
+
const specificationExtension_1 = require("./specificationExtension");
|
|
8
|
+
const createRequestBody = (requestBodyObject, components) => {
|
|
9
|
+
if (!requestBodyObject) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
...requestBodyObject,
|
|
14
|
+
content: (0, content_1.createContent)(requestBodyObject.content, components),
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
const createOperation = (operationObject, components) => {
|
|
18
|
+
if (!operationObject) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
const { parameters, requestParams, requestBody, responses, ...rest } = operationObject;
|
|
22
|
+
const maybeParameters = (0, parameters_1.createParametersObject)(parameters, requestParams, components);
|
|
23
|
+
const maybeRequestBody = createRequestBody(operationObject.requestBody, components);
|
|
24
|
+
const maybeResponses = (0, responses_1.createResponses)(operationObject.responses, components);
|
|
25
|
+
return {
|
|
26
|
+
...rest,
|
|
27
|
+
...(maybeParameters && { parameters: maybeParameters }),
|
|
28
|
+
...(maybeRequestBody && { requestBody: maybeRequestBody }),
|
|
29
|
+
...(maybeResponses && { responses: maybeResponses }),
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const createPathItem = (pathObject, components) => {
|
|
33
|
+
const { get, put, post, delete: del, options, head, patch, trace, ...rest } = pathObject;
|
|
34
|
+
const maybeGet = createOperation(get, components);
|
|
35
|
+
const maybePut = createOperation(put, components);
|
|
36
|
+
const maybePost = createOperation(post, components);
|
|
37
|
+
const maybeDelete = createOperation(del, components);
|
|
38
|
+
const maybeOptions = createOperation(options, components);
|
|
39
|
+
const maybeHead = createOperation(head, components);
|
|
40
|
+
const maybePatch = createOperation(patch, components);
|
|
41
|
+
const maybeTrace = createOperation(trace, components);
|
|
42
|
+
return {
|
|
43
|
+
...rest,
|
|
44
|
+
...(get && { get: maybeGet }),
|
|
45
|
+
...(put && { put: maybePut }),
|
|
46
|
+
...(post && { post: maybePost }),
|
|
47
|
+
...(del && { delete: maybeDelete }),
|
|
48
|
+
...(options && { options: maybeOptions }),
|
|
49
|
+
...(head && { head: maybeHead }),
|
|
50
|
+
...(patch && { patch: maybePatch }),
|
|
51
|
+
...(trace && { trace: maybeTrace }),
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const createPaths = (pathsObject, components) => {
|
|
55
|
+
if (!pathsObject) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
return Object.entries(pathsObject).reduce((acc, [path, pathItemObject]) => {
|
|
59
|
+
if ((0, specificationExtension_1.isISpecificationExtension)(path)) {
|
|
60
|
+
acc[path] = pathItemObject;
|
|
61
|
+
return acc;
|
|
62
|
+
}
|
|
63
|
+
acc[path] = createPathItem(pathItemObject, components);
|
|
64
|
+
return acc;
|
|
65
|
+
}, {});
|
|
66
|
+
};
|
|
67
|
+
exports.createPaths = createPaths;
|
|
68
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/create/paths.ts"],"names":[],"mappings":";;;AAGA,uCAA0C;AAO1C,6CAAsD;AACtD,2CAA8C;AAC9C,qEAAqE;AAErE,MAAM,iBAAiB,GAAG,CACxB,iBAA0D,EAC1D,UAA4B,EACS,EAAE;IACvC,IAAI,CAAC,iBAAiB,EAAE;QACtB,OAAO,SAAS,CAAC;KAClB;IACD,OAAO;QACL,GAAG,iBAAiB;QACpB,OAAO,EAAE,IAAA,uBAAa,EAAC,iBAAiB,CAAC,OAAO,EAAE,UAAU,CAAC;KAC9D,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CACtB,eAAsD,EACtD,UAA4B,EACO,EAAE;IACrC,IAAI,CAAC,eAAe,EAAE;QACpB,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,GAClE,eAAe,CAAC;IAElB,MAAM,eAAe,GAAG,IAAA,mCAAsB,EAC5C,UAAU,EACV,aAAa,EACb,UAAU,CACX,CAAC;IAEF,MAAM,gBAAgB,GAAG,iBAAiB,CACxC,eAAe,CAAC,WAAW,EAC3B,UAAU,CACX,CAAC;IAEF,MAAM,cAAc,GAA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,CAAC;QAC7B,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QAChC,GAAG,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;QACnC,GAAG,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;QACzC,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QAChC,GAAG,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;QACnC,GAAG,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;KACpC,CAAC;AACJ,CAAC,CAAC;AAEK,MAAM,WAAW,GAAG,CACzB,WAA8C,EAC9C,UAA4B,EACG,EAAE;IACjC,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,CACvC,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,cAAc,CAAC,EAAqB,EAAE;QACjD,IAAI,IAAA,kDAAyB,EAAC,IAAI,CAAC,EAAE;YACnC,GAAG,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;YAC3B,OAAO,GAAG,CAAC;SACZ;QACD,GAAG,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;QACvD,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAE,CACH,CAAC;AACJ,CAAC,CAAC;AAnBW,QAAA,WAAW,eAmBtB"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createResponses = exports.createComponentHeaderRef = exports.createBaseHeader = exports.createResponseHeaders = void 0;
|
|
4
|
+
const content_1 = require("./content");
|
|
5
|
+
const parameters_1 = require("./parameters");
|
|
6
|
+
const schema_1 = require("./schema");
|
|
7
|
+
const specificationExtension_1 = require("./specificationExtension");
|
|
8
|
+
const createResponseHeaders = (responseHeaders, components) => {
|
|
9
|
+
if (!responseHeaders) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
return Object.entries(responseHeaders.shape).reduce((acc, [key, zodSchema]) => {
|
|
13
|
+
acc[key] = createHeaderOrRef(zodSchema, components);
|
|
14
|
+
return acc;
|
|
15
|
+
}, {});
|
|
16
|
+
};
|
|
17
|
+
exports.createResponseHeaders = createResponseHeaders;
|
|
18
|
+
const createHeaderOrRef = (schema, components) => {
|
|
19
|
+
const ref = schema?._def?.openapi?.header?.ref;
|
|
20
|
+
if (ref) {
|
|
21
|
+
return createRegisteredHeader(schema, ref, components);
|
|
22
|
+
}
|
|
23
|
+
return (0, exports.createBaseHeader)(schema, components);
|
|
24
|
+
};
|
|
25
|
+
const createBaseHeader = (schema, components) => {
|
|
26
|
+
const { ref, ...rest } = schema._def.openapi?.header ?? {};
|
|
27
|
+
const schemaOrRef = (0, schema_1.createSchemaOrRef)(schema, components);
|
|
28
|
+
const required = !schema.isOptional();
|
|
29
|
+
return {
|
|
30
|
+
...rest,
|
|
31
|
+
...(schema && { schema: schemaOrRef }),
|
|
32
|
+
...(required && { required }),
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
exports.createBaseHeader = createBaseHeader;
|
|
36
|
+
const createRegisteredHeader = (zodSchema, ref, components) => {
|
|
37
|
+
const component = components.headers[ref];
|
|
38
|
+
if (component) {
|
|
39
|
+
if (!('$ref' in component.headerObject) &&
|
|
40
|
+
component.zodSchema !== zodSchema) {
|
|
41
|
+
throw new Error(`header "${ref}" is already registered`);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
$ref: (0, exports.createComponentHeaderRef)(ref),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// Optional Objects can return a reference object
|
|
48
|
+
const baseParamOrRef = (0, parameters_1.createBaseParameter)(zodSchema, components);
|
|
49
|
+
if ('$ref' in baseParamOrRef) {
|
|
50
|
+
throw new Error('Unexpected Error: received a reference object');
|
|
51
|
+
}
|
|
52
|
+
components.headers[ref] = {
|
|
53
|
+
headerObject: baseParamOrRef,
|
|
54
|
+
zodSchema,
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
$ref: (0, exports.createComponentHeaderRef)(ref),
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
const createComponentHeaderRef = (ref) => `#/components/headers/${ref}`;
|
|
61
|
+
exports.createComponentHeaderRef = createComponentHeaderRef;
|
|
62
|
+
const createHeaders = (headers, responseHeaders, components) => {
|
|
63
|
+
if (!responseHeaders && !headers) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
const createdHeaders = (0, exports.createResponseHeaders)(responseHeaders, components);
|
|
67
|
+
return {
|
|
68
|
+
...headers,
|
|
69
|
+
...createdHeaders,
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
const createResponse = (responseObject, components) => {
|
|
73
|
+
if ('$ref' in responseObject) {
|
|
74
|
+
return responseObject;
|
|
75
|
+
}
|
|
76
|
+
const { content, headers, responseHeaders, ...rest } = responseObject;
|
|
77
|
+
const maybeHeaders = createHeaders(headers, responseHeaders, components);
|
|
78
|
+
return {
|
|
79
|
+
...rest,
|
|
80
|
+
...(maybeHeaders && { headers: maybeHeaders }),
|
|
81
|
+
...(content && { content: (0, content_1.createContent)(content, components) }),
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
const createResponses = (responsesObject, components) => Object.entries(responsesObject).reduce((acc, [path, responseObject]) => {
|
|
85
|
+
if ((0, specificationExtension_1.isISpecificationExtension)(path)) {
|
|
86
|
+
acc[path] = responseObject;
|
|
87
|
+
return acc;
|
|
88
|
+
}
|
|
89
|
+
acc[path] = createResponse(responseObject, components);
|
|
90
|
+
return acc;
|
|
91
|
+
}, {});
|
|
92
|
+
exports.createResponses = createResponses;
|
|
93
|
+
//# sourceMapp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17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createArraySchema = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const createArraySchema = (zodArray, components) => {
|
|
6
|
+
const zodType = zodArray._def.type;
|
|
7
|
+
const minItems = zodArray._def.exactLength?.value ?? zodArray._def.minLength?.value;
|
|
8
|
+
const maxItems = zodArray._def.exactLength?.value ?? zodArray._def.maxLength?.value;
|
|
9
|
+
return {
|
|
10
|
+
type: 'array',
|
|
11
|
+
items: (0, _1.createSchemaOrRef)(zodType, components),
|
|
12
|
+
...(minItems !== undefined && { minItems }),
|
|
13
|
+
...(maxItems !== undefined && { maxItems }),
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
exports.createArraySchema = createArraySchema;
|
|
17
|
+
//# sourceMappingURL=array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../../src/create/schema/array.ts"],"names":[],"mappings":";;;AAKA,wBAAsC;AAE/B,MAAM,iBAAiB,GAAG,CAC/B,QAA4B,EAC5B,UAA4B,EACR,EAAE;IACtB,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAkB,CAAC;IACjD,MAAM,QAAQ,GACZ,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC;IACrE,MAAM,QAAQ,GACZ,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC;IACrE,OAAO;QACL,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,IAAA,oBAAiB,EAAC,OAAO,EAAE,UAAU,CAAC;QAC7C,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,EAAE,QAAQ,EAAE,CAAC;QAC3C,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,EAAE,QAAQ,EAAE,CAAC;KAC5C,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,iBAAiB,qBAe5B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBooleanSchema = void 0;
|
|
4
|
+
const createBooleanSchema = (_zodBoolean) => ({
|
|
5
|
+
type: 'boolean',
|
|
6
|
+
});
|
|
7
|
+
exports.createBooleanSchema = createBooleanSchema;
|
|
8
|
+
//# sourceMappingURL=boolean.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../../src/create/schema/boolean.ts"],"names":[],"mappings":";;;AAGO,MAAM,mBAAmB,GAAG,CACjC,WAAuB,EACH,EAAE,CAAC,CAAC;IACxB,IAAI,EAAE,SAAS;CAChB,CAAC,CAAC;AAJU,QAAA,mBAAmB,uBAI7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../../src/create/schema/date.ts"],"names":[],"mappings":";;;AAGO,MAAM,gBAAgB,GAAG,CAAC,QAAiB,EAAsB,EAAE,CAAC,CAAC;IAC1E,IAAI,EAAE,QAAQ;CACf,CAAC,CAAC;AAFU,QAAA,gBAAgB,oBAE1B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDefaultSchema = void 0;
|
|
4
|
+
const metadata_1 = require("./metadata");
|
|
5
|
+
const _1 = require(".");
|
|
6
|
+
const createDefaultSchema = (zodDefault, components) => {
|
|
7
|
+
const schemaOrRef = (0, _1.createSchemaOrRef)(zodDefault._def.innerType, components);
|
|
8
|
+
return (0, metadata_1.enhanceWithMetadata)(schemaOrRef, {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
10
|
+
default: zodDefault._def.defaultValue(),
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
exports.createDefaultSchema = createDefaultSchema;
|
|
14
|
+
//# sourceMappingURL=default.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default.js","sourceRoot":"","sources":["../../../src/create/schema/default.ts"],"names":[],"mappings":";;;AAKA,yCAAiD;AAEjD,wBAAsC;AAE/B,MAAM,mBAAmB,GAAG,CACjC,UAA2B,EAC3B,UAA4B,EACgB,EAAE;IAC9C,MAAM,WAAW,GAAG,IAAA,oBAAiB,EACnC,UAAU,CAAC,IAAI,CAAC,SAAuB,EACvC,UAAU,CACX,CAAC;IAEF,OAAO,IAAA,8BAAmB,EAAC,WAAW,EAAE;QACtC,mEAAmE;QACnE,OAAO,EAAE,UAAU,CAAC,IAAI,CAAC,YAAY,EAAE;KACxC,CAAC,CAAC;AACL,CAAC,CAAC;AAbW,QAAA,mBAAmB,uBAa9B"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapDiscriminator = exports.createDiscriminatedUnionSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const components_1 = require("../components");
|
|
6
|
+
const _1 = require(".");
|
|
7
|
+
const createDiscriminatedUnionSchema = (zodDiscriminatedUnion, components) => {
|
|
8
|
+
const options = zodDiscriminatedUnion.options;
|
|
9
|
+
const schemas = options.map((option) => (0, _1.createSchemaOrRef)(option, components));
|
|
10
|
+
const discriminator = (0, exports.mapDiscriminator)(options, zodDiscriminatedUnion.discriminator);
|
|
11
|
+
return {
|
|
12
|
+
oneOf: schemas,
|
|
13
|
+
...(discriminator && { discriminator }),
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
exports.createDiscriminatedUnionSchema = createDiscriminatedUnionSchema;
|
|
17
|
+
const mapDiscriminator = (zodObjects, discriminator) => {
|
|
18
|
+
if (zodObjects.some((obj) => !obj._def.openapi?.ref)) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
const mapping = zodObjects.reduce((acc, zodObject) => {
|
|
22
|
+
const schemaRef = zodObject._def.openapi?.ref;
|
|
23
|
+
const value = zodObject.shape[discriminator];
|
|
24
|
+
if (value instanceof zod_1.ZodEnum) {
|
|
25
|
+
for (const enumValue of value._def.values) {
|
|
26
|
+
acc[enumValue] = (0, components_1.createComponentSchemaRef)(schemaRef);
|
|
27
|
+
}
|
|
28
|
+
return acc;
|
|
29
|
+
}
|
|
30
|
+
const literalValue = (value?._def).value;
|
|
31
|
+
if (typeof literalValue !== 'string') {
|
|
32
|
+
throw new Error(`Discriminator ${discriminator} could not be found in one of the values of a discriminated union`);
|
|
33
|
+
}
|
|
34
|
+
acc[literalValue] = (0, components_1.createComponentSchemaRef)(schemaRef);
|
|
35
|
+
return acc;
|
|
36
|
+
}, {});
|
|
37
|
+
return {
|
|
38
|
+
propertyName: discriminator,
|
|
39
|
+
mapping,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
exports.mapDiscriminator = mapDiscriminator;
|
|
43
|
+
//# sourceMappingURL=discriminatedUnion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminatedUnion.js","sourceRoot":"","sources":["../../../src/create/schema/discriminatedUnion.ts"],"names":[],"mappings":";;;AACA,6BAMa;AAEb,8CAA2E;AAE3E,wBAAsC;AAE/B,MAAM,8BAA8B,GAAG,CAC5C,qBAAsD,EACtD,UAA4B,EACR,EAAE;IACtB,MAAM,OAAO,GAAG,qBAAqB,CAAC,OAAyB,CAAC;IAChE,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CACrC,IAAA,oBAAiB,EAAC,MAAM,EAAE,UAAU,CAAC,CACtC,CAAC;IACF,MAAM,aAAa,GAAG,IAAA,wBAAgB,EACpC,OAA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J,CAAC,CAAC;AArCW,QAAA,gBAAgB,oBAqC3B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEffectsSchema = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const createEffectsSchema = (zodEffects, components) => (0, _1.createSchemaOrRef)(zodEffects._def.schema, components);
|
|
6
|
+
exports.createEffectsSchema = createEffectsSchema;
|
|
7
|
+
//# sourceMappingURL=effects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effects.js","sourceRoot":"","sources":["../../../src/create/schema/effects.ts"],"names":[],"mappings":";;;AAKA,wBAAsC;AAE/B,MAAM,mBAAmB,GAAG,CACjC,UAAqC,EACrC,UAA4B,EACgB,EAAE,CAC9C,IAAA,oBAAiB,EAAC,UAAU,CAAC,IAAI,CAAC,MAAiB,EAAE,UAAU,CAAC,CAAC;AAJtD,QAAA,mBAAmB,uBAImC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEnumSchema = void 0;
|
|
4
|
+
const createEnumSchema = (zodEnum) => ({
|
|
5
|
+
type: 'string',
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
7
|
+
enum: zodEnum._def.values,
|
|
8
|
+
});
|
|
9
|
+
exports.createEnumSchema = createEnumSchema;
|
|
10
|
+
//# sourceMappingURL=enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../../src/create/schema/enum.ts"],"names":[],"mappings":";;;AAGO,MAAM,gBAAgB,GAAG,CAC9B,OAAqB,EACD,EAAE,CAAC,CAAC;IACxB,IAAI,EAAE,QAAQ;IACd,mEAAmE;IACnE,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM;CAC1B,CAAC,CAAC;AANU,QAAA,gBAAgB,oBAM1B"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSchemaOrRef = exports.createRegisteredSchema = exports.createSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const components_1 = require("../components");
|
|
6
|
+
const array_1 = require("./array");
|
|
7
|
+
const boolean_1 = require("./boolean");
|
|
8
|
+
const date_1 = require("./date");
|
|
9
|
+
const default_1 = require("./default");
|
|
10
|
+
const discriminatedUnion_1 = require("./discriminatedUnion");
|
|
11
|
+
const effects_1 = require("./effects");
|
|
12
|
+
const enum_1 = require("./enum");
|
|
13
|
+
const intersection_1 = require("./intersection");
|
|
14
|
+
const literal_1 = require("./literal");
|
|
15
|
+
const metadata_1 = require("./metadata");
|
|
16
|
+
const nativeEnum_1 = require("./nativeEnum");
|
|
17
|
+
const null_1 = require("./null");
|
|
18
|
+
const nullable_1 = require("./nullable");
|
|
19
|
+
const number_1 = require("./number");
|
|
20
|
+
const object_1 = require("./object");
|
|
21
|
+
const optional_1 = require("./optional");
|
|
22
|
+
const record_1 = require("./record");
|
|
23
|
+
const string_1 = require("./string");
|
|
24
|
+
const tuple_1 = require("./tuple");
|
|
25
|
+
const union_1 = require("./union");
|
|
26
|
+
const createSchema = (zodSchema, components) => {
|
|
27
|
+
if (zodSchema instanceof zod_1.ZodString) {
|
|
28
|
+
return (0, string_1.createStringSchema)(zodSchema);
|
|
29
|
+
}
|
|
30
|
+
if (zodSchema instanceof zod_1.ZodNumber) {
|
|
31
|
+
return (0, number_1.createNumberSchema)(zodSchema);
|
|
32
|
+
}
|
|
33
|
+
if (zodSchema instanceof zod_1.ZodBoolean) {
|
|
34
|
+
return (0, boolean_1.createBooleanSchema)(zodSchema);
|
|
35
|
+
}
|
|
36
|
+
if (zodSchema instanceof zod_1.ZodEnum) {
|
|
37
|
+
return (0, enum_1.createEnumSchema)(zodSchema);
|
|
38
|
+
}
|
|
39
|
+
if (zodSchema instanceof zod_1.ZodLiteral) {
|
|
40
|
+
return (0, literal_1.createLiteralSchema)(zodSchema);
|
|
41
|
+
}
|
|
42
|
+
if (zodSchema instanceof zod_1.ZodNativeEnum) {
|
|
43
|
+
return (0, nativeEnum_1.createNativeEnumSchema)(zodSchema);
|
|
44
|
+
}
|
|
45
|
+
if (zodSchema instanceof zod_1.ZodArray) {
|
|
46
|
+
return (0, array_1.createArraySchema)(zodSchema, components);
|
|
47
|
+
}
|
|
48
|
+
if (zodSchema instanceof zod_1.ZodObject) {
|
|
49
|
+
return (0, object_1.createObjectSchema)(zodSchema, components);
|
|
50
|
+
}
|
|
51
|
+
if (zodSchema instanceof zod_1.ZodUnion) {
|
|
52
|
+
return (0, union_1.createUnionSchema)(zodSchema, components);
|
|
53
|
+
}
|
|
54
|
+
if (zodSchema instanceof zod_1.ZodDiscriminatedUnion) {
|
|
55
|
+
return (0, discriminatedUnion_1.createDiscriminatedUnionSchema)(zodSchema, components);
|
|
56
|
+
}
|
|
57
|
+
if (zodSchema instanceof zod_1.ZodNull) {
|
|
58
|
+
return (0, null_1.createNullSchema)(zodSchema);
|
|
59
|
+
}
|
|
60
|
+
if (zodSchema instanceof zod_1.ZodNullable) {
|
|
61
|
+
return (0, nullable_1.createNullableSchema)(zodSchema, components);
|
|
62
|
+
}
|
|
63
|
+
if (zodSchema instanceof zod_1.ZodOptional) {
|
|
64
|
+
return (0, optional_1.createOptionalSchema)(zodSchema, components);
|
|
65
|
+
}
|
|
66
|
+
if (zodSchema instanceof zod_1.ZodDefault) {
|
|
67
|
+
return (0, default_1.createDefaultSchema)(zodSchema, components);
|
|
68
|
+
}
|
|
69
|
+
if (zodSchema instanceof zod_1.ZodRecord) {
|
|
70
|
+
return (0, record_1.createRecordSchema)(zodSchema, components);
|
|
71
|
+
}
|
|
72
|
+
if (zodSchema instanceof zod_1.ZodTuple) {
|
|
73
|
+
return (0, tuple_1.createTupleSchema)(zodSchema, components);
|
|
74
|
+
}
|
|
75
|
+
if (zodSchema instanceof zod_1.ZodDate) {
|
|
76
|
+
return (0, date_1.createDateSchema)(zodSchema);
|
|
77
|
+
}
|
|
78
|
+
if (zodSchema instanceof zod_1.ZodEffects &&
|
|
79
|
+
(zodSchema._def.effect.type === 'refinement' ||
|
|
80
|
+
zodSchema._def.effect.type === 'preprocess')) {
|
|
81
|
+
return (0, effects_1.createEffectsSchema)(zodSchema, components);
|
|
82
|
+
}
|
|
83
|
+
if (zodSchema instanceof zod_1.ZodNativeEnum) {
|
|
84
|
+
return (0, nativeEnum_1.createNativeEnumSchema)(zodSchema);
|
|
85
|
+
}
|
|
86
|
+
if (zodSchema instanceof zod_1.ZodIntersection) {
|
|
87
|
+
return (0, intersection_1.createIntersectionSchema)(zodSchema, components);
|
|
88
|
+
}
|
|
89
|
+
if (!zodSchema._def.openapi?.type) {
|
|
90
|
+
throw new Error(`Unknown schema ${zodSchema.toString()}. Please assign it a manual type`);
|
|
91
|
+
}
|
|
92
|
+
return {};
|
|
93
|
+
};
|
|
94
|
+
exports.createSchema = createSchema;
|
|
95
|
+
const createRegisteredSchema = (zodSchema, schemaRef, components) => {
|
|
96
|
+
const component = components.schemas[schemaRef];
|
|
97
|
+
if (component) {
|
|
98
|
+
if (component.zodSchema !== zodSchema) {
|
|
99
|
+
throw new Error(`schemaRef "${schemaRef}" is already registered`);
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
$ref: (0, components_1.createComponentSchemaRef)(schemaRef),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
// Optional Objects can return a reference object
|
|
106
|
+
const schemaOrRef = (0, metadata_1.createSchemaWithMetadata)(zodSchema, components);
|
|
107
|
+
if ('$ref' in schemaOrRef) {
|
|
108
|
+
throw new Error('Unexpected Error: received a reference object');
|
|
109
|
+
}
|
|
110
|
+
components.schemas[schemaRef] = {
|
|
111
|
+
schemaObject: schemaOrRef,
|
|
112
|
+
zodSchema,
|
|
113
|
+
};
|
|
114
|
+
return {
|
|
115
|
+
$ref: (0, components_1.createComponentSchemaRef)(schemaRef),
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
exports.createRegisteredSchema = createRegisteredSchema;
|
|
119
|
+
const createSchemaOrRef = (zodSchema, components) => {
|
|
120
|
+
const schemaRef = zodSchema._def.openapi?.ref;
|
|
121
|
+
if (schemaRef) {
|
|
122
|
+
return (0, exports.createRegisteredSchema)(zodSchema, schemaRef, components);
|
|
123
|
+
}
|
|
124
|
+
return (0, metadata_1.createSchemaWithMetadata)(zodSchema, components);
|
|
125
|
+
};
|
|
126
|
+
exports.createSchemaOrRef = createSchemaOrRef;
|
|
127
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/create/schema/index.ts"],"names":[],"mappings":";;;AACA,6BAsBa;AAEb,8CAA2E;AAE3E,mCAA4C;AAC5C,uCAAgD;AAChD,iCAA0C;AAC1C,uCAAgD;AAChD,6DAAsE;AACtE,uCAAgD;AAChD,iCAA0C;AAC1C,iDAA0D;AAC1D,uCAAgD;AAChD,yCAAsD;AACtD,6CAAsD;AACtD,iCAA0C;AAC1C,yCAAkD;AAClD,qCAA8C;AAC9C,qCAA8C;AAC9C,yCAAkD;AAClD,qCAA8C;AAC9C,qCAA8C;AAC9C,mCAA4C;AAC5C,mCAA4C;AAErC,MAAM,YAAY,GAAG,CAK1B,SAAsC,EACtC,UAA4B,EACgB,EAAE;IAC9C,IAAI,SAAS,YAAY,eAAS,EAAE;QAClC,OAAO,IAAA,2BAAkB,EAAC,SAAS,CAAC,CAAC;KACtC;IAED,IAAI,SAAS,YAAY,eAAS,EAAE;QAClC,OAAO,IAAA,2BAAkB,EAAC,SAAS,CAAC,CAAC;KACtC;IAED,IAAI,SAAS,YAAY,gBAAU,EAAE;QACnC,OAAO,IAAA,6BAAmB,EAAC,SAAS,CAAC,CAAC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GAAG,IAAA,mCAAwB,EAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACpE,IAAI,MAAM,IAAI,WAAW,EAAE;QACzB,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;KAClE;IAED,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG;QAC9B,YAAY,EAAE,WAAW;QACzB,SAAS;KACV,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,IAAA,qCAAwB,EAAC,SAAS,CAAC;KAC1C,CAAC;AACJ,CAAC,CAAC;AAjCW,QAAA,sBAAsB,0BAiCjC;AAEK,MAAM,iBAAiB,GAAG,CAK/B,SAAsC,EACtC,UAA4B,EACgB,EAAE;IAC9C,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC;IAC9C,IAAI,SAAS,EAAE;QACb,OAAO,IAAA,8BAAsB,EAAC,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;KACjE;IAED,OAAO,IAAA,mCAAwB,EAAC,SAAS,EAAE,UAAU,CAAC,CAAC;AACzD,CAAC,CAAC;AAdW,QAAA,iBAAiB,qBAc5B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createIntersectionSchema = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const createIntersectionSchema = (zodIntersection, components) => ({
|
|
6
|
+
allOf: [
|
|
7
|
+
(0, _1.createSchemaOrRef)(zodIntersection._def.left, components),
|
|
8
|
+
(0, _1.createSchemaOrRef)(zodIntersection._def.right, components),
|
|
9
|
+
],
|
|
10
|
+
});
|
|
11
|
+
exports.createIntersectionSchema = createIntersectionSchema;
|
|
12
|
+
//# sourceMappingURL=intersection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intersection.js","sourceRoot":"","sources":["../../../src/create/schema/intersection.ts"],"names":[],"mappings":";;;AAKA,wBAAsC;AAE/B,MAAM,wBAAwB,GAAG,CACtC,eAA0C,EAC1C,UAA4B,EACgB,EAAE,CAAC,CAAC;IAChD,KAAK,EAAE;QACL,IAAA,oBAAiB,EAAC,eAAe,CAAC,IAAI,CAAC,IAAe,EAAE,UAAU,CAAC;QACnE,IAAA,oBAAiB,EAAC,eAAe,CAAC,IAAI,CAAC,KAAgB,EAAE,UAAU,CAAC;KACrE;CACF,CAAC,CAAC;AARU,QAAA,wBAAwB,4BAQlC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLiteralSchema = void 0;
|
|
4
|
+
const createLiteralSchema = (zodLiteral) => ({
|
|
5
|
+
type: typeof zodLiteral.value,
|
|
6
|
+
enum: [zodLiteral._def.value],
|
|
7
|
+
});
|
|
8
|
+
exports.createLiteralSchema = createLiteralSchema;
|
|
9
|
+
//# sourceMappingURL=literal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"literal.js","sourceRoot":"","sources":["../../../src/create/schema/literal.ts"],"names":[],"mappings":";;;AAGO,MAAM,mBAAmB,GAAG,CACjC,UAA2B,EACP,EAAE,CAAC,CAAC;IACxB,IAAI,EAAE,OAAO,UAAU,CAAC,KAAmC;IAC3D,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC;CAC9B,CAAC,CAAC;AALU,QAAA,mBAAmB,uBAK7B"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.enhanceWithMetadata = exports.createSchemaWithMetadata = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const createSchemaWithMetadata = (zodSchema, components) => {
|
|
6
|
+
const { ref, param, header, ...additionalMetadata } = zodSchema._def.openapi ?? {};
|
|
7
|
+
const schemaOrRef = (0, _1.createSchema)(zodSchema, components);
|
|
8
|
+
const description = zodSchema.description;
|
|
9
|
+
return (0, exports.enhanceWithMetadata)(schemaOrRef, {
|
|
10
|
+
...(description && { description }),
|
|
11
|
+
...additionalMetadata,
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
exports.createSchemaWithMetadata = createSchemaWithMetadata;
|
|
15
|
+
const enhanceWithMetadata = (schemaOrRef, metadata) => {
|
|
16
|
+
if ('$ref' in schemaOrRef) {
|
|
17
|
+
if (Object.values(metadata).every((val) => val === undefined)) {
|
|
18
|
+
return schemaOrRef;
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
allOf: [schemaOrRef, metadata],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (schemaOrRef.allOf) {
|
|
25
|
+
const rest = schemaOrRef.allOf.slice(0, -1);
|
|
26
|
+
const end = schemaOrRef.allOf.at(-1);
|
|
27
|
+
return {
|
|
28
|
+
...schemaOrRef,
|
|
29
|
+
allOf: [...rest, ...(end ? [(0, exports.enhanceWithMetadata)(end, metadata)] : [])],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
...schemaOrRef,
|
|
34
|
+
...metadata,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
exports.enhanceWithMetadata = enhanceWithMetadata;
|
|
38
|
+
//# sourceMappingURL=metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../src/create/schema/metadata.ts"],"names":[],"mappings":";;;AAKA,wBAAiC;AAE1B,MAAM,wBAAwB,GAAG,CAKtC,SAAsC,EACtC,UAA4B,EACgB,EAAE;IAC9C,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,kBAAkB,EAAE,GACjD,SAAS,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;IAC/B,MAAM,WAAW,GAAG,IAAA,eAAY,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