zod-openapi 2.6.3 → 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,10 +1,44 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createRecordSchema = void 0;
4
+ const openapi_1 = require("../../openapi");
4
5
  const _1 = require(".");
5
- const createRecordSchema = (zodRecord, state) => ({
6
- type: 'object',
7
- additionalProperties: (0, _1.createSchemaOrRef)(zodRecord.valueSchema, state, ['record value']),
8
- });
6
+ const createRecordSchema = (zodRecord, state) => {
7
+ const additionalProperties = (0, _1.createSchemaOrRef)(zodRecord.valueSchema, state, ['record value']);
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) {
18
+ return {
19
+ type: 'object',
20
+ properties: renderedKeySchema.enum.reduce((acc, key) => {
21
+ acc[key] = additionalProperties;
22
+ return acc;
23
+ }, {}),
24
+ additionalProperties: false,
25
+ };
26
+ }
27
+ if ((0, openapi_1.satisfiesVersion)(state.components.openapi, '3.1.0') &&
28
+ 'type' in renderedKeySchema &&
29
+ renderedKeySchema.type === 'string' &&
30
+ Object.keys(renderedKeySchema).length > 1) {
31
+ return {
32
+ type: 'object',
33
+ // @ts-expect-error FIXME: https://github.com/metadevpro/openapi3-ts/pull/120
34
+ propertyNames: keySchema,
35
+ additionalProperties,
36
+ };
37
+ }
38
+ return {
39
+ type: 'object',
40
+ additionalProperties,
41
+ };
42
+ };
9
43
  exports.createRecordSchema = createRecordSchema;
10
44
  //# sourceMappingURL=record.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"record.js","sourceRoot":"","sources":["../../../src/create/schema/record.ts"],"names":[],"mappings":";;;AAIA,wBAAwD;AAEjD,MAAM,kBAAkB,GAAG,CAChC,SAA8B,EAC9B,KAAkB,EACE,EAAE,CAAC,CAAC;IACxB,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,IAAA,oBAAiB,EACrC,SAAS,CAAC,WAAyB,EACnC,KAAK,EACL,CAAC,cAAc,CAAC,CACjB;CACF,CAAC,CAAC;AAVU,QAAA,kBAAkB,sBAU5B"}
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,6 +1,40 @@
1
+ import { satisfiesVersion } from '../../openapi';
1
2
  import { createSchemaOrRef } from '.';
2
- export const createRecordSchema = (zodRecord, state) => ({
3
- type: 'object',
4
- additionalProperties: createSchemaOrRef(zodRecord.valueSchema, state, ['record value']),
5
- });
3
+ export const createRecordSchema = (zodRecord, state) => {
4
+ const additionalProperties = createSchemaOrRef(zodRecord.valueSchema, state, ['record value']);
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) {
15
+ return {
16
+ type: 'object',
17
+ properties: renderedKeySchema.enum.reduce((acc, key) => {
18
+ acc[key] = additionalProperties;
19
+ return acc;
20
+ }, {}),
21
+ additionalProperties: false,
22
+ };
23
+ }
24
+ if (satisfiesVersion(state.components.openapi, '3.1.0') &&
25
+ 'type' in renderedKeySchema &&
26
+ renderedKeySchema.type === 'string' &&
27
+ Object.keys(renderedKeySchema).length > 1) {
28
+ return {
29
+ type: 'object',
30
+ // @ts-expect-error FIXME: https://github.com/metadevpro/openapi3-ts/pull/120
31
+ propertyNames: keySchema,
32
+ additionalProperties,
33
+ };
34
+ }
35
+ return {
36
+ type: 'object',
37
+ additionalProperties,
38
+ };
39
+ };
6
40
  //# sourceMappingURL=record.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"record.js","sourceRoot":"","sources":["../../../src/create/schema/record.ts"],"names":[],"mappings":"AAIA,OAAO,EAAoB,iBAAiB,EAAE,MAAM,GAAG,CAAC;AAExD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,SAA8B,EAC9B,KAAkB,EACE,EAAE,CAAC,CAAC;IACxB,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,iBAAiB,CACrC,SAAS,CAAC,WAAyB,EACnC,KAAK,EACL,CAAC,cAAc,CAAC,CACjB;CACF,CAAC,CAAC"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod-openapi",
3
- "version": "2.6.3",
3
+ "version": "2.7.1",
4
4
  "description": "Convert Zod Schemas to OpenAPI v3.x documentation",
5
5
  "keywords": [
6
6
  "typescript",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "dependencies": {},
45
45
  "devDependencies": {
46
- "@redocly/cli": "1.0.0-beta.129",
46
+ "@redocly/cli": "1.0.0-beta.131",
47
47
  "@types/node": "^20.3.0",
48
48
  "eslint-plugin-zod-openapi": "^0.1.0",
49
49
  "openapi3-ts": "4.1.2",