zod-openapi 2.7.0 → 2.7.1
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.
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createRecordSchema = void 0;
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
4
|
const openapi_1 = require("../../openapi");
|
|
6
5
|
const _1 = require(".");
|
|
7
6
|
const createRecordSchema = (zodRecord, state) => {
|
|
8
7
|
const additionalProperties = (0, _1.createSchemaOrRef)(zodRecord.valueSchema, state, ['record value']);
|
|
9
|
-
|
|
8
|
+
const keySchema = (0, _1.createSchemaOrRef)(zodRecord.keySchema, state, [
|
|
9
|
+
'record key',
|
|
10
|
+
]);
|
|
11
|
+
const maybeComponent = '$ref' in keySchema &&
|
|
12
|
+
state.components.schemas.get(zodRecord.keySchema);
|
|
13
|
+
const maybeSchema = maybeComponent &&
|
|
14
|
+
maybeComponent.type === 'complete' &&
|
|
15
|
+
maybeComponent.schemaObject;
|
|
16
|
+
const renderedKeySchema = maybeSchema || keySchema;
|
|
17
|
+
if ('enum' in renderedKeySchema && renderedKeySchema.enum) {
|
|
10
18
|
return {
|
|
11
19
|
type: 'object',
|
|
12
|
-
properties:
|
|
20
|
+
properties: renderedKeySchema.enum.reduce((acc, key) => {
|
|
13
21
|
acc[key] = additionalProperties;
|
|
14
22
|
return acc;
|
|
15
23
|
}, {}),
|
|
@@ -17,12 +25,13 @@ const createRecordSchema = (zodRecord, state) => {
|
|
|
17
25
|
};
|
|
18
26
|
}
|
|
19
27
|
if ((0, openapi_1.satisfiesVersion)(state.components.openapi, '3.1.0') &&
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
'type' in renderedKeySchema &&
|
|
29
|
+
renderedKeySchema.type === 'string' &&
|
|
30
|
+
Object.keys(renderedKeySchema).length > 1) {
|
|
22
31
|
return {
|
|
23
32
|
type: 'object',
|
|
24
33
|
// @ts-expect-error FIXME: https://github.com/metadevpro/openapi3-ts/pull/120
|
|
25
|
-
propertyNames:
|
|
34
|
+
propertyNames: keySchema,
|
|
26
35
|
additionalProperties,
|
|
27
36
|
};
|
|
28
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.js","sourceRoot":"","sources":["../../../src/create/schema/record.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"record.js","sourceRoot":"","sources":["../../../src/create/schema/record.ts"],"names":[],"mappings":";;;AAEA,2CAAiD;AAGjD,wBAAwD;AAEjD,MAAM,kBAAkB,GAAG,CAChC,SAA8B,EAC9B,KAAkB,EACE,EAAE;IACtB,MAAM,oBAAoB,GAAG,IAAA,oBAAiB,EAC5C,SAAS,CAAC,WAAyB,EACnC,KAAK,EACL,CAAC,cAAc,CAAC,CACjB,CAAC;IAEF,MAAM,SAAS,GAAG,IAAA,oBAAiB,EAAC,SAAS,CAAC,SAAoB,EAAE,KAAK,EAAE;QACzE,YAAY;KACb,CAAC,CAAC;IAEH,MAAM,cAAc,GAClB,MAAM,IAAI,SAAS;QACnB,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,SAAoB,CAAC,CAAC;IAC/D,MAAM,WAAW,GACf,cAAc;QACd,cAAc,CAAC,IAAI,KAAK,UAAU;QAClC,cAAc,CAAC,YAAY,CAAC;IAE9B,MAAM,iBAAiB,GAAG,WAAW,IAAI,SAAS,CAAC;IAEnD,IAAI,MAAM,IAAI,iBAAiB,IAAI,iBAAiB,CAAC,IAAI,EAAE;QACzD,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,UAAU,EAAG,iBAAiB,CAAC,IAAiB,CAAC,MAAM,CAErD,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;gBACb,GAAG,CAAC,GAAG,CAAC,GAAG,oBAAoB,CAAC;gBAChC,OAAO,GAAG,CAAC;YACb,CAAC,EAAE,EAAE,CAAC;YACN,oBAAoB,EAAE,KAAK;SAC5B,CAAC;KACH;IAED,IACE,IAAA,0BAAgB,EAAC,KAAK,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC;QACnD,MAAM,IAAI,iBAAiB;QAC3B,iBAAiB,CAAC,IAAI,KAAK,QAAQ;QACnC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,MAAM,GAAG,CAAC,EACzC;QACA,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,6EAA6E;YAC7E,aAAa,EAAE,SAAS;YACxB,oBAAoB;SACrB,CAAC;KACH;IAED,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,oBAAoB;KACrB,CAAC;AACJ,CAAC,CAAC;AAvDW,QAAA,kBAAkB,sBAuD7B"}
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import { ZodEnum, ZodString } from 'zod';
|
|
2
1
|
import { satisfiesVersion } from '../../openapi';
|
|
3
2
|
import { createSchemaOrRef } from '.';
|
|
4
3
|
export const createRecordSchema = (zodRecord, state) => {
|
|
5
4
|
const additionalProperties = createSchemaOrRef(zodRecord.valueSchema, state, ['record value']);
|
|
6
|
-
|
|
5
|
+
const keySchema = createSchemaOrRef(zodRecord.keySchema, state, [
|
|
6
|
+
'record key',
|
|
7
|
+
]);
|
|
8
|
+
const maybeComponent = '$ref' in keySchema &&
|
|
9
|
+
state.components.schemas.get(zodRecord.keySchema);
|
|
10
|
+
const maybeSchema = maybeComponent &&
|
|
11
|
+
maybeComponent.type === 'complete' &&
|
|
12
|
+
maybeComponent.schemaObject;
|
|
13
|
+
const renderedKeySchema = maybeSchema || keySchema;
|
|
14
|
+
if ('enum' in renderedKeySchema && renderedKeySchema.enum) {
|
|
7
15
|
return {
|
|
8
16
|
type: 'object',
|
|
9
|
-
properties:
|
|
17
|
+
properties: renderedKeySchema.enum.reduce((acc, key) => {
|
|
10
18
|
acc[key] = additionalProperties;
|
|
11
19
|
return acc;
|
|
12
20
|
}, {}),
|
|
@@ -14,12 +22,13 @@ export const createRecordSchema = (zodRecord, state) => {
|
|
|
14
22
|
};
|
|
15
23
|
}
|
|
16
24
|
if (satisfiesVersion(state.components.openapi, '3.1.0') &&
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
'type' in renderedKeySchema &&
|
|
26
|
+
renderedKeySchema.type === 'string' &&
|
|
27
|
+
Object.keys(renderedKeySchema).length > 1) {
|
|
19
28
|
return {
|
|
20
29
|
type: 'object',
|
|
21
30
|
// @ts-expect-error FIXME: https://github.com/metadevpro/openapi3-ts/pull/120
|
|
22
|
-
propertyNames:
|
|
31
|
+
propertyNames: keySchema,
|
|
23
32
|
additionalProperties,
|
|
24
33
|
};
|
|
25
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.js","sourceRoot":"","sources":["../../../src/create/schema/record.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"record.js","sourceRoot":"","sources":["../../../src/create/schema/record.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGjD,OAAO,EAAoB,iBAAiB,EAAE,MAAM,GAAG,CAAC;AAExD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,SAA8B,EAC9B,KAAkB,EACE,EAAE;IACtB,MAAM,oBAAoB,GAAG,iBAAiB,CAC5C,SAAS,CAAC,WAAyB,EACnC,KAAK,EACL,CAAC,cAAc,CAAC,CACjB,CAAC;IAEF,MAAM,SAAS,GAAG,iBAAiB,CAAC,SAAS,CAAC,SAAoB,EAAE,KAAK,EAAE;QACzE,YAAY;KACb,CAAC,CAAC;IAEH,MAAM,cAAc,GAClB,MAAM,IAAI,SAAS;QACnB,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,SAAoB,CAAC,CAAC;IAC/D,MAAM,WAAW,GACf,cAAc;QACd,cAAc,CAAC,IAAI,KAAK,UAAU;QAClC,cAAc,CAAC,YAAY,CAAC;IAE9B,MAAM,iBAAiB,GAAG,WAAW,IAAI,SAAS,CAAC;IAEnD,IAAI,MAAM,IAAI,iBAAiB,IAAI,iBAAiB,CAAC,IAAI,EAAE;QACzD,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,UAAU,EAAG,iBAAiB,CAAC,IAAiB,CAAC,MAAM,CAErD,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;gBACb,GAAG,CAAC,GAAG,CAAC,GAAG,oBAAoB,CAAC;gBAChC,OAAO,GAAG,CAAC;YACb,CAAC,EAAE,EAAE,CAAC;YACN,oBAAoB,EAAE,KAAK;SAC5B,CAAC;KACH;IAED,IACE,gBAAgB,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC;QACnD,MAAM,IAAI,iBAAiB;QAC3B,iBAAiB,CAAC,IAAI,KAAK,QAAQ;QACnC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,MAAM,GAAG,CAAC,EACzC;QACA,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,6EAA6E;YAC7E,aAAa,EAAE,SAAS;YACxB,oBAAoB;SACrB,CAAC;KACH;IAED,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,oBAAoB;KACrB,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ZodRecord } from 'zod';
|
|
2
2
|
import type { oas31 } from '../../openapi3-ts/dist';
|
|
3
3
|
import { type SchemaState } from '.';
|
|
4
4
|
export declare const createRecordSchema: (zodRecord: ZodRecord<any, any>, state: SchemaState) => oas31.SchemaObject;
|