@strapi/openapi 5.50.2 → 5.51.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/dist/post-processor/component-writer.d.ts.map +1 -1
- package/dist/post-processor/component-writer.js +5 -0
- package/dist/post-processor/component-writer.js.map +1 -1
- package/dist/post-processor/component-writer.mjs +6 -1
- package/dist/post-processor/component-writer.mjs.map +1 -1
- package/dist/utils/zod.d.ts +6 -0
- package/dist/utils/zod.d.ts.map +1 -1
- package/dist/utils/zod.js +12 -1
- package/dist/utils/zod.js.map +1 -1
- package/dist/utils/zod.mjs +12 -2
- package/dist/utils/zod.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-writer.d.ts","sourceRoot":"","sources":["../../src/post-processor/component-writer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,qBAAa,gBAAiB,YAAW,aAAa;IACpD,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"component-writer.d.ts","sourceRoot":"","sources":["../../src/post-processor/component-writer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,qBAAa,gBAAiB,YAAW,aAAa;IACpD,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;CAoB5C"}
|
|
@@ -29,6 +29,11 @@ class ComponentsWriter {
|
|
|
29
29
|
const { schemas } = z__namespace.toJSONSchema(z__namespace.globalRegistry, {
|
|
30
30
|
uri: zod.toComponentsPath
|
|
31
31
|
});
|
|
32
|
+
for (const schema of Object.values(schemas ?? {})){
|
|
33
|
+
if (schema && typeof schema === 'object') {
|
|
34
|
+
zod.stripJsonSchemaId(schema);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
32
37
|
const existingComponents = output.data.components ?? {};
|
|
33
38
|
output.data.components = {
|
|
34
39
|
...existingComponents,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-writer.js","sources":["../../src/post-processor/component-writer.ts"],"sourcesContent":["import { OpenAPIV3_1 } from 'openapi-types';\nimport * as z from 'zod/v4';\nimport type { DocumentContext } from '../types';\nimport { toComponentsPath } from '../utils/zod';\nimport type { PostProcessor } from './types';\n\nexport class ComponentsWriter implements PostProcessor {\n postProcess(context: DocumentContext): void {\n const { output } = context;\n\n const { schemas } = z.toJSONSchema(z.globalRegistry, {\n uri: toComponentsPath,\n }) as OpenAPIV3_1.ComponentsObject;\n\n const existingComponents = output.data.components ?? {};\n\n output.data.components = {\n ...existingComponents,\n schemas,\n };\n }\n}\n"],"names":["ComponentsWriter","postProcess","context","output","schemas","z","toJSONSchema","globalRegistry","uri","toComponentsPath","existingComponents","data","components"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAMO,MAAMA,gBAAAA,CAAAA;AACXC,IAAAA,WAAAA,CAAYC,OAAwB,EAAQ;QAC1C,MAAM,EAAEC,MAAM,EAAE,GAAGD,OAAAA;QAEnB,MAAM,EAAEE,OAAO,EAAE,GAAGC,aAAEC,YAAY,CAACD,YAAAA,CAAEE,cAAc,EAAE;YACnDC,GAAAA,EAAKC;AACP,SAAA,CAAA;AAEA,QAAA,MAAMC,
|
|
1
|
+
{"version":3,"file":"component-writer.js","sources":["../../src/post-processor/component-writer.ts"],"sourcesContent":["import { OpenAPIV3_1 } from 'openapi-types';\nimport * as z from 'zod/v4';\nimport type { DocumentContext } from '../types';\nimport { stripJsonSchemaId, toComponentsPath } from '../utils/zod';\nimport type { PostProcessor } from './types';\n\nexport class ComponentsWriter implements PostProcessor {\n postProcess(context: DocumentContext): void {\n const { output } = context;\n\n const { schemas } = z.toJSONSchema(z.globalRegistry, {\n uri: toComponentsPath,\n }) as OpenAPIV3_1.ComponentsObject;\n\n for (const schema of Object.values(schemas ?? {})) {\n if (schema && typeof schema === 'object') {\n stripJsonSchemaId(schema);\n }\n }\n\n const existingComponents = output.data.components ?? {};\n\n output.data.components = {\n ...existingComponents,\n schemas,\n };\n }\n}\n"],"names":["ComponentsWriter","postProcess","context","output","schemas","z","toJSONSchema","globalRegistry","uri","toComponentsPath","schema","Object","values","stripJsonSchemaId","existingComponents","data","components"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAMO,MAAMA,gBAAAA,CAAAA;AACXC,IAAAA,WAAAA,CAAYC,OAAwB,EAAQ;QAC1C,MAAM,EAAEC,MAAM,EAAE,GAAGD,OAAAA;QAEnB,MAAM,EAAEE,OAAO,EAAE,GAAGC,aAAEC,YAAY,CAACD,YAAAA,CAAEE,cAAc,EAAE;YACnDC,GAAAA,EAAKC;AACP,SAAA,CAAA;AAEA,QAAA,KAAK,MAAMC,MAAAA,IAAUC,MAAAA,CAAOC,MAAM,CAACR,OAAAA,IAAW,EAAC,CAAA,CAAI;YACjD,IAAIM,MAAAA,IAAU,OAAOA,MAAAA,KAAW,QAAA,EAAU;gBACxCG,qBAAAA,CAAkBH,MAAAA,CAAAA;AACpB,YAAA;AACF,QAAA;AAEA,QAAA,MAAMI,qBAAqBX,MAAAA,CAAOY,IAAI,CAACC,UAAU,IAAI,EAAC;QAEtDb,MAAAA,CAAOY,IAAI,CAACC,UAAU,GAAG;AACvB,YAAA,GAAGF,kBAAkB;AACrBV,YAAAA;AACF,SAAA;AACF,IAAA;AACF;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as z from 'zod/v4';
|
|
2
|
-
import { toComponentsPath } from '../utils/zod.mjs';
|
|
2
|
+
import { toComponentsPath, stripJsonSchemaId } from '../utils/zod.mjs';
|
|
3
3
|
|
|
4
4
|
class ComponentsWriter {
|
|
5
5
|
postProcess(context) {
|
|
@@ -7,6 +7,11 @@ class ComponentsWriter {
|
|
|
7
7
|
const { schemas } = z.toJSONSchema(z.globalRegistry, {
|
|
8
8
|
uri: toComponentsPath
|
|
9
9
|
});
|
|
10
|
+
for (const schema of Object.values(schemas ?? {})){
|
|
11
|
+
if (schema && typeof schema === 'object') {
|
|
12
|
+
stripJsonSchemaId(schema);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
10
15
|
const existingComponents = output.data.components ?? {};
|
|
11
16
|
output.data.components = {
|
|
12
17
|
...existingComponents,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-writer.mjs","sources":["../../src/post-processor/component-writer.ts"],"sourcesContent":["import { OpenAPIV3_1 } from 'openapi-types';\nimport * as z from 'zod/v4';\nimport type { DocumentContext } from '../types';\nimport { toComponentsPath } from '../utils/zod';\nimport type { PostProcessor } from './types';\n\nexport class ComponentsWriter implements PostProcessor {\n postProcess(context: DocumentContext): void {\n const { output } = context;\n\n const { schemas } = z.toJSONSchema(z.globalRegistry, {\n uri: toComponentsPath,\n }) as OpenAPIV3_1.ComponentsObject;\n\n const existingComponents = output.data.components ?? {};\n\n output.data.components = {\n ...existingComponents,\n schemas,\n };\n }\n}\n"],"names":["ComponentsWriter","postProcess","context","output","schemas","z","toJSONSchema","globalRegistry","uri","toComponentsPath","existingComponents","data","components"],"mappings":";;;AAMO,MAAMA,gBAAAA,CAAAA;AACXC,IAAAA,WAAAA,CAAYC,OAAwB,EAAQ;QAC1C,MAAM,EAAEC,MAAM,EAAE,GAAGD,OAAAA;QAEnB,MAAM,EAAEE,OAAO,EAAE,GAAGC,EAAEC,YAAY,CAACD,CAAAA,CAAEE,cAAc,EAAE;YACnDC,GAAAA,EAAKC;AACP,SAAA,CAAA;AAEA,QAAA,MAAMC,
|
|
1
|
+
{"version":3,"file":"component-writer.mjs","sources":["../../src/post-processor/component-writer.ts"],"sourcesContent":["import { OpenAPIV3_1 } from 'openapi-types';\nimport * as z from 'zod/v4';\nimport type { DocumentContext } from '../types';\nimport { stripJsonSchemaId, toComponentsPath } from '../utils/zod';\nimport type { PostProcessor } from './types';\n\nexport class ComponentsWriter implements PostProcessor {\n postProcess(context: DocumentContext): void {\n const { output } = context;\n\n const { schemas } = z.toJSONSchema(z.globalRegistry, {\n uri: toComponentsPath,\n }) as OpenAPIV3_1.ComponentsObject;\n\n for (const schema of Object.values(schemas ?? {})) {\n if (schema && typeof schema === 'object') {\n stripJsonSchemaId(schema);\n }\n }\n\n const existingComponents = output.data.components ?? {};\n\n output.data.components = {\n ...existingComponents,\n schemas,\n };\n }\n}\n"],"names":["ComponentsWriter","postProcess","context","output","schemas","z","toJSONSchema","globalRegistry","uri","toComponentsPath","schema","Object","values","stripJsonSchemaId","existingComponents","data","components"],"mappings":";;;AAMO,MAAMA,gBAAAA,CAAAA;AACXC,IAAAA,WAAAA,CAAYC,OAAwB,EAAQ;QAC1C,MAAM,EAAEC,MAAM,EAAE,GAAGD,OAAAA;QAEnB,MAAM,EAAEE,OAAO,EAAE,GAAGC,EAAEC,YAAY,CAACD,CAAAA,CAAEE,cAAc,EAAE;YACnDC,GAAAA,EAAKC;AACP,SAAA,CAAA;AAEA,QAAA,KAAK,MAAMC,MAAAA,IAAUC,MAAAA,CAAOC,MAAM,CAACR,OAAAA,IAAW,EAAC,CAAA,CAAI;YACjD,IAAIM,MAAAA,IAAU,OAAOA,MAAAA,KAAW,QAAA,EAAU;gBACxCG,iBAAAA,CAAkBH,MAAAA,CAAAA;AACpB,YAAA;AACF,QAAA;AAEA,QAAA,MAAMI,qBAAqBX,MAAAA,CAAOY,IAAI,CAACC,UAAU,IAAI,EAAC;QAEtDb,MAAAA,CAAOY,IAAI,CAACC,UAAU,GAAG;AACvB,YAAA,GAAGF,kBAAkB;AACrBV,YAAAA;AACF,SAAA;AACF,IAAA;AACF;;;;"}
|
package/dist/utils/zod.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import * as z from 'zod/v4';
|
|
2
2
|
import type { OpenAPIV3_1 } from 'openapi-types';
|
|
3
|
+
/**
|
|
4
|
+
* Zod ≥3.25.76 embeds `$id` in `toJSONSchema` output (set after `override`).
|
|
5
|
+
* Strip it so OpenAPI documents stay stable — inline schemas use random UUIDs
|
|
6
|
+
* as registry ids — and match the pre-3.25.76 shape.
|
|
7
|
+
*/
|
|
8
|
+
export declare const stripJsonSchemaId: <T extends object>(schema: T) => T;
|
|
3
9
|
/**
|
|
4
10
|
* Converts a Zod schema to an OpenAPI Schema Object.
|
|
5
11
|
*
|
package/dist/utils/zod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/utils/zod.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;
|
|
1
|
+
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/utils/zod.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,MAAM,EAAE,QAAQ,CAAC,KAAG,CAK/D,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,YAAY,GACvB,WAAW,CAAC,CAAC,OAAO,KACnB,WAAW,CAAC,YAAY,GAAG,WAAW,CAAC,eAsBzC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,IAAI,MAAM,WAAiC,CAAC"}
|
package/dist/utils/zod.js
CHANGED
|
@@ -23,6 +23,16 @@ function _interopNamespace(e) {
|
|
|
23
23
|
|
|
24
24
|
var z__namespace = /*#__PURE__*/_interopNamespace(z);
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Zod ≥3.25.76 embeds `$id` in `toJSONSchema` output (set after `override`).
|
|
28
|
+
* Strip it so OpenAPI documents stay stable — inline schemas use random UUIDs
|
|
29
|
+
* as registry ids — and match the pre-3.25.76 shape.
|
|
30
|
+
*/ const stripJsonSchemaId = (schema)=>{
|
|
31
|
+
if ('$id' in schema) {
|
|
32
|
+
delete schema.$id;
|
|
33
|
+
}
|
|
34
|
+
return schema;
|
|
35
|
+
};
|
|
26
36
|
/**
|
|
27
37
|
* Converts a Zod schema to an OpenAPI Schema Object.
|
|
28
38
|
*
|
|
@@ -70,7 +80,7 @@ var z__namespace = /*#__PURE__*/_interopNamespace(z);
|
|
|
70
80
|
uri: toComponentsPath
|
|
71
81
|
});
|
|
72
82
|
// TODO: make sure it's compliant
|
|
73
|
-
return schemas[id];
|
|
83
|
+
return stripJsonSchemaId(schemas[id]);
|
|
74
84
|
} catch (e) {
|
|
75
85
|
throw new Error("Couldn't transform the zod schema into an OpenAPI schema");
|
|
76
86
|
}
|
|
@@ -82,6 +92,7 @@ var z__namespace = /*#__PURE__*/_interopNamespace(z);
|
|
|
82
92
|
* @returns The constructed path string for the specified component schema.
|
|
83
93
|
*/ const toComponentsPath = (id)=>`#/components/schemas/${id}`;
|
|
84
94
|
|
|
95
|
+
exports.stripJsonSchemaId = stripJsonSchemaId;
|
|
85
96
|
exports.toComponentsPath = toComponentsPath;
|
|
86
97
|
exports.zodToOpenAPI = zodToOpenAPI;
|
|
87
98
|
//# sourceMappingURL=zod.js.map
|
package/dist/utils/zod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.js","sources":["../../src/utils/zod.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport * as z from 'zod/v4';\n\nimport type { OpenAPIV3_1 } from 'openapi-types';\n\n/**\n * Converts a Zod schema to an OpenAPI Schema Object.\n *\n * @description\n * Takes a Zod schema and converts it into an OpenAPI Schema Object (v3.1).\n * It uses a local registry to handle the conversion process and generates the appropriate\n * OpenAPI components.\n *\n * @param zodSchema - The Zod schema to convert to OpenAPI format. Can be any valid Zod schema.\n *\n * @returns An OpenAPI Schema Object representing the input Zod schema structure.\n * If the conversion cannot be completed, returns undefined.\n *\n * @example\n * ```typescript\n * import * as z from 'zod/v4';\n *\n * // Create a Zod schema\n * const userSchema = z.object({\n * id: z.number(),\n * name: z.string(),\n * email: z.string().email()\n * });\n *\n * // Convert to OpenAPI schema\n * const openAPISchema = zodToOpenAPI(userSchema);\n * ```\n */\
|
|
1
|
+
{"version":3,"file":"zod.js","sources":["../../src/utils/zod.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport * as z from 'zod/v4';\n\nimport type { OpenAPIV3_1 } from 'openapi-types';\n\n/**\n * Zod ≥3.25.76 embeds `$id` in `toJSONSchema` output (set after `override`).\n * Strip it so OpenAPI documents stay stable — inline schemas use random UUIDs\n * as registry ids — and match the pre-3.25.76 shape.\n */\nexport const stripJsonSchemaId = <T extends object>(schema: T): T => {\n if ('$id' in schema) {\n delete (schema as { $id?: string }).$id;\n }\n return schema;\n};\n\n/**\n * Converts a Zod schema to an OpenAPI Schema Object.\n *\n * @description\n * Takes a Zod schema and converts it into an OpenAPI Schema Object (v3.1).\n * It uses a local registry to handle the conversion process and generates the appropriate\n * OpenAPI components.\n *\n * @param zodSchema - The Zod schema to convert to OpenAPI format. Can be any valid Zod schema.\n *\n * @returns An OpenAPI Schema Object representing the input Zod schema structure.\n * If the conversion cannot be completed, returns undefined.\n *\n * @example\n * ```typescript\n * import * as z from 'zod/v4';\n *\n * // Create a Zod schema\n * const userSchema = z.object({\n * id: z.number(),\n * name: z.string(),\n * email: z.string().email()\n * });\n *\n * // Convert to OpenAPI schema\n * const openAPISchema = zodToOpenAPI(userSchema);\n * ```\n */\nexport const zodToOpenAPI = (\n zodSchema: z.ZodType\n): OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject => {\n try {\n const id = randomUUID();\n const registry = z.registry<{ id: string }>();\n\n // Add the schema to the local registry with a custom, unique ID\n registry.add(zodSchema, { id });\n\n // Copy the global registry definitions into the local registry to make sure references are resolved\n // This prevent \"__shared\" definitions from being created\n for (const [key, value] of z.globalRegistry._idmap) {\n registry.add(value, { id: key });\n }\n\n // Generate the schemas and only return the one we want, transform the URI path to be OpenAPI compliant\n const { schemas } = z.toJSONSchema(registry, { uri: toComponentsPath });\n\n // TODO: make sure it's compliant\n return stripJsonSchemaId(schemas[id] as OpenAPIV3_1.SchemaObject);\n } catch (e) {\n throw new Error(\"Couldn't transform the zod schema into an OpenAPI schema\");\n }\n};\n\n/**\n * Generates a path string for referencing a component schema by its identifier.\n *\n * @param id - The identifier of the component schema.\n * @returns The constructed path string for the specified component schema.\n */\nexport const toComponentsPath = (id: string) => `#/components/schemas/${id}`;\n"],"names":["stripJsonSchemaId","schema","$id","zodToOpenAPI","zodSchema","id","randomUUID","registry","z","add","key","value","globalRegistry","_idmap","schemas","toJSONSchema","uri","toComponentsPath","e","Error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAKA;;;;IAKO,MAAMA,iBAAAA,GAAoB,CAAmBC,MAAAA,GAAAA;AAClD,IAAA,IAAI,SAASA,MAAAA,EAAQ;QACnB,OAAQA,OAA4BC,GAAG;AACzC,IAAA;IACA,OAAOD,MAAAA;AACT;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;IA4BO,MAAME,YAAAA,GAAe,CAC1BC,SAAAA,GAAAA;IAEA,IAAI;AACF,QAAA,MAAMC,EAAAA,GAAKC,sBAAAA,EAAAA;QACX,MAAMC,QAAAA,GAAWC,aAAED,QAAQ,EAAA;;QAG3BA,QAAAA,CAASE,GAAG,CAACL,SAAAA,EAAW;AAAEC,YAAAA;AAAG,SAAA,CAAA;;;QAI7B,KAAK,MAAM,CAACK,GAAAA,EAAKC,KAAAA,CAAM,IAAIH,YAAAA,CAAEI,cAAc,CAACC,MAAM,CAAE;YAClDN,QAAAA,CAASE,GAAG,CAACE,KAAAA,EAAO;gBAAEN,EAAAA,EAAIK;AAAI,aAAA,CAAA;AAChC,QAAA;;AAGA,QAAA,MAAM,EAAEI,OAAO,EAAE,GAAGN,YAAAA,CAAEO,YAAY,CAACR,QAAAA,EAAU;YAAES,GAAAA,EAAKC;AAAiB,SAAA,CAAA;;QAGrE,OAAOjB,iBAAAA,CAAkBc,OAAO,CAACT,EAAAA,CAAG,CAAA;AACtC,IAAA,CAAA,CAAE,OAAOa,CAAAA,EAAG;AACV,QAAA,MAAM,IAAIC,KAAAA,CAAM,0DAAA,CAAA;AAClB,IAAA;AACF;AAEA;;;;;UAMaF,gBAAAA,GAAmB,CAACZ,KAAe,CAAC,qBAAqB,EAAEA,EAAAA,CAAAA;;;;;;"}
|
package/dist/utils/zod.mjs
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import * as z from 'zod/v4';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Zod ≥3.25.76 embeds `$id` in `toJSONSchema` output (set after `override`).
|
|
6
|
+
* Strip it so OpenAPI documents stay stable — inline schemas use random UUIDs
|
|
7
|
+
* as registry ids — and match the pre-3.25.76 shape.
|
|
8
|
+
*/ const stripJsonSchemaId = (schema)=>{
|
|
9
|
+
if ('$id' in schema) {
|
|
10
|
+
delete schema.$id;
|
|
11
|
+
}
|
|
12
|
+
return schema;
|
|
13
|
+
};
|
|
4
14
|
/**
|
|
5
15
|
* Converts a Zod schema to an OpenAPI Schema Object.
|
|
6
16
|
*
|
|
@@ -48,7 +58,7 @@ import * as z from 'zod/v4';
|
|
|
48
58
|
uri: toComponentsPath
|
|
49
59
|
});
|
|
50
60
|
// TODO: make sure it's compliant
|
|
51
|
-
return schemas[id];
|
|
61
|
+
return stripJsonSchemaId(schemas[id]);
|
|
52
62
|
} catch (e) {
|
|
53
63
|
throw new Error("Couldn't transform the zod schema into an OpenAPI schema");
|
|
54
64
|
}
|
|
@@ -60,5 +70,5 @@ import * as z from 'zod/v4';
|
|
|
60
70
|
* @returns The constructed path string for the specified component schema.
|
|
61
71
|
*/ const toComponentsPath = (id)=>`#/components/schemas/${id}`;
|
|
62
72
|
|
|
63
|
-
export { toComponentsPath, zodToOpenAPI };
|
|
73
|
+
export { stripJsonSchemaId, toComponentsPath, zodToOpenAPI };
|
|
64
74
|
//# sourceMappingURL=zod.mjs.map
|
package/dist/utils/zod.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.mjs","sources":["../../src/utils/zod.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport * as z from 'zod/v4';\n\nimport type { OpenAPIV3_1 } from 'openapi-types';\n\n/**\n * Converts a Zod schema to an OpenAPI Schema Object.\n *\n * @description\n * Takes a Zod schema and converts it into an OpenAPI Schema Object (v3.1).\n * It uses a local registry to handle the conversion process and generates the appropriate\n * OpenAPI components.\n *\n * @param zodSchema - The Zod schema to convert to OpenAPI format. Can be any valid Zod schema.\n *\n * @returns An OpenAPI Schema Object representing the input Zod schema structure.\n * If the conversion cannot be completed, returns undefined.\n *\n * @example\n * ```typescript\n * import * as z from 'zod/v4';\n *\n * // Create a Zod schema\n * const userSchema = z.object({\n * id: z.number(),\n * name: z.string(),\n * email: z.string().email()\n * });\n *\n * // Convert to OpenAPI schema\n * const openAPISchema = zodToOpenAPI(userSchema);\n * ```\n */\
|
|
1
|
+
{"version":3,"file":"zod.mjs","sources":["../../src/utils/zod.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport * as z from 'zod/v4';\n\nimport type { OpenAPIV3_1 } from 'openapi-types';\n\n/**\n * Zod ≥3.25.76 embeds `$id` in `toJSONSchema` output (set after `override`).\n * Strip it so OpenAPI documents stay stable — inline schemas use random UUIDs\n * as registry ids — and match the pre-3.25.76 shape.\n */\nexport const stripJsonSchemaId = <T extends object>(schema: T): T => {\n if ('$id' in schema) {\n delete (schema as { $id?: string }).$id;\n }\n return schema;\n};\n\n/**\n * Converts a Zod schema to an OpenAPI Schema Object.\n *\n * @description\n * Takes a Zod schema and converts it into an OpenAPI Schema Object (v3.1).\n * It uses a local registry to handle the conversion process and generates the appropriate\n * OpenAPI components.\n *\n * @param zodSchema - The Zod schema to convert to OpenAPI format. Can be any valid Zod schema.\n *\n * @returns An OpenAPI Schema Object representing the input Zod schema structure.\n * If the conversion cannot be completed, returns undefined.\n *\n * @example\n * ```typescript\n * import * as z from 'zod/v4';\n *\n * // Create a Zod schema\n * const userSchema = z.object({\n * id: z.number(),\n * name: z.string(),\n * email: z.string().email()\n * });\n *\n * // Convert to OpenAPI schema\n * const openAPISchema = zodToOpenAPI(userSchema);\n * ```\n */\nexport const zodToOpenAPI = (\n zodSchema: z.ZodType\n): OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject => {\n try {\n const id = randomUUID();\n const registry = z.registry<{ id: string }>();\n\n // Add the schema to the local registry with a custom, unique ID\n registry.add(zodSchema, { id });\n\n // Copy the global registry definitions into the local registry to make sure references are resolved\n // This prevent \"__shared\" definitions from being created\n for (const [key, value] of z.globalRegistry._idmap) {\n registry.add(value, { id: key });\n }\n\n // Generate the schemas and only return the one we want, transform the URI path to be OpenAPI compliant\n const { schemas } = z.toJSONSchema(registry, { uri: toComponentsPath });\n\n // TODO: make sure it's compliant\n return stripJsonSchemaId(schemas[id] as OpenAPIV3_1.SchemaObject);\n } catch (e) {\n throw new Error(\"Couldn't transform the zod schema into an OpenAPI schema\");\n }\n};\n\n/**\n * Generates a path string for referencing a component schema by its identifier.\n *\n * @param id - The identifier of the component schema.\n * @returns The constructed path string for the specified component schema.\n */\nexport const toComponentsPath = (id: string) => `#/components/schemas/${id}`;\n"],"names":["stripJsonSchemaId","schema","$id","zodToOpenAPI","zodSchema","id","randomUUID","registry","z","add","key","value","globalRegistry","_idmap","schemas","toJSONSchema","uri","toComponentsPath","e","Error"],"mappings":";;;AAKA;;;;IAKO,MAAMA,iBAAAA,GAAoB,CAAmBC,MAAAA,GAAAA;AAClD,IAAA,IAAI,SAASA,MAAAA,EAAQ;QACnB,OAAQA,OAA4BC,GAAG;AACzC,IAAA;IACA,OAAOD,MAAAA;AACT;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;IA4BO,MAAME,YAAAA,GAAe,CAC1BC,SAAAA,GAAAA;IAEA,IAAI;AACF,QAAA,MAAMC,EAAAA,GAAKC,UAAAA,EAAAA;QACX,MAAMC,QAAAA,GAAWC,EAAED,QAAQ,EAAA;;QAG3BA,QAAAA,CAASE,GAAG,CAACL,SAAAA,EAAW;AAAEC,YAAAA;AAAG,SAAA,CAAA;;;QAI7B,KAAK,MAAM,CAACK,GAAAA,EAAKC,KAAAA,CAAM,IAAIH,CAAAA,CAAEI,cAAc,CAACC,MAAM,CAAE;YAClDN,QAAAA,CAASE,GAAG,CAACE,KAAAA,EAAO;gBAAEN,EAAAA,EAAIK;AAAI,aAAA,CAAA;AAChC,QAAA;;AAGA,QAAA,MAAM,EAAEI,OAAO,EAAE,GAAGN,CAAAA,CAAEO,YAAY,CAACR,QAAAA,EAAU;YAAES,GAAAA,EAAKC;AAAiB,SAAA,CAAA;;QAGrE,OAAOjB,iBAAAA,CAAkBc,OAAO,CAACT,EAAAA,CAAG,CAAA;AACtC,IAAA,CAAA,CAAE,OAAOa,CAAAA,EAAG;AACV,QAAA,MAAM,IAAIC,KAAAA,CAAM,0DAAA,CAAA;AAClB,IAAA;AACF;AAEA;;;;;UAMaF,gBAAAA,GAAmB,CAACZ,KAAe,CAAC,qBAAqB,EAAEA,EAAAA,CAAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/openapi",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.51.0",
|
|
4
4
|
"description": "A tool set to help generate and validate API documentation for Strapi projects",
|
|
5
5
|
"homepage": "https://strapi.io",
|
|
6
6
|
"bugs": {
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"debug": "4.3.4",
|
|
62
62
|
"openapi-types": "12.1.3",
|
|
63
|
-
"zod": "3.25.
|
|
63
|
+
"zod": "3.25.76"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@strapi/types": "5.
|
|
66
|
+
"@strapi/types": "5.51.0",
|
|
67
67
|
"@types/debug": "^4",
|
|
68
68
|
"@types/jest": "29.5.2",
|
|
69
69
|
"@types/node": "20.19.41",
|