@geekmidas/schema 10.0.0-alpha.12 → 10.0.0-alpha.13
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/conversion.cjs +105 -8
- package/dist/conversion.cjs.map +1 -0
- package/dist/conversion.d.cts +37 -2
- package/dist/conversion.d.cts.map +1 -0
- package/dist/conversion.d.mts +37 -2
- package/dist/conversion.d.mts.map +1 -0
- package/dist/conversion.mjs +98 -2
- package/dist/conversion.mjs.map +1 -0
- package/dist/index.cjs +4 -4
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -4
- package/dist/openapi.cjs +47 -3
- package/dist/openapi.cjs.map +1 -0
- package/dist/openapi.d.cts +24 -2
- package/dist/openapi.d.cts.map +1 -0
- package/dist/openapi.d.mts +24 -2
- package/dist/openapi.d.mts.map +1 -0
- package/dist/openapi.mjs +45 -2
- package/dist/openapi.mjs.map +1 -0
- package/dist/parser.cjs +3 -3
- package/dist/parser.cjs.map +1 -1
- package/dist/parser.d.cts +3 -8
- package/dist/parser.d.cts.map +1 -1
- package/dist/parser.d.mts +3 -8
- package/dist/parser.d.mts.map +1 -1
- package/dist/parser.mjs +2 -2
- package/dist/parser.mjs.map +1 -1
- package/dist/types.d.cts +22 -2
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +22 -2
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +1 -0
- package/package.json +9 -6
- package/dist/conversion-CIBtqJkS.mjs +0 -106
- package/dist/conversion-CIBtqJkS.mjs.map +0 -1
- package/dist/conversion-Cf9R-jGc.cjs +0 -148
- package/dist/conversion-Cf9R-jGc.cjs.map +0 -1
- package/dist/conversion-JY1Wixil.d.cts +0 -39
- package/dist/conversion-JY1Wixil.d.cts.map +0 -1
- package/dist/conversion-e4k9rTxy.d.mts +0 -39
- package/dist/conversion-e4k9rTxy.d.mts.map +0 -1
- package/dist/openapi-Aeb_1e9T.d.cts +0 -28
- package/dist/openapi-Aeb_1e9T.d.cts.map +0 -1
- package/dist/openapi-DH5yCqKh.mjs +0 -46
- package/dist/openapi-DH5yCqKh.mjs.map +0 -1
- package/dist/openapi-DVvLYx-8.cjs +0 -58
- package/dist/openapi-DVvLYx-8.cjs.map +0 -1
- package/dist/openapi-Dxc4FuMP.d.mts +0 -28
- package/dist/openapi-Dxc4FuMP.d.mts.map +0 -1
- package/dist/types-Bm3VhqVE.d.cts +0 -26
- package/dist/types-Bm3VhqVE.d.cts.map +0 -1
- package/dist/types-xm7EGhin.d.mts +0 -26
- package/dist/types-xm7EGhin.d.mts.map +0 -1
package/dist/conversion.cjs
CHANGED
|
@@ -1,9 +1,106 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/conversion.ts
|
|
3
|
+
let SchemaVendor = /* @__PURE__ */ function(SchemaVendor) {
|
|
4
|
+
SchemaVendor["zod"] = "zod";
|
|
5
|
+
SchemaVendor["valibot"] = "valibot";
|
|
6
|
+
return SchemaVendor;
|
|
7
|
+
}({});
|
|
8
|
+
function isSchemaVendor(vendor) {
|
|
9
|
+
if (!vendor) return false;
|
|
10
|
+
return Object.values(SchemaVendor).includes(vendor);
|
|
11
|
+
}
|
|
12
|
+
const StandardSchemaJsonSchema = {
|
|
13
|
+
zod: async (schema) => {
|
|
14
|
+
try {
|
|
15
|
+
const { z } = await import("zod/v4").catch(() => ({ z: {} }));
|
|
16
|
+
if ("toJSONSchema" in z && typeof z.toJSONSchema === "function") return z.toJSONSchema(schema);
|
|
17
|
+
const { zodToJsonSchema } = await import("zod-to-json-schema");
|
|
18
|
+
return zodToJsonSchema(schema, { removeAdditionalStrategy: "strict" });
|
|
19
|
+
} catch {
|
|
20
|
+
return { type: "object" };
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
valibot: async (schema) => {
|
|
24
|
+
const { toJsonSchema } = await import("@valibot/to-json-schema");
|
|
25
|
+
return toJsonSchema(schema);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
function extractAndConvertDefs(jsonSchema, componentCollector) {
|
|
29
|
+
if (!jsonSchema || typeof jsonSchema !== "object") return jsonSchema;
|
|
30
|
+
const processSchema = (schema) => {
|
|
31
|
+
if (!schema || typeof schema !== "object") return schema;
|
|
32
|
+
if (schema.$ref && typeof schema.$ref === "string") {
|
|
33
|
+
if (schema.$ref.startsWith("#/$defs/")) {
|
|
34
|
+
const refName = schema.$ref.replace("#/$defs/", "");
|
|
35
|
+
return componentCollector ? componentCollector.getReference(refName) : schema;
|
|
36
|
+
}
|
|
37
|
+
return schema;
|
|
38
|
+
}
|
|
39
|
+
if (Array.isArray(schema)) return schema.map(processSchema);
|
|
40
|
+
const processed = {};
|
|
41
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
42
|
+
if (key === "$defs") continue;
|
|
43
|
+
processed[key] = processSchema(value);
|
|
44
|
+
}
|
|
45
|
+
return processed;
|
|
46
|
+
};
|
|
47
|
+
if (jsonSchema.$defs && componentCollector) for (const [defName, defSchema] of Object.entries(jsonSchema.$defs)) {
|
|
48
|
+
const processedDefSchema = processSchema(defSchema);
|
|
49
|
+
componentCollector.addSchema(defName, processedDefSchema);
|
|
50
|
+
}
|
|
51
|
+
const { $defs, ...schemaWithoutDefs } = jsonSchema;
|
|
52
|
+
return processSchema(schemaWithoutDefs);
|
|
53
|
+
}
|
|
54
|
+
async function convertStandardSchemaToJsonSchema(schema, componentCollector) {
|
|
55
|
+
if (!schema) return;
|
|
56
|
+
const vendor = schema["~standard"]?.vendor;
|
|
57
|
+
if (!isSchemaVendor(vendor)) throw new Error(`Unsupported or missing vendor "${vendor}" for Standard Schema. Supported vendors are: ${Object.keys(StandardSchemaJsonSchema).join(", ")}`);
|
|
58
|
+
const toJSONSchema = StandardSchemaJsonSchema[vendor];
|
|
59
|
+
return extractAndConvertDefs(await toJSONSchema(schema), componentCollector);
|
|
60
|
+
}
|
|
61
|
+
async function getZodMetadata(schema) {
|
|
62
|
+
const { ZodObject } = await import("zod/v4");
|
|
63
|
+
if (schema instanceof ZodObject) return schema.meta();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Return JSON Schema for every schema registered in zod v4's global registry
|
|
67
|
+
* via `.meta({ id })`. Returns an empty object when zod v4 is unavailable or
|
|
68
|
+
* no schemas are registered.
|
|
69
|
+
*
|
|
70
|
+
* `unrepresentable: 'any'` keeps a single unrepresentable schema from
|
|
71
|
+
* collapsing the whole result.
|
|
72
|
+
*/
|
|
73
|
+
async function getRegisteredZodJsonSchemas() {
|
|
74
|
+
try {
|
|
75
|
+
const { z } = await import("zod/v4").catch(() => ({ z: null }));
|
|
76
|
+
if (!z?.toJSONSchema || !z.globalRegistry) return {};
|
|
77
|
+
return z.toJSONSchema(z.globalRegistry, { unrepresentable: "any" })?.schemas ?? {};
|
|
78
|
+
} catch {
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function getSchemaMetadata(schema) {
|
|
83
|
+
if (schema["~standard"]?.vendor === "zod") return getZodMetadata(schema);
|
|
84
|
+
}
|
|
85
|
+
async function convertSchemaWithComponents(schema, componentCollector) {
|
|
86
|
+
if (!schema) return;
|
|
87
|
+
const jsonSchema = await convertStandardSchemaToJsonSchema(schema, componentCollector);
|
|
88
|
+
if (!componentCollector) return jsonSchema;
|
|
89
|
+
const schemaId = (await getSchemaMetadata(schema))?.id || jsonSchema?.id;
|
|
90
|
+
if (schemaId) {
|
|
91
|
+
const { id, ...schemaWithoutId } = jsonSchema;
|
|
92
|
+
componentCollector.addSchema(schemaId, schemaWithoutId);
|
|
93
|
+
return componentCollector.getReference(schemaId);
|
|
94
|
+
}
|
|
95
|
+
return jsonSchema;
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
exports.SchemaVendor = SchemaVendor;
|
|
99
|
+
exports.StandardSchemaJsonSchema = StandardSchemaJsonSchema;
|
|
100
|
+
exports.convertSchemaWithComponents = convertSchemaWithComponents;
|
|
101
|
+
exports.convertStandardSchemaToJsonSchema = convertStandardSchemaToJsonSchema;
|
|
102
|
+
exports.getRegisteredZodJsonSchemas = getRegisteredZodJsonSchemas;
|
|
103
|
+
exports.getSchemaMetadata = getSchemaMetadata;
|
|
104
|
+
exports.getZodMetadata = getZodMetadata;
|
|
2
105
|
|
|
3
|
-
|
|
4
|
-
exports.StandardSchemaJsonSchema = require_conversion.StandardSchemaJsonSchema;
|
|
5
|
-
exports.convertSchemaWithComponents = require_conversion.convertSchemaWithComponents;
|
|
6
|
-
exports.convertStandardSchemaToJsonSchema = require_conversion.convertStandardSchemaToJsonSchema;
|
|
7
|
-
exports.getRegisteredZodJsonSchemas = require_conversion.getRegisteredZodJsonSchemas;
|
|
8
|
-
exports.getSchemaMetadata = require_conversion.getSchemaMetadata;
|
|
9
|
-
exports.getZodMetadata = require_conversion.getZodMetadata;
|
|
106
|
+
//# sourceMappingURL=conversion.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversion.cjs","names":[],"sources":["../src/conversion.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec';\n\nexport enum SchemaVendor {\n\tzod = 'zod',\n\tvalibot = 'valibot',\n}\n\nexport type VendorConvertor = (schema: any) => Promise<any>;\nexport type VendorConvertors = Record<SchemaVendor, VendorConvertor>;\n\nfunction isSchemaVendor(vendor?: string): vendor is SchemaVendor {\n\tif (!vendor) {\n\t\treturn false;\n\t}\n\n\treturn Object.values(SchemaVendor).includes(vendor as SchemaVendor);\n}\n\nexport const StandardSchemaJsonSchema: VendorConvertors = {\n\tzod: async (schema): Promise<any> => {\n\t\ttry {\n\t\t\tconst { z } = await import('zod/v4').catch(() => ({ z: {} }));\n\n\t\t\tif ('toJSONSchema' in z && typeof z.toJSONSchema === 'function') {\n\t\t\t\treturn z.toJSONSchema(schema);\n\t\t\t}\n\t\t\tconst { zodToJsonSchema } = await import('zod-to-json-schema');\n\n\t\t\tconst result = zodToJsonSchema(schema, {\n\t\t\t\tremoveAdditionalStrategy: 'strict',\n\t\t\t});\n\n\t\t\treturn result;\n\t\t} catch {\n\t\t\t// Fallback to basic conversion if zod-to-json-schema is not available\n\t\t\treturn { type: 'object' };\n\t\t}\n\t},\n\tvalibot: async (schema): Promise<any> => {\n\t\tconst { toJsonSchema } = await import('@valibot/to-json-schema');\n\t\treturn toJsonSchema(schema as any);\n\t},\n};\n\nfunction extractAndConvertDefs(\n\tjsonSchema: any,\n\tcomponentCollector?: {\n\t\taddSchema(id: string, schema: any): void;\n\t\tgetReference(id: string): { $ref: string };\n\t},\n): any {\n\tif (!jsonSchema || typeof jsonSchema !== 'object') {\n\t\treturn jsonSchema;\n\t}\n\n\t// Process the schema recursively to update references\n\tconst processSchema = (schema: any): any => {\n\t\tif (!schema || typeof schema !== 'object') {\n\t\t\treturn schema;\n\t\t}\n\n\t\t// Handle $ref\n\t\tif (schema.$ref && typeof schema.$ref === 'string') {\n\t\t\t// Convert #/$defs/X to #/components/schemas/X\n\t\t\tif (schema.$ref.startsWith('#/$defs/')) {\n\t\t\t\tconst refName = schema.$ref.replace('#/$defs/', '');\n\t\t\t\treturn componentCollector\n\t\t\t\t\t? componentCollector.getReference(refName)\n\t\t\t\t\t: schema;\n\t\t\t}\n\t\t\treturn schema;\n\t\t}\n\n\t\t// Handle arrays\n\t\tif (Array.isArray(schema)) {\n\t\t\treturn schema.map(processSchema);\n\t\t}\n\n\t\t// Process all properties recursively\n\t\tconst processed: any = {};\n\t\tfor (const [key, value] of Object.entries(schema)) {\n\t\t\tif (key === '$defs') {\n\t\t\t\t// Skip $defs as they've been extracted\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tprocessed[key] = processSchema(value);\n\t\t}\n\t\treturn processed;\n\t};\n\n\t// Extract $defs if present\n\tif (jsonSchema.$defs && componentCollector) {\n\t\tfor (const [defName, defSchema] of Object.entries(jsonSchema.$defs)) {\n\t\t\t// Process the definition recursively to handle nested $refs\n\t\t\tconst processedDefSchema = processSchema(defSchema);\n\t\t\t// Add each definition to the component collector\n\t\t\tcomponentCollector.addSchema(defName, processedDefSchema);\n\t\t}\n\t}\n\n\t// Process the schema and remove $defs\n\tconst { $defs, ...schemaWithoutDefs } = jsonSchema;\n\treturn processSchema(schemaWithoutDefs);\n}\n\nexport async function convertStandardSchemaToJsonSchema(\n\tschema?: StandardSchemaV1,\n\tcomponentCollector?: {\n\t\taddSchema(id: string, schema: any): void;\n\t\tgetReference(id: string): { $ref: string };\n\t},\n): Promise<any> {\n\tif (!schema) {\n\t\treturn undefined;\n\t}\n\n\tconst vendor = schema['~standard']?.vendor;\n\tif (!isSchemaVendor(vendor)) {\n\t\tthrow new Error(\n\t\t\t`Unsupported or missing vendor \"${vendor}\" for Standard Schema. Supported vendors are: ${Object.keys(StandardSchemaJsonSchema).join(', ')}`,\n\t\t);\n\t}\n\n\tconst toJSONSchema = StandardSchemaJsonSchema[vendor];\n\tconst jsonSchema = await toJSONSchema(schema);\n\n\t// Extract and convert $defs to components\n\treturn extractAndConvertDefs(jsonSchema, componentCollector);\n}\n\nexport async function getZodMetadata(\n\tschema: StandardSchemaV1,\n): Promise<SchemaMeta | undefined> {\n\tconst { ZodObject } = await import('zod/v4');\n\n\tif (schema instanceof ZodObject) {\n\t\treturn schema.meta();\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Return JSON Schema for every schema registered in zod v4's global registry\n * via `.meta({ id })`. Returns an empty object when zod v4 is unavailable or\n * no schemas are registered.\n *\n * `unrepresentable: 'any'` keeps a single unrepresentable schema from\n * collapsing the whole result.\n */\nexport async function getRegisteredZodJsonSchemas(): Promise<\n\tRecord<string, any>\n> {\n\ttry {\n\t\tconst { z } = await import('zod/v4').catch(() => ({ z: null as any }));\n\t\tif (!z?.toJSONSchema || !z.globalRegistry) {\n\t\t\treturn {};\n\t\t}\n\t\tconst result = z.toJSONSchema(z.globalRegistry, {\n\t\t\tunrepresentable: 'any',\n\t\t});\n\t\treturn (result?.schemas ?? {}) as Record<string, any>;\n\t} catch {\n\t\treturn {};\n\t}\n}\n\nexport async function getSchemaMetadata(\n\tschema: StandardSchemaV1,\n): Promise<SchemaMeta | undefined> {\n\tconst vendor = schema['~standard']?.vendor;\n\n\tif (vendor === 'zod') {\n\t\treturn getZodMetadata(schema);\n\t}\n\n\treturn undefined;\n}\n\ninterface SchemaMeta {\n\tid?: string;\n}\n\nexport async function convertSchemaWithComponents(\n\tschema: StandardSchemaV1 | undefined,\n\tcomponentCollector?: {\n\t\taddSchema(id: string, schema: any): void;\n\t\tgetReference(id: string): { $ref: string };\n\t},\n): Promise<any> {\n\tif (!schema) {\n\t\treturn undefined;\n\t}\n\n\t// Convert to JSON Schema with component collector to handle $defs\n\tconst jsonSchema = await convertStandardSchemaToJsonSchema(\n\t\tschema,\n\t\tcomponentCollector,\n\t);\n\n\tif (!componentCollector) {\n\t\treturn jsonSchema;\n\t}\n\n\t// Check if this schema has metadata with an ID\n\tconst metadata = await getSchemaMetadata(schema);\n\n\t// Also check if the JSON Schema itself has an id field (from Zod's meta)\n\tconst schemaId = metadata?.id || jsonSchema?.id;\n\n\tif (schemaId) {\n\t\t// Remove the id from the schema before adding to components\n\t\tconst { id, ...schemaWithoutId } = jsonSchema;\n\t\t// Add this schema to components and return a reference\n\t\tcomponentCollector.addSchema(schemaId, schemaWithoutId);\n\t\treturn componentCollector.getReference(schemaId);\n\t}\n\n\treturn jsonSchema;\n}\n"],"mappings":"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"}
|
package/dist/conversion.d.cts
CHANGED
|
@@ -1,2 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
//#region src/conversion.d.ts
|
|
3
|
+
export declare enum SchemaVendor {
|
|
4
|
+
zod = "zod",
|
|
5
|
+
valibot = "valibot"
|
|
6
|
+
}
|
|
7
|
+
export type VendorConvertor = (schema: any) => Promise<any>;
|
|
8
|
+
export type VendorConvertors = Record<SchemaVendor, VendorConvertor>;
|
|
9
|
+
export declare const StandardSchemaJsonSchema: VendorConvertors;
|
|
10
|
+
export declare function convertStandardSchemaToJsonSchema(schema?: StandardSchemaV1, componentCollector?: {
|
|
11
|
+
addSchema(id: string, schema: any): void;
|
|
12
|
+
getReference(id: string): {
|
|
13
|
+
$ref: string;
|
|
14
|
+
};
|
|
15
|
+
}): Promise<any>;
|
|
16
|
+
export declare function getZodMetadata(schema: StandardSchemaV1): Promise<SchemaMeta | undefined>;
|
|
17
|
+
/**
|
|
18
|
+
* Return JSON Schema for every schema registered in zod v4's global registry
|
|
19
|
+
* via `.meta({ id })`. Returns an empty object when zod v4 is unavailable or
|
|
20
|
+
* no schemas are registered.
|
|
21
|
+
*
|
|
22
|
+
* `unrepresentable: 'any'` keeps a single unrepresentable schema from
|
|
23
|
+
* collapsing the whole result.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getRegisteredZodJsonSchemas(): Promise<Record<string, any>>;
|
|
26
|
+
export declare function getSchemaMetadata(schema: StandardSchemaV1): Promise<SchemaMeta | undefined>;
|
|
27
|
+
interface SchemaMeta {
|
|
28
|
+
id?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function convertSchemaWithComponents(schema: StandardSchemaV1 | undefined, componentCollector?: {
|
|
31
|
+
addSchema(id: string, schema: any): void;
|
|
32
|
+
getReference(id: string): {
|
|
33
|
+
$ref: string;
|
|
34
|
+
};
|
|
35
|
+
}): Promise<any>;
|
|
36
|
+
//#endregion
|
|
37
|
+
//# sourceMappingURL=conversion.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversion.d.cts","names":[],"sources":["../src/conversion.ts"],"mappings":";;oBAEY;EACX;EACA;;YAGW,mBAAmB,gBAAgB;YACnC,mBAAmB,OAAO,cAAc;qBAUvC,0BAA0B;wBAuFjB,kCACrB,SAAS,kBACT;EACC,UAAU,YAAY;EACtB,aAAa;IAAe;;IAE3B;wBAmBmB,eACrB,QAAQ,mBACN,QAAQ;;;;;;;;;wBAkBW,+BAA+B,QACpD;wBAgBqB,kBACrB,QAAQ,mBACN,QAAQ;UAUD;EACT;;wBAGqB,4BACrB,QAAQ,8BACR;EACC,UAAU,YAAY;EACtB,aAAa;IAAe;;IAE3B"}
|
package/dist/conversion.d.mts
CHANGED
|
@@ -1,2 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
//#region src/conversion.d.ts
|
|
3
|
+
export declare enum SchemaVendor {
|
|
4
|
+
zod = "zod",
|
|
5
|
+
valibot = "valibot"
|
|
6
|
+
}
|
|
7
|
+
export type VendorConvertor = (schema: any) => Promise<any>;
|
|
8
|
+
export type VendorConvertors = Record<SchemaVendor, VendorConvertor>;
|
|
9
|
+
export declare const StandardSchemaJsonSchema: VendorConvertors;
|
|
10
|
+
export declare function convertStandardSchemaToJsonSchema(schema?: StandardSchemaV1, componentCollector?: {
|
|
11
|
+
addSchema(id: string, schema: any): void;
|
|
12
|
+
getReference(id: string): {
|
|
13
|
+
$ref: string;
|
|
14
|
+
};
|
|
15
|
+
}): Promise<any>;
|
|
16
|
+
export declare function getZodMetadata(schema: StandardSchemaV1): Promise<SchemaMeta | undefined>;
|
|
17
|
+
/**
|
|
18
|
+
* Return JSON Schema for every schema registered in zod v4's global registry
|
|
19
|
+
* via `.meta({ id })`. Returns an empty object when zod v4 is unavailable or
|
|
20
|
+
* no schemas are registered.
|
|
21
|
+
*
|
|
22
|
+
* `unrepresentable: 'any'` keeps a single unrepresentable schema from
|
|
23
|
+
* collapsing the whole result.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getRegisteredZodJsonSchemas(): Promise<Record<string, any>>;
|
|
26
|
+
export declare function getSchemaMetadata(schema: StandardSchemaV1): Promise<SchemaMeta | undefined>;
|
|
27
|
+
interface SchemaMeta {
|
|
28
|
+
id?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function convertSchemaWithComponents(schema: StandardSchemaV1 | undefined, componentCollector?: {
|
|
31
|
+
addSchema(id: string, schema: any): void;
|
|
32
|
+
getReference(id: string): {
|
|
33
|
+
$ref: string;
|
|
34
|
+
};
|
|
35
|
+
}): Promise<any>;
|
|
36
|
+
//#endregion
|
|
37
|
+
//# sourceMappingURL=conversion.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversion.d.mts","names":[],"sources":["../src/conversion.ts"],"mappings":";;oBAEY;EACX;EACA;;YAGW,mBAAmB,gBAAgB;YACnC,mBAAmB,OAAO,cAAc;qBAUvC,0BAA0B;wBAuFjB,kCACrB,SAAS,kBACT;EACC,UAAU,YAAY;EACtB,aAAa;IAAe;;IAE3B;wBAmBmB,eACrB,QAAQ,mBACN,QAAQ;;;;;;;;;wBAkBW,+BAA+B,QACpD;wBAgBqB,kBACrB,QAAQ,mBACN,QAAQ;UAUD;EACT;;wBAGqB,4BACrB,QAAQ,8BACR;EACC,UAAU,YAAY;EACtB,aAAa;IAAe;;IAE3B"}
|
package/dist/conversion.mjs
CHANGED
|
@@ -1,3 +1,99 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/conversion.ts
|
|
2
|
+
let SchemaVendor = /* @__PURE__ */ function(SchemaVendor) {
|
|
3
|
+
SchemaVendor["zod"] = "zod";
|
|
4
|
+
SchemaVendor["valibot"] = "valibot";
|
|
5
|
+
return SchemaVendor;
|
|
6
|
+
}({});
|
|
7
|
+
function isSchemaVendor(vendor) {
|
|
8
|
+
if (!vendor) return false;
|
|
9
|
+
return Object.values(SchemaVendor).includes(vendor);
|
|
10
|
+
}
|
|
11
|
+
const StandardSchemaJsonSchema = {
|
|
12
|
+
zod: async (schema) => {
|
|
13
|
+
try {
|
|
14
|
+
const { z } = await import("zod/v4").catch(() => ({ z: {} }));
|
|
15
|
+
if ("toJSONSchema" in z && typeof z.toJSONSchema === "function") return z.toJSONSchema(schema);
|
|
16
|
+
const { zodToJsonSchema } = await import("zod-to-json-schema");
|
|
17
|
+
return zodToJsonSchema(schema, { removeAdditionalStrategy: "strict" });
|
|
18
|
+
} catch {
|
|
19
|
+
return { type: "object" };
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
valibot: async (schema) => {
|
|
23
|
+
const { toJsonSchema } = await import("@valibot/to-json-schema");
|
|
24
|
+
return toJsonSchema(schema);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function extractAndConvertDefs(jsonSchema, componentCollector) {
|
|
28
|
+
if (!jsonSchema || typeof jsonSchema !== "object") return jsonSchema;
|
|
29
|
+
const processSchema = (schema) => {
|
|
30
|
+
if (!schema || typeof schema !== "object") return schema;
|
|
31
|
+
if (schema.$ref && typeof schema.$ref === "string") {
|
|
32
|
+
if (schema.$ref.startsWith("#/$defs/")) {
|
|
33
|
+
const refName = schema.$ref.replace("#/$defs/", "");
|
|
34
|
+
return componentCollector ? componentCollector.getReference(refName) : schema;
|
|
35
|
+
}
|
|
36
|
+
return schema;
|
|
37
|
+
}
|
|
38
|
+
if (Array.isArray(schema)) return schema.map(processSchema);
|
|
39
|
+
const processed = {};
|
|
40
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
41
|
+
if (key === "$defs") continue;
|
|
42
|
+
processed[key] = processSchema(value);
|
|
43
|
+
}
|
|
44
|
+
return processed;
|
|
45
|
+
};
|
|
46
|
+
if (jsonSchema.$defs && componentCollector) for (const [defName, defSchema] of Object.entries(jsonSchema.$defs)) {
|
|
47
|
+
const processedDefSchema = processSchema(defSchema);
|
|
48
|
+
componentCollector.addSchema(defName, processedDefSchema);
|
|
49
|
+
}
|
|
50
|
+
const { $defs, ...schemaWithoutDefs } = jsonSchema;
|
|
51
|
+
return processSchema(schemaWithoutDefs);
|
|
52
|
+
}
|
|
53
|
+
async function convertStandardSchemaToJsonSchema(schema, componentCollector) {
|
|
54
|
+
if (!schema) return;
|
|
55
|
+
const vendor = schema["~standard"]?.vendor;
|
|
56
|
+
if (!isSchemaVendor(vendor)) throw new Error(`Unsupported or missing vendor "${vendor}" for Standard Schema. Supported vendors are: ${Object.keys(StandardSchemaJsonSchema).join(", ")}`);
|
|
57
|
+
const toJSONSchema = StandardSchemaJsonSchema[vendor];
|
|
58
|
+
return extractAndConvertDefs(await toJSONSchema(schema), componentCollector);
|
|
59
|
+
}
|
|
60
|
+
async function getZodMetadata(schema) {
|
|
61
|
+
const { ZodObject } = await import("zod/v4");
|
|
62
|
+
if (schema instanceof ZodObject) return schema.meta();
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Return JSON Schema for every schema registered in zod v4's global registry
|
|
66
|
+
* via `.meta({ id })`. Returns an empty object when zod v4 is unavailable or
|
|
67
|
+
* no schemas are registered.
|
|
68
|
+
*
|
|
69
|
+
* `unrepresentable: 'any'` keeps a single unrepresentable schema from
|
|
70
|
+
* collapsing the whole result.
|
|
71
|
+
*/
|
|
72
|
+
async function getRegisteredZodJsonSchemas() {
|
|
73
|
+
try {
|
|
74
|
+
const { z } = await import("zod/v4").catch(() => ({ z: null }));
|
|
75
|
+
if (!z?.toJSONSchema || !z.globalRegistry) return {};
|
|
76
|
+
return z.toJSONSchema(z.globalRegistry, { unrepresentable: "any" })?.schemas ?? {};
|
|
77
|
+
} catch {
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async function getSchemaMetadata(schema) {
|
|
82
|
+
if (schema["~standard"]?.vendor === "zod") return getZodMetadata(schema);
|
|
83
|
+
}
|
|
84
|
+
async function convertSchemaWithComponents(schema, componentCollector) {
|
|
85
|
+
if (!schema) return;
|
|
86
|
+
const jsonSchema = await convertStandardSchemaToJsonSchema(schema, componentCollector);
|
|
87
|
+
if (!componentCollector) return jsonSchema;
|
|
88
|
+
const schemaId = (await getSchemaMetadata(schema))?.id || jsonSchema?.id;
|
|
89
|
+
if (schemaId) {
|
|
90
|
+
const { id, ...schemaWithoutId } = jsonSchema;
|
|
91
|
+
componentCollector.addSchema(schemaId, schemaWithoutId);
|
|
92
|
+
return componentCollector.getReference(schemaId);
|
|
93
|
+
}
|
|
94
|
+
return jsonSchema;
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
export { SchemaVendor, StandardSchemaJsonSchema, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, getRegisteredZodJsonSchemas, getSchemaMetadata, getZodMetadata };
|
|
2
98
|
|
|
3
|
-
|
|
99
|
+
//# sourceMappingURL=conversion.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversion.mjs","names":[],"sources":["../src/conversion.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec';\n\nexport enum SchemaVendor {\n\tzod = 'zod',\n\tvalibot = 'valibot',\n}\n\nexport type VendorConvertor = (schema: any) => Promise<any>;\nexport type VendorConvertors = Record<SchemaVendor, VendorConvertor>;\n\nfunction isSchemaVendor(vendor?: string): vendor is SchemaVendor {\n\tif (!vendor) {\n\t\treturn false;\n\t}\n\n\treturn Object.values(SchemaVendor).includes(vendor as SchemaVendor);\n}\n\nexport const StandardSchemaJsonSchema: VendorConvertors = {\n\tzod: async (schema): Promise<any> => {\n\t\ttry {\n\t\t\tconst { z } = await import('zod/v4').catch(() => ({ z: {} }));\n\n\t\t\tif ('toJSONSchema' in z && typeof z.toJSONSchema === 'function') {\n\t\t\t\treturn z.toJSONSchema(schema);\n\t\t\t}\n\t\t\tconst { zodToJsonSchema } = await import('zod-to-json-schema');\n\n\t\t\tconst result = zodToJsonSchema(schema, {\n\t\t\t\tremoveAdditionalStrategy: 'strict',\n\t\t\t});\n\n\t\t\treturn result;\n\t\t} catch {\n\t\t\t// Fallback to basic conversion if zod-to-json-schema is not available\n\t\t\treturn { type: 'object' };\n\t\t}\n\t},\n\tvalibot: async (schema): Promise<any> => {\n\t\tconst { toJsonSchema } = await import('@valibot/to-json-schema');\n\t\treturn toJsonSchema(schema as any);\n\t},\n};\n\nfunction extractAndConvertDefs(\n\tjsonSchema: any,\n\tcomponentCollector?: {\n\t\taddSchema(id: string, schema: any): void;\n\t\tgetReference(id: string): { $ref: string };\n\t},\n): any {\n\tif (!jsonSchema || typeof jsonSchema !== 'object') {\n\t\treturn jsonSchema;\n\t}\n\n\t// Process the schema recursively to update references\n\tconst processSchema = (schema: any): any => {\n\t\tif (!schema || typeof schema !== 'object') {\n\t\t\treturn schema;\n\t\t}\n\n\t\t// Handle $ref\n\t\tif (schema.$ref && typeof schema.$ref === 'string') {\n\t\t\t// Convert #/$defs/X to #/components/schemas/X\n\t\t\tif (schema.$ref.startsWith('#/$defs/')) {\n\t\t\t\tconst refName = schema.$ref.replace('#/$defs/', '');\n\t\t\t\treturn componentCollector\n\t\t\t\t\t? componentCollector.getReference(refName)\n\t\t\t\t\t: schema;\n\t\t\t}\n\t\t\treturn schema;\n\t\t}\n\n\t\t// Handle arrays\n\t\tif (Array.isArray(schema)) {\n\t\t\treturn schema.map(processSchema);\n\t\t}\n\n\t\t// Process all properties recursively\n\t\tconst processed: any = {};\n\t\tfor (const [key, value] of Object.entries(schema)) {\n\t\t\tif (key === '$defs') {\n\t\t\t\t// Skip $defs as they've been extracted\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tprocessed[key] = processSchema(value);\n\t\t}\n\t\treturn processed;\n\t};\n\n\t// Extract $defs if present\n\tif (jsonSchema.$defs && componentCollector) {\n\t\tfor (const [defName, defSchema] of Object.entries(jsonSchema.$defs)) {\n\t\t\t// Process the definition recursively to handle nested $refs\n\t\t\tconst processedDefSchema = processSchema(defSchema);\n\t\t\t// Add each definition to the component collector\n\t\t\tcomponentCollector.addSchema(defName, processedDefSchema);\n\t\t}\n\t}\n\n\t// Process the schema and remove $defs\n\tconst { $defs, ...schemaWithoutDefs } = jsonSchema;\n\treturn processSchema(schemaWithoutDefs);\n}\n\nexport async function convertStandardSchemaToJsonSchema(\n\tschema?: StandardSchemaV1,\n\tcomponentCollector?: {\n\t\taddSchema(id: string, schema: any): void;\n\t\tgetReference(id: string): { $ref: string };\n\t},\n): Promise<any> {\n\tif (!schema) {\n\t\treturn undefined;\n\t}\n\n\tconst vendor = schema['~standard']?.vendor;\n\tif (!isSchemaVendor(vendor)) {\n\t\tthrow new Error(\n\t\t\t`Unsupported or missing vendor \"${vendor}\" for Standard Schema. Supported vendors are: ${Object.keys(StandardSchemaJsonSchema).join(', ')}`,\n\t\t);\n\t}\n\n\tconst toJSONSchema = StandardSchemaJsonSchema[vendor];\n\tconst jsonSchema = await toJSONSchema(schema);\n\n\t// Extract and convert $defs to components\n\treturn extractAndConvertDefs(jsonSchema, componentCollector);\n}\n\nexport async function getZodMetadata(\n\tschema: StandardSchemaV1,\n): Promise<SchemaMeta | undefined> {\n\tconst { ZodObject } = await import('zod/v4');\n\n\tif (schema instanceof ZodObject) {\n\t\treturn schema.meta();\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Return JSON Schema for every schema registered in zod v4's global registry\n * via `.meta({ id })`. Returns an empty object when zod v4 is unavailable or\n * no schemas are registered.\n *\n * `unrepresentable: 'any'` keeps a single unrepresentable schema from\n * collapsing the whole result.\n */\nexport async function getRegisteredZodJsonSchemas(): Promise<\n\tRecord<string, any>\n> {\n\ttry {\n\t\tconst { z } = await import('zod/v4').catch(() => ({ z: null as any }));\n\t\tif (!z?.toJSONSchema || !z.globalRegistry) {\n\t\t\treturn {};\n\t\t}\n\t\tconst result = z.toJSONSchema(z.globalRegistry, {\n\t\t\tunrepresentable: 'any',\n\t\t});\n\t\treturn (result?.schemas ?? {}) as Record<string, any>;\n\t} catch {\n\t\treturn {};\n\t}\n}\n\nexport async function getSchemaMetadata(\n\tschema: StandardSchemaV1,\n): Promise<SchemaMeta | undefined> {\n\tconst vendor = schema['~standard']?.vendor;\n\n\tif (vendor === 'zod') {\n\t\treturn getZodMetadata(schema);\n\t}\n\n\treturn undefined;\n}\n\ninterface SchemaMeta {\n\tid?: string;\n}\n\nexport async function convertSchemaWithComponents(\n\tschema: StandardSchemaV1 | undefined,\n\tcomponentCollector?: {\n\t\taddSchema(id: string, schema: any): void;\n\t\tgetReference(id: string): { $ref: string };\n\t},\n): Promise<any> {\n\tif (!schema) {\n\t\treturn undefined;\n\t}\n\n\t// Convert to JSON Schema with component collector to handle $defs\n\tconst jsonSchema = await convertStandardSchemaToJsonSchema(\n\t\tschema,\n\t\tcomponentCollector,\n\t);\n\n\tif (!componentCollector) {\n\t\treturn jsonSchema;\n\t}\n\n\t// Check if this schema has metadata with an ID\n\tconst metadata = await getSchemaMetadata(schema);\n\n\t// Also check if the JSON Schema itself has an id field (from Zod's meta)\n\tconst schemaId = metadata?.id || jsonSchema?.id;\n\n\tif (schemaId) {\n\t\t// Remove the id from the schema before adding to components\n\t\tconst { id, ...schemaWithoutId } = jsonSchema;\n\t\t// Add this schema to components and return a reference\n\t\tcomponentCollector.addSchema(schemaId, schemaWithoutId);\n\t\treturn componentCollector.getReference(schemaId);\n\t}\n\n\treturn jsonSchema;\n}\n"],"mappings":"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"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_conversion = require("./conversion.cjs");
|
|
3
|
+
const require_openapi = require("./openapi.cjs");
|
|
4
4
|
exports.buildOpenApiSchema = require_openapi.buildOpenApiSchema;
|
|
5
5
|
exports.convertSchemaWithComponents = require_conversion.convertSchemaWithComponents;
|
|
6
6
|
exports.convertStandardSchemaToJsonSchema = require_conversion.convertStandardSchemaToJsonSchema;
|
|
7
|
-
exports.createComponentCollector = require_openapi.createComponentCollector;
|
|
7
|
+
exports.createComponentCollector = require_openapi.createComponentCollector;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { convertSchemaWithComponents, convertStandardSchemaToJsonSchema } from "./conversion
|
|
2
|
-
import { ComponentCollector, OpenApiSchemaOptions, buildOpenApiSchema, createComponentCollector } from "./openapi
|
|
3
|
-
import { ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema, InferStandardSchemaInput } from "./types
|
|
4
|
-
export { ComponentCollector, ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema, InferStandardSchemaInput, OpenApiSchemaOptions, buildOpenApiSchema, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, createComponentCollector };
|
|
1
|
+
import { convertSchemaWithComponents, convertStandardSchemaToJsonSchema } from "./conversion.cjs";
|
|
2
|
+
import { ComponentCollector, OpenApiSchemaOptions, buildOpenApiSchema, createComponentCollector } from "./openapi.cjs";
|
|
3
|
+
import { ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema, InferStandardSchemaInput } from "./types.cjs";
|
|
4
|
+
export { type ComponentCollector, type ComposableStandardSchema, type InferComposableStandardSchema, type InferStandardSchema, type InferStandardSchemaInput, type OpenApiSchemaOptions, buildOpenApiSchema, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, createComponentCollector };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { convertSchemaWithComponents, convertStandardSchemaToJsonSchema } from "./conversion
|
|
2
|
-
import { ComponentCollector, OpenApiSchemaOptions, buildOpenApiSchema, createComponentCollector } from "./openapi
|
|
3
|
-
import { ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema, InferStandardSchemaInput } from "./types
|
|
4
|
-
export { ComponentCollector, ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema, InferStandardSchemaInput, OpenApiSchemaOptions, buildOpenApiSchema, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, createComponentCollector };
|
|
1
|
+
import { convertSchemaWithComponents, convertStandardSchemaToJsonSchema } from "./conversion.mjs";
|
|
2
|
+
import { ComponentCollector, OpenApiSchemaOptions, buildOpenApiSchema, createComponentCollector } from "./openapi.mjs";
|
|
3
|
+
import { ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema, InferStandardSchemaInput } from "./types.mjs";
|
|
4
|
+
export { type ComponentCollector, type ComposableStandardSchema, type InferComposableStandardSchema, type InferStandardSchema, type InferStandardSchemaInput, type OpenApiSchemaOptions, buildOpenApiSchema, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, createComponentCollector };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { convertSchemaWithComponents, convertStandardSchemaToJsonSchema } from "./conversion
|
|
2
|
-
import { buildOpenApiSchema, createComponentCollector } from "./openapi
|
|
3
|
-
|
|
4
|
-
export { buildOpenApiSchema, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, createComponentCollector };
|
|
1
|
+
import { convertSchemaWithComponents, convertStandardSchemaToJsonSchema } from "./conversion.mjs";
|
|
2
|
+
import { buildOpenApiSchema, createComponentCollector } from "./openapi.mjs";
|
|
3
|
+
export { buildOpenApiSchema, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, createComponentCollector };
|
package/dist/openapi.cjs
CHANGED
|
@@ -1,4 +1,48 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/openapi.ts
|
|
3
|
+
function createComponentCollector() {
|
|
4
|
+
const schemas = {};
|
|
5
|
+
return {
|
|
6
|
+
schemas,
|
|
7
|
+
addSchema(id, schema) {
|
|
8
|
+
schemas[id] = schema;
|
|
9
|
+
},
|
|
10
|
+
getReference(id) {
|
|
11
|
+
return { $ref: `#/components/schemas/${id}` };
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Builds OpenAPI 3.1 schema from an array of endpoints.
|
|
17
|
+
*
|
|
18
|
+
* Note: This function requires endpoints with toOpenApi3Route method.
|
|
19
|
+
* The actual implementation is in @geekmidas/constructs to avoid circular dependencies.
|
|
20
|
+
*/
|
|
21
|
+
async function buildOpenApiSchema(endpoints, options = {}) {
|
|
22
|
+
const { title = "API", version = "1.0.0", description } = options;
|
|
23
|
+
const paths = {};
|
|
24
|
+
const componentCollector = createComponentCollector();
|
|
25
|
+
for (const endpoint of endpoints) {
|
|
26
|
+
const route = await endpoint.toOpenApi3Route(componentCollector);
|
|
27
|
+
for (const [path, methods] of Object.entries(route)) {
|
|
28
|
+
if (!paths[path]) paths[path] = {};
|
|
29
|
+
Object.assign(paths[path], methods);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const doc = {
|
|
33
|
+
openapi: "3.0.0",
|
|
34
|
+
info: {
|
|
35
|
+
title,
|
|
36
|
+
version,
|
|
37
|
+
...description && { description }
|
|
38
|
+
},
|
|
39
|
+
paths
|
|
40
|
+
};
|
|
41
|
+
if (Object.keys(componentCollector.schemas).length > 0) doc.components = { schemas: componentCollector.schemas };
|
|
42
|
+
return doc;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
exports.buildOpenApiSchema = buildOpenApiSchema;
|
|
46
|
+
exports.createComponentCollector = createComponentCollector;
|
|
2
47
|
|
|
3
|
-
|
|
4
|
-
exports.createComponentCollector = require_openapi.createComponentCollector;
|
|
48
|
+
//# sourceMappingURL=openapi.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi.cjs","names":[],"sources":["../src/openapi.ts"],"sourcesContent":["import type { OpenAPIV3_1 } from 'openapi-types';\n\nexport interface OpenApiSchemaOptions {\n\ttitle?: string;\n\tversion?: string;\n\tdescription?: string;\n}\n\nexport interface ComponentCollector {\n\tschemas: Record<string, OpenAPIV3_1.SchemaObject>;\n\taddSchema(id: string, schema: OpenAPIV3_1.SchemaObject): void;\n\tgetReference(id: string): OpenAPIV3_1.ReferenceObject;\n}\n\nexport function createComponentCollector(): ComponentCollector {\n\tconst schemas: Record<string, OpenAPIV3_1.SchemaObject> = {};\n\n\treturn {\n\t\tschemas,\n\t\taddSchema(id: string, schema: OpenAPIV3_1.SchemaObject) {\n\t\t\tschemas[id] = schema;\n\t\t},\n\t\tgetReference(id: string): OpenAPIV3_1.ReferenceObject {\n\t\t\treturn { $ref: `#/components/schemas/${id}` };\n\t\t},\n\t};\n}\n\n/**\n * Builds OpenAPI 3.1 schema from an array of endpoints.\n *\n * Note: This function requires endpoints with toOpenApi3Route method.\n * The actual implementation is in @geekmidas/constructs to avoid circular dependencies.\n */\nexport async function buildOpenApiSchema(\n\tendpoints: Array<{\n\t\ttoOpenApi3Route(collector?: ComponentCollector): Promise<any>;\n\t}>,\n\toptions: OpenApiSchemaOptions = {},\n): Promise<OpenAPIV3_1.Document> {\n\tconst { title = 'API', version = '1.0.0', description } = options;\n\tconst paths: OpenAPIV3_1.PathsObject = {};\n\tconst componentCollector = createComponentCollector();\n\n\tfor (const endpoint of endpoints) {\n\t\tconst route = await endpoint.toOpenApi3Route(componentCollector);\n\n\t\t// Merge the route into the paths object\n\t\tfor (const [path, methods] of Object.entries(route)) {\n\t\t\tif (!paths[path]) {\n\t\t\t\tpaths[path] = {};\n\t\t\t}\n\t\t\tObject.assign(paths[path], methods);\n\t\t}\n\t}\n\n\tconst doc: OpenAPIV3_1.Document = {\n\t\topenapi: '3.0.0',\n\t\tinfo: {\n\t\t\ttitle,\n\t\t\tversion,\n\t\t\t...(description && { description }),\n\t\t},\n\t\tpaths,\n\t};\n\n\t// Add components if any schemas were collected\n\tif (Object.keys(componentCollector.schemas).length > 0) {\n\t\tdoc.components = {\n\t\t\tschemas: componentCollector.schemas,\n\t\t};\n\t}\n\n\treturn doc;\n}\n"],"mappings":";;AAcA,SAAgB,2BAA+C;CAC9D,MAAM,UAAoD,CAAC;CAE3D,OAAO;EACN;EACA,UAAU,IAAY,QAAkC;GACvD,QAAQ,MAAM;EACf;EACA,aAAa,IAAyC;GACrD,OAAO,EAAE,MAAM,wBAAwB,KAAK;EAC7C;CACD;AACD;;;;;;;AAQA,eAAsB,mBACrB,WAGA,UAAgC,CAAC,GACD;CAChC,MAAM,EAAE,QAAQ,OAAO,UAAU,SAAS,gBAAgB;CAC1D,MAAM,QAAiC,CAAC;CACxC,MAAM,qBAAqB,yBAAyB;CAEpD,KAAK,MAAM,YAAY,WAAW;EACjC,MAAM,QAAQ,MAAM,SAAS,gBAAgB,kBAAkB;EAG/D,KAAK,MAAM,CAAC,MAAM,YAAY,OAAO,QAAQ,KAAK,GAAG;GACpD,IAAI,CAAC,MAAM,OACV,MAAM,QAAQ,CAAC;GAEhB,OAAO,OAAO,MAAM,OAAO,OAAO;EACnC;CACD;CAEA,MAAM,MAA4B;EACjC,SAAS;EACT,MAAM;GACL;GACA;GACA,GAAI,eAAe,EAAE,YAAY;EAClC;EACA;CACD;CAGA,IAAI,OAAO,KAAK,mBAAmB,OAAO,CAAC,CAAC,SAAS,GACpD,IAAI,aAAa,EAChB,SAAS,mBAAmB,QAC7B;CAGD,OAAO;AACR"}
|
package/dist/openapi.d.cts
CHANGED
|
@@ -1,2 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { OpenAPIV3_1 } from "openapi-types";
|
|
2
|
+
//#region src/openapi.d.ts
|
|
3
|
+
export interface OpenApiSchemaOptions {
|
|
4
|
+
title?: string;
|
|
5
|
+
version?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ComponentCollector {
|
|
9
|
+
schemas: Record<string, OpenAPIV3_1.SchemaObject>;
|
|
10
|
+
addSchema(id: string, schema: OpenAPIV3_1.SchemaObject): void;
|
|
11
|
+
getReference(id: string): OpenAPIV3_1.ReferenceObject;
|
|
12
|
+
}
|
|
13
|
+
export declare function createComponentCollector(): ComponentCollector;
|
|
14
|
+
/**
|
|
15
|
+
* Builds OpenAPI 3.1 schema from an array of endpoints.
|
|
16
|
+
*
|
|
17
|
+
* Note: This function requires endpoints with toOpenApi3Route method.
|
|
18
|
+
* The actual implementation is in @geekmidas/constructs to avoid circular dependencies.
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildOpenApiSchema(endpoints: Array<{
|
|
21
|
+
toOpenApi3Route(collector?: ComponentCollector): Promise<any>;
|
|
22
|
+
}>, options?: OpenApiSchemaOptions): Promise<OpenAPIV3_1.Document>;
|
|
23
|
+
//#endregion
|
|
24
|
+
//# sourceMappingURL=openapi.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi.d.cts","names":[],"sources":["../src/openapi.ts"],"mappings":";;iBAEiB;EAChB;EACA;EACA;;iBAGgB;EAChB,SAAS,eAAe,YAAY;EACpC,UAAU,YAAY,QAAQ,YAAY;EAC1C,aAAa,aAAa,YAAY;;wBAGvB,4BAA4B;;;;;;;wBAoBtB,mBACrB,WAAW;EACV,gBAAgB,YAAY,qBAAqB;IAElD,UAAS,uBACP,QAAQ,YAAY"}
|
package/dist/openapi.d.mts
CHANGED
|
@@ -1,2 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { OpenAPIV3_1 } from "openapi-types";
|
|
2
|
+
//#region src/openapi.d.ts
|
|
3
|
+
export interface OpenApiSchemaOptions {
|
|
4
|
+
title?: string;
|
|
5
|
+
version?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ComponentCollector {
|
|
9
|
+
schemas: Record<string, OpenAPIV3_1.SchemaObject>;
|
|
10
|
+
addSchema(id: string, schema: OpenAPIV3_1.SchemaObject): void;
|
|
11
|
+
getReference(id: string): OpenAPIV3_1.ReferenceObject;
|
|
12
|
+
}
|
|
13
|
+
export declare function createComponentCollector(): ComponentCollector;
|
|
14
|
+
/**
|
|
15
|
+
* Builds OpenAPI 3.1 schema from an array of endpoints.
|
|
16
|
+
*
|
|
17
|
+
* Note: This function requires endpoints with toOpenApi3Route method.
|
|
18
|
+
* The actual implementation is in @geekmidas/constructs to avoid circular dependencies.
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildOpenApiSchema(endpoints: Array<{
|
|
21
|
+
toOpenApi3Route(collector?: ComponentCollector): Promise<any>;
|
|
22
|
+
}>, options?: OpenApiSchemaOptions): Promise<OpenAPIV3_1.Document>;
|
|
23
|
+
//#endregion
|
|
24
|
+
//# sourceMappingURL=openapi.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi.d.mts","names":[],"sources":["../src/openapi.ts"],"mappings":";;iBAEiB;EAChB;EACA;EACA;;iBAGgB;EAChB,SAAS,eAAe,YAAY;EACpC,UAAU,YAAY,QAAQ,YAAY;EAC1C,aAAa,aAAa,YAAY;;wBAGvB,4BAA4B;;;;;;;wBAoBtB,mBACrB,WAAW;EACV,gBAAgB,YAAY,qBAAqB;IAElD,UAAS,uBACP,QAAQ,YAAY"}
|
package/dist/openapi.mjs
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/openapi.ts
|
|
2
|
+
function createComponentCollector() {
|
|
3
|
+
const schemas = {};
|
|
4
|
+
return {
|
|
5
|
+
schemas,
|
|
6
|
+
addSchema(id, schema) {
|
|
7
|
+
schemas[id] = schema;
|
|
8
|
+
},
|
|
9
|
+
getReference(id) {
|
|
10
|
+
return { $ref: `#/components/schemas/${id}` };
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Builds OpenAPI 3.1 schema from an array of endpoints.
|
|
16
|
+
*
|
|
17
|
+
* Note: This function requires endpoints with toOpenApi3Route method.
|
|
18
|
+
* The actual implementation is in @geekmidas/constructs to avoid circular dependencies.
|
|
19
|
+
*/
|
|
20
|
+
async function buildOpenApiSchema(endpoints, options = {}) {
|
|
21
|
+
const { title = "API", version = "1.0.0", description } = options;
|
|
22
|
+
const paths = {};
|
|
23
|
+
const componentCollector = createComponentCollector();
|
|
24
|
+
for (const endpoint of endpoints) {
|
|
25
|
+
const route = await endpoint.toOpenApi3Route(componentCollector);
|
|
26
|
+
for (const [path, methods] of Object.entries(route)) {
|
|
27
|
+
if (!paths[path]) paths[path] = {};
|
|
28
|
+
Object.assign(paths[path], methods);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const doc = {
|
|
32
|
+
openapi: "3.0.0",
|
|
33
|
+
info: {
|
|
34
|
+
title,
|
|
35
|
+
version,
|
|
36
|
+
...description && { description }
|
|
37
|
+
},
|
|
38
|
+
paths
|
|
39
|
+
};
|
|
40
|
+
if (Object.keys(componentCollector.schemas).length > 0) doc.components = { schemas: componentCollector.schemas };
|
|
41
|
+
return doc;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { buildOpenApiSchema, createComponentCollector };
|
|
2
45
|
|
|
3
|
-
|
|
46
|
+
//# sourceMappingURL=openapi.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi.mjs","names":[],"sources":["../src/openapi.ts"],"sourcesContent":["import type { OpenAPIV3_1 } from 'openapi-types';\n\nexport interface OpenApiSchemaOptions {\n\ttitle?: string;\n\tversion?: string;\n\tdescription?: string;\n}\n\nexport interface ComponentCollector {\n\tschemas: Record<string, OpenAPIV3_1.SchemaObject>;\n\taddSchema(id: string, schema: OpenAPIV3_1.SchemaObject): void;\n\tgetReference(id: string): OpenAPIV3_1.ReferenceObject;\n}\n\nexport function createComponentCollector(): ComponentCollector {\n\tconst schemas: Record<string, OpenAPIV3_1.SchemaObject> = {};\n\n\treturn {\n\t\tschemas,\n\t\taddSchema(id: string, schema: OpenAPIV3_1.SchemaObject) {\n\t\t\tschemas[id] = schema;\n\t\t},\n\t\tgetReference(id: string): OpenAPIV3_1.ReferenceObject {\n\t\t\treturn { $ref: `#/components/schemas/${id}` };\n\t\t},\n\t};\n}\n\n/**\n * Builds OpenAPI 3.1 schema from an array of endpoints.\n *\n * Note: This function requires endpoints with toOpenApi3Route method.\n * The actual implementation is in @geekmidas/constructs to avoid circular dependencies.\n */\nexport async function buildOpenApiSchema(\n\tendpoints: Array<{\n\t\ttoOpenApi3Route(collector?: ComponentCollector): Promise<any>;\n\t}>,\n\toptions: OpenApiSchemaOptions = {},\n): Promise<OpenAPIV3_1.Document> {\n\tconst { title = 'API', version = '1.0.0', description } = options;\n\tconst paths: OpenAPIV3_1.PathsObject = {};\n\tconst componentCollector = createComponentCollector();\n\n\tfor (const endpoint of endpoints) {\n\t\tconst route = await endpoint.toOpenApi3Route(componentCollector);\n\n\t\t// Merge the route into the paths object\n\t\tfor (const [path, methods] of Object.entries(route)) {\n\t\t\tif (!paths[path]) {\n\t\t\t\tpaths[path] = {};\n\t\t\t}\n\t\t\tObject.assign(paths[path], methods);\n\t\t}\n\t}\n\n\tconst doc: OpenAPIV3_1.Document = {\n\t\topenapi: '3.0.0',\n\t\tinfo: {\n\t\t\ttitle,\n\t\t\tversion,\n\t\t\t...(description && { description }),\n\t\t},\n\t\tpaths,\n\t};\n\n\t// Add components if any schemas were collected\n\tif (Object.keys(componentCollector.schemas).length > 0) {\n\t\tdoc.components = {\n\t\t\tschemas: componentCollector.schemas,\n\t\t};\n\t}\n\n\treturn doc;\n}\n"],"mappings":";AAcA,SAAgB,2BAA+C;CAC9D,MAAM,UAAoD,CAAC;CAE3D,OAAO;EACN;EACA,UAAU,IAAY,QAAkC;GACvD,QAAQ,MAAM;EACf;EACA,aAAa,IAAyC;GACrD,OAAO,EAAE,MAAM,wBAAwB,KAAK;EAC7C;CACD;AACD;;;;;;;AAQA,eAAsB,mBACrB,WAGA,UAAgC,CAAC,GACD;CAChC,MAAM,EAAE,QAAQ,OAAO,UAAU,SAAS,gBAAgB;CAC1D,MAAM,QAAiC,CAAC;CACxC,MAAM,qBAAqB,yBAAyB;CAEpD,KAAK,MAAM,YAAY,WAAW;EACjC,MAAM,QAAQ,MAAM,SAAS,gBAAgB,kBAAkB;EAG/D,KAAK,MAAM,CAAC,MAAM,YAAY,OAAO,QAAQ,KAAK,GAAG;GACpD,IAAI,CAAC,MAAM,OACV,MAAM,QAAQ,CAAC;GAEhB,OAAO,OAAO,MAAM,OAAO,OAAO;EACnC;CACD;CAEA,MAAM,MAA4B;EACjC,SAAS;EACT,MAAM;GACL;GACA;GACA,GAAI,eAAe,EAAE,YAAY;EAClC;EACA;CACD;CAGA,IAAI,OAAO,KAAK,mBAAmB,OAAO,CAAC,CAAC,SAAS,GACpD,IAAI,aAAa,EAChB,SAAS,mBAAmB,QAC7B;CAGD,OAAO;AACR"}
|
package/dist/parser.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/parser.ts
|
|
3
3
|
/**
|
|
4
4
|
* Validates data against a StandardSchema.
|
|
@@ -11,13 +11,13 @@ function validate(schema, data) {
|
|
|
11
11
|
return schema["~standard"].validate(data);
|
|
12
12
|
}
|
|
13
13
|
async function parseSchema(schema, data) {
|
|
14
|
-
if (!schema) return
|
|
14
|
+
if (!schema) return;
|
|
15
15
|
const parsed = await validate(schema, data);
|
|
16
16
|
if (parsed.issues) throw parsed.issues;
|
|
17
17
|
return parsed.value;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
19
|
//#endregion
|
|
21
20
|
exports.parseSchema = parseSchema;
|
|
22
21
|
exports.validate = validate;
|
|
22
|
+
|
|
23
23
|
//# sourceMappingURL=parser.cjs.map
|
package/dist/parser.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.cjs","names":[
|
|
1
|
+
{"version":3,"file":"parser.cjs","names":[],"sources":["../src/parser.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { InferStandardSchema } from './types';\n\n/**\n * Validates data against a StandardSchema.\n *\n * @param schema - The StandardSchema to validate against\n * @param data - The data to validate\n * @returns Validation result with value or issues\n */\nexport function validate<T extends StandardSchemaV1>(schema: T, data: unknown) {\n\treturn schema['~standard'].validate(data);\n}\n\nexport async function parseSchema<T extends StandardSchemaV1>(\n\tschema: T,\n\tdata: unknown,\n): Promise<InferStandardSchema<T>> {\n\tif (!schema) {\n\t\treturn undefined as InferStandardSchema<T>;\n\t}\n\n\tconst parsed = await validate(schema as unknown as StandardSchemaV1, data);\n\n\tif (parsed.issues) {\n\t\tthrow parsed.issues;\n\t}\n\n\treturn parsed.value as InferStandardSchema<T>;\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgB,SAAqC,QAAW,MAAe;CAC9E,OAAO,OAAO,YAAY,CAAC,SAAS,IAAI;AACzC;AAEA,eAAsB,YACrB,QACA,MACkC;CAClC,IAAI,CAAC,QACJ;CAGD,MAAM,SAAS,MAAM,SAAS,QAAuC,IAAI;CAEzE,IAAI,OAAO,QACV,MAAM,OAAO;CAGd,OAAO,OAAO;AACf"}
|
package/dist/parser.d.cts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { InferStandardSchema } from "./types
|
|
1
|
+
import { InferStandardSchema } from "./types.cjs";
|
|
2
2
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
-
|
|
4
3
|
//#region src/parser.d.ts
|
|
5
|
-
|
|
6
4
|
/**
|
|
7
5
|
* Validates data against a StandardSchema.
|
|
8
6
|
*
|
|
@@ -10,10 +8,7 @@ import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
|
10
8
|
* @param data - The data to validate
|
|
11
9
|
* @returns Validation result with value or issues
|
|
12
10
|
*/
|
|
13
|
-
declare function validate<T extends StandardSchemaV1>(schema: T, data: unknown): StandardSchemaV1.Result<unknown> | Promise<StandardSchemaV1.Result<unknown>>;
|
|
14
|
-
declare function parseSchema<T extends StandardSchemaV1>(schema: T, data: unknown): Promise<InferStandardSchema<T>>;
|
|
15
|
-
//# sourceMappingURL=parser.d.ts.map
|
|
16
|
-
|
|
11
|
+
export declare function validate<T extends StandardSchemaV1>(schema: T, data: unknown): StandardSchemaV1.Result<unknown> | Promise<StandardSchemaV1.Result<unknown>>;
|
|
12
|
+
export declare function parseSchema<T extends StandardSchemaV1>(schema: T, data: unknown): Promise<InferStandardSchema<T>>;
|
|
17
13
|
//#endregion
|
|
18
|
-
export { parseSchema, validate };
|
|
19
14
|
//# sourceMappingURL=parser.d.cts.map
|