@geekmidas/schema 10.0.0-alpha.98 → 10.0.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/CHANGELOG.md +65 -0
- package/README.md +6 -6
- package/dist/conversion-CIBtqJkS.mjs +106 -0
- package/dist/conversion-CIBtqJkS.mjs.map +1 -0
- package/dist/conversion-Cf9R-jGc.cjs +148 -0
- package/dist/conversion-Cf9R-jGc.cjs.map +1 -0
- package/dist/conversion-JY1Wixil.d.cts +39 -0
- package/dist/conversion-JY1Wixil.d.cts.map +1 -0
- package/dist/conversion-e4k9rTxy.d.mts +39 -0
- package/dist/conversion-e4k9rTxy.d.mts.map +1 -0
- package/dist/conversion.cjs +8 -106
- package/dist/conversion.d.cts +2 -37
- package/dist/conversion.d.mts +2 -37
- package/dist/conversion.mjs +2 -99
- package/dist/index.cjs +4 -4
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +4 -3
- package/dist/openapi-Aeb_1e9T.d.cts +28 -0
- package/dist/openapi-Aeb_1e9T.d.cts.map +1 -0
- package/dist/openapi-DH5yCqKh.mjs +46 -0
- package/dist/openapi-DH5yCqKh.mjs.map +1 -0
- package/dist/openapi-DVvLYx-8.cjs +58 -0
- package/dist/openapi-DVvLYx-8.cjs.map +1 -0
- package/dist/openapi-Dxc4FuMP.d.mts +28 -0
- package/dist/openapi-Dxc4FuMP.d.mts.map +1 -0
- package/dist/openapi.cjs +3 -56
- package/dist/openapi.d.cts +2 -27
- package/dist/openapi.d.mts +2 -27
- package/dist/openapi.mjs +2 -54
- package/dist/parser.cjs +3 -3
- package/dist/parser.cjs.map +1 -1
- package/dist/parser.d.cts +8 -3
- package/dist/parser.d.cts.map +1 -1
- package/dist/parser.d.mts +8 -3
- package/dist/parser.d.mts.map +1 -1
- package/dist/parser.mjs +2 -2
- package/dist/parser.mjs.map +1 -1
- package/dist/types-Bm3VhqVE.d.cts +26 -0
- package/dist/types-Bm3VhqVE.d.cts.map +1 -0
- package/dist/types-xm7EGhin.d.mts +26 -0
- package/dist/types-xm7EGhin.d.mts.map +1 -0
- package/dist/types.d.cts +2 -22
- package/dist/types.d.mts +2 -22
- package/dist/types.mjs +0 -1
- package/package.json +8 -15
- package/src/__benchmarks__/conversion.bench.ts +88 -0
- package/src/__tests__/conversion.spec.ts +502 -0
- package/src/__tests__/openapi.spec.ts +396 -0
- package/src/__tests__/parser.spec.ts +236 -0
- package/src/conversion.ts +220 -0
- package/src/index.ts +15 -0
- package/src/openapi.ts +75 -0
- package/src/parser.ts +30 -0
- package/src/types.ts +37 -0
- package/tsconfig.json +9 -0
- package/tsdown.config.ts +5 -0
- package/dist/conversion.cjs.map +0 -1
- package/dist/conversion.d.cts.map +0 -1
- package/dist/conversion.d.mts.map +0 -1
- package/dist/conversion.mjs.map +0 -1
- package/dist/openapi.cjs.map +0 -1
- package/dist/openapi.d.cts.map +0 -1
- package/dist/openapi.d.mts.map +0 -1
- package/dist/openapi.mjs.map +0 -1
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts.map +0 -1
package/dist/conversion.d.mts
CHANGED
|
@@ -1,37 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
|
1
|
+
import { SchemaVendor, StandardSchemaJsonSchema, VendorConvertor, VendorConvertors, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, getRegisteredZodJsonSchemas, getSchemaMetadata, getZodMetadata } from "./conversion-e4k9rTxy.mjs";
|
|
2
|
+
export { SchemaVendor, StandardSchemaJsonSchema, VendorConvertor, VendorConvertors, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, getRegisteredZodJsonSchemas, getSchemaMetadata, getZodMetadata };
|
package/dist/conversion.mjs
CHANGED
|
@@ -1,100 +1,3 @@
|
|
|
1
|
-
|
|
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" || key === "$schema") 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
|
-
if (typeof jsonSchema?.$ref === "string") return componentCollector.getReference(schemaId);
|
|
91
|
-
const { id, ...schemaWithoutId } = jsonSchema;
|
|
92
|
-
componentCollector.addSchema(schemaId, schemaWithoutId);
|
|
93
|
-
return componentCollector.getReference(schemaId);
|
|
94
|
-
}
|
|
95
|
-
return jsonSchema;
|
|
96
|
-
}
|
|
97
|
-
//#endregion
|
|
98
|
-
export { SchemaVendor, StandardSchemaJsonSchema, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, getRegisteredZodJsonSchemas, getSchemaMetadata, getZodMetadata };
|
|
1
|
+
import { SchemaVendor, StandardSchemaJsonSchema, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, getRegisteredZodJsonSchemas, getSchemaMetadata, getZodMetadata } from "./conversion-CIBtqJkS.mjs";
|
|
99
2
|
|
|
100
|
-
|
|
3
|
+
export { SchemaVendor, StandardSchemaJsonSchema, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, getRegisteredZodJsonSchemas, getSchemaMetadata, getZodMetadata };
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
1
|
+
const require_conversion = require('./conversion-Cf9R-jGc.cjs');
|
|
2
|
+
const require_openapi = require('./openapi-DVvLYx-8.cjs');
|
|
3
|
+
|
|
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.cjs";
|
|
2
|
-
import { ComponentCollector, OpenApiSchemaOptions, buildOpenApiSchema, createComponentCollector } from "./openapi.cjs";
|
|
3
|
-
import { ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema, InferStandardSchemaInput } from "./types.cjs";
|
|
4
|
-
export {
|
|
1
|
+
import { convertSchemaWithComponents, convertStandardSchemaToJsonSchema } from "./conversion-JY1Wixil.cjs";
|
|
2
|
+
import { ComponentCollector, OpenApiSchemaOptions, buildOpenApiSchema, createComponentCollector } from "./openapi-Aeb_1e9T.cjs";
|
|
3
|
+
import { ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema, InferStandardSchemaInput } from "./types-Bm3VhqVE.cjs";
|
|
4
|
+
export { ComponentCollector, ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema, InferStandardSchemaInput, OpenApiSchemaOptions, buildOpenApiSchema, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, createComponentCollector };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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 {
|
|
1
|
+
import { convertSchemaWithComponents, convertStandardSchemaToJsonSchema } from "./conversion-e4k9rTxy.mjs";
|
|
2
|
+
import { ComponentCollector, OpenApiSchemaOptions, buildOpenApiSchema, createComponentCollector } from "./openapi-Dxc4FuMP.mjs";
|
|
3
|
+
import { ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema, InferStandardSchemaInput } from "./types-xm7EGhin.mjs";
|
|
4
|
+
export { ComponentCollector, ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema, InferStandardSchemaInput, OpenApiSchemaOptions, buildOpenApiSchema, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, createComponentCollector };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { convertSchemaWithComponents, convertStandardSchemaToJsonSchema } from "./conversion.mjs";
|
|
2
|
-
import { buildOpenApiSchema, createComponentCollector } from "./openapi.mjs";
|
|
3
|
-
|
|
1
|
+
import { convertSchemaWithComponents, convertStandardSchemaToJsonSchema } from "./conversion-CIBtqJkS.mjs";
|
|
2
|
+
import { buildOpenApiSchema, createComponentCollector } from "./openapi-DH5yCqKh.mjs";
|
|
3
|
+
|
|
4
|
+
export { buildOpenApiSchema, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, createComponentCollector };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { OpenAPIV3_1 } from "openapi-types";
|
|
2
|
+
|
|
3
|
+
//#region src/openapi.d.ts
|
|
4
|
+
interface OpenApiSchemaOptions {
|
|
5
|
+
title?: string;
|
|
6
|
+
version?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
}
|
|
9
|
+
interface ComponentCollector {
|
|
10
|
+
schemas: Record<string, OpenAPIV3_1.SchemaObject>;
|
|
11
|
+
addSchema(id: string, schema: OpenAPIV3_1.SchemaObject): void;
|
|
12
|
+
getReference(id: string): OpenAPIV3_1.ReferenceObject;
|
|
13
|
+
}
|
|
14
|
+
declare function createComponentCollector(): ComponentCollector;
|
|
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
|
+
declare function buildOpenApiSchema(endpoints: Array<{
|
|
22
|
+
toOpenApi3Route(collector?: ComponentCollector): Promise<any>;
|
|
23
|
+
}>, options?: OpenApiSchemaOptions): Promise<OpenAPIV3_1.Document>;
|
|
24
|
+
//# sourceMappingURL=openapi.d.ts.map
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { ComponentCollector, OpenApiSchemaOptions, buildOpenApiSchema, createComponentCollector };
|
|
28
|
+
//# sourceMappingURL=openapi-Aeb_1e9T.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-Aeb_1e9T.d.cts","names":[],"sources":["../src/openapi.ts"],"sourcesContent":[],"mappings":";;;UAEiB,oBAAA;;EAAA,OAAA,CAAA,EAAA,MAAA;EAMA,WAAA,CAAA,EAAA,MAAA;;AACQ,UADR,kBAAA,CACoB;EAAY,OAAvC,EAAA,MAAA,CAAA,MAAA,EAAe,WAAA,CAAY,YAA3B,CAAA;EAAM,SACe,CAAA,EAAA,EAAA,MAAY,EAAA,MAAA,EAAZ,WAAA,CAAY,YAAA,CAAA,EAAA,IAAA;EAAY,YAC5B,CAAA,EAAY,EAAA,MAAA,CAAA,EAAZ,WAAA,CAAY,eAAA;AAAe;AAGtC,iBAAA,wBAAA,CAAA,CAA4B,EAAA,kBAAkB;AAoB9D;;;;;;AAKW,iBALW,kBAAA,CAKC,SAAA,EAJX,KAIW,CAAA;EAAQ,eAA5B,CAAA,SAAA,CAAA,EAH2B,kBAG3B,CAAA,EAHgD,OAGhD,CAAA,GAAA,CAAA;AAAO,CAAA,CAAA,EAAA,OAAA,CAAA,EADA,oBACA,CAAA,EAAP,OAAO,CAAC,WAAA,CAAY,QAAb,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { buildOpenApiSchema, createComponentCollector };
|
|
46
|
+
//# sourceMappingURL=openapi-DH5yCqKh.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-DH5yCqKh.mjs","names":["schemas: Record<string, OpenAPIV3_1.SchemaObject>","id: string","schema: OpenAPIV3_1.SchemaObject","endpoints: Array<{\n\t\ttoOpenApi3Route(collector?: ComponentCollector): Promise<any>;\n\t}>","options: OpenApiSchemaOptions","paths: OpenAPIV3_1.PathsObject","doc: OpenAPIV3_1.Document"],"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,MAAMA,UAAoD,CAAE;AAE5D,QAAO;EACN;EACA,UAAUC,IAAYC,QAAkC;AACvD,WAAQ,MAAM;EACd;EACD,aAAaD,IAAyC;AACrD,UAAO,EAAE,OAAO,uBAAuB,GAAG,EAAG;EAC7C;CACD;AACD;;;;;;;AAQD,eAAsB,mBACrBE,WAGAC,UAAgC,CAAE,GACF;CAChC,MAAM,EAAE,QAAQ,OAAO,UAAU,SAAS,aAAa,GAAG;CAC1D,MAAMC,QAAiC,CAAE;CACzC,MAAM,qBAAqB,0BAA0B;AAErD,MAAK,MAAM,YAAY,WAAW;EACjC,MAAM,QAAQ,MAAM,SAAS,gBAAgB,mBAAmB;AAGhE,OAAK,MAAM,CAAC,MAAM,QAAQ,IAAI,OAAO,QAAQ,MAAM,EAAE;AACpD,QAAK,MAAM,MACV,OAAM,QAAQ,CAAE;AAEjB,UAAO,OAAO,MAAM,OAAO,QAAQ;EACnC;CACD;CAED,MAAMC,MAA4B;EACjC,SAAS;EACT,MAAM;GACL;GACA;GACA,GAAI,eAAe,EAAE,YAAa;EAClC;EACD;CACA;AAGD,KAAI,OAAO,KAAK,mBAAmB,QAAQ,CAAC,SAAS,EACpD,KAAI,aAAa,EAChB,SAAS,mBAAmB,QAC5B;AAGF,QAAO;AACP"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
|
|
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
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
Object.defineProperty(exports, 'buildOpenApiSchema', {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
get: function () {
|
|
49
|
+
return buildOpenApiSchema;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(exports, 'createComponentCollector', {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
get: function () {
|
|
55
|
+
return createComponentCollector;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
//# sourceMappingURL=openapi-DVvLYx-8.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-DVvLYx-8.cjs","names":["schemas: Record<string, OpenAPIV3_1.SchemaObject>","id: string","schema: OpenAPIV3_1.SchemaObject","endpoints: Array<{\n\t\ttoOpenApi3Route(collector?: ComponentCollector): Promise<any>;\n\t}>","options: OpenApiSchemaOptions","paths: OpenAPIV3_1.PathsObject","doc: OpenAPIV3_1.Document"],"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,MAAMA,UAAoD,CAAE;AAE5D,QAAO;EACN;EACA,UAAUC,IAAYC,QAAkC;AACvD,WAAQ,MAAM;EACd;EACD,aAAaD,IAAyC;AACrD,UAAO,EAAE,OAAO,uBAAuB,GAAG,EAAG;EAC7C;CACD;AACD;;;;;;;AAQD,eAAsB,mBACrBE,WAGAC,UAAgC,CAAE,GACF;CAChC,MAAM,EAAE,QAAQ,OAAO,UAAU,SAAS,aAAa,GAAG;CAC1D,MAAMC,QAAiC,CAAE;CACzC,MAAM,qBAAqB,0BAA0B;AAErD,MAAK,MAAM,YAAY,WAAW;EACjC,MAAM,QAAQ,MAAM,SAAS,gBAAgB,mBAAmB;AAGhE,OAAK,MAAM,CAAC,MAAM,QAAQ,IAAI,OAAO,QAAQ,MAAM,EAAE;AACpD,QAAK,MAAM,MACV,OAAM,QAAQ,CAAE;AAEjB,UAAO,OAAO,MAAM,OAAO,QAAQ;EACnC;CACD;CAED,MAAMC,MAA4B;EACjC,SAAS;EACT,MAAM;GACL;GACA;GACA,GAAI,eAAe,EAAE,YAAa;EAClC;EACD;CACA;AAGD,KAAI,OAAO,KAAK,mBAAmB,QAAQ,CAAC,SAAS,EACpD,KAAI,aAAa,EAChB,SAAS,mBAAmB,QAC5B;AAGF,QAAO;AACP"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { OpenAPIV3_1 } from "openapi-types";
|
|
2
|
+
|
|
3
|
+
//#region src/openapi.d.ts
|
|
4
|
+
interface OpenApiSchemaOptions {
|
|
5
|
+
title?: string;
|
|
6
|
+
version?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
}
|
|
9
|
+
interface ComponentCollector {
|
|
10
|
+
schemas: Record<string, OpenAPIV3_1.SchemaObject>;
|
|
11
|
+
addSchema(id: string, schema: OpenAPIV3_1.SchemaObject): void;
|
|
12
|
+
getReference(id: string): OpenAPIV3_1.ReferenceObject;
|
|
13
|
+
}
|
|
14
|
+
declare function createComponentCollector(): ComponentCollector;
|
|
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
|
+
declare function buildOpenApiSchema(endpoints: Array<{
|
|
22
|
+
toOpenApi3Route(collector?: ComponentCollector): Promise<any>;
|
|
23
|
+
}>, options?: OpenApiSchemaOptions): Promise<OpenAPIV3_1.Document>;
|
|
24
|
+
//# sourceMappingURL=openapi.d.ts.map
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { ComponentCollector, OpenApiSchemaOptions, buildOpenApiSchema, createComponentCollector };
|
|
28
|
+
//# sourceMappingURL=openapi-Dxc4FuMP.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-Dxc4FuMP.d.mts","names":[],"sources":["../src/openapi.ts"],"sourcesContent":[],"mappings":";;;UAEiB,oBAAA;;EAAA,OAAA,CAAA,EAAA,MAAA;EAMA,WAAA,CAAA,EAAA,MAAA;;AACQ,UADR,kBAAA,CACoB;EAAY,OAAvC,EAAA,MAAA,CAAA,MAAA,EAAe,WAAA,CAAY,YAA3B,CAAA;EAAM,SACe,CAAA,EAAA,EAAA,MAAY,EAAA,MAAA,EAAZ,WAAA,CAAY,YAAA,CAAA,EAAA,IAAA;EAAY,YAC5B,CAAA,EAAY,EAAA,MAAA,CAAA,EAAZ,WAAA,CAAY,eAAA;AAAe;AAGtC,iBAAA,wBAAA,CAAA,CAA4B,EAAA,kBAAkB;AAoB9D;;;;;;AAKW,iBALW,kBAAA,CAKC,SAAA,EAJX,KAIW,CAAA;EAAQ,eAA5B,CAAA,SAAA,CAAA,EAH2B,kBAG3B,CAAA,EAHgD,OAGhD,CAAA,GAAA,CAAA;AAAO,CAAA,CAAA,EAAA,OAAA,CAAA,EADA,oBACA,CAAA,EAAP,OAAO,CAAC,WAAA,CAAY,QAAb,CAAA"}
|
package/dist/openapi.cjs
CHANGED
|
@@ -1,57 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/openapi.ts
|
|
3
|
-
function createComponentCollector() {
|
|
4
|
-
const schemas = {};
|
|
5
|
-
const securitySchemes = {};
|
|
6
|
-
return {
|
|
7
|
-
schemas,
|
|
8
|
-
securitySchemes,
|
|
9
|
-
addSchema(id, schema) {
|
|
10
|
-
schemas[id] = schema;
|
|
11
|
-
},
|
|
12
|
-
addSecurityScheme(name, scheme) {
|
|
13
|
-
securitySchemes[name] = scheme;
|
|
14
|
-
},
|
|
15
|
-
getReference(id) {
|
|
16
|
-
return { $ref: `#/components/schemas/${id}` };
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Builds OpenAPI 3.1 schema from an array of endpoints.
|
|
22
|
-
*
|
|
23
|
-
* Note: This function requires endpoints with toOpenApi3Route method.
|
|
24
|
-
* The actual implementation is in @geekmidas/constructs to avoid circular dependencies.
|
|
25
|
-
*/
|
|
26
|
-
async function buildOpenApiSchema(endpoints, options = {}) {
|
|
27
|
-
const { title = "API", version = "1.0.0", description } = options;
|
|
28
|
-
const paths = {};
|
|
29
|
-
const componentCollector = createComponentCollector();
|
|
30
|
-
for (const endpoint of endpoints) {
|
|
31
|
-
const route = await endpoint.toOpenApi3Route(componentCollector);
|
|
32
|
-
for (const [path, methods] of Object.entries(route)) {
|
|
33
|
-
if (!paths[path]) paths[path] = {};
|
|
34
|
-
Object.assign(paths[path], methods);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
const doc = {
|
|
38
|
-
openapi: "3.1.0",
|
|
39
|
-
info: {
|
|
40
|
-
title,
|
|
41
|
-
version,
|
|
42
|
-
...description && { description }
|
|
43
|
-
},
|
|
44
|
-
paths
|
|
45
|
-
};
|
|
46
|
-
const { schemas, securitySchemes } = componentCollector;
|
|
47
|
-
if (Object.keys(schemas).length > 0 || Object.keys(securitySchemes).length > 0) doc.components = {
|
|
48
|
-
...Object.keys(schemas).length > 0 && { schemas },
|
|
49
|
-
...Object.keys(securitySchemes).length > 0 && { securitySchemes }
|
|
50
|
-
};
|
|
51
|
-
return doc;
|
|
52
|
-
}
|
|
53
|
-
//#endregion
|
|
54
|
-
exports.buildOpenApiSchema = buildOpenApiSchema;
|
|
55
|
-
exports.createComponentCollector = createComponentCollector;
|
|
1
|
+
const require_openapi = require('./openapi-DVvLYx-8.cjs');
|
|
56
2
|
|
|
57
|
-
|
|
3
|
+
exports.buildOpenApiSchema = require_openapi.buildOpenApiSchema;
|
|
4
|
+
exports.createComponentCollector = require_openapi.createComponentCollector;
|
package/dist/openapi.d.cts
CHANGED
|
@@ -1,27 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
-
/** The schemes operations name in their `security` requirements. */
|
|
11
|
-
securitySchemes: Record<string, OpenAPIV3_1.SecuritySchemeObject>;
|
|
12
|
-
addSchema(id: string, schema: OpenAPIV3_1.SchemaObject): void;
|
|
13
|
-
addSecurityScheme(name: string, scheme: OpenAPIV3_1.SecuritySchemeObject): void;
|
|
14
|
-
getReference(id: string): OpenAPIV3_1.ReferenceObject;
|
|
15
|
-
}
|
|
16
|
-
export declare function createComponentCollector(): ComponentCollector;
|
|
17
|
-
/**
|
|
18
|
-
* Builds OpenAPI 3.1 schema from an array of endpoints.
|
|
19
|
-
*
|
|
20
|
-
* Note: This function requires endpoints with toOpenApi3Route method.
|
|
21
|
-
* The actual implementation is in @geekmidas/constructs to avoid circular dependencies.
|
|
22
|
-
*/
|
|
23
|
-
export declare function buildOpenApiSchema(endpoints: Array<{
|
|
24
|
-
toOpenApi3Route(collector?: ComponentCollector): Promise<any>;
|
|
25
|
-
}>, options?: OpenApiSchemaOptions): Promise<OpenAPIV3_1.Document>;
|
|
26
|
-
//#endregion
|
|
27
|
-
//# sourceMappingURL=openapi.d.cts.map
|
|
1
|
+
import { ComponentCollector, OpenApiSchemaOptions, buildOpenApiSchema, createComponentCollector } from "./openapi-Aeb_1e9T.cjs";
|
|
2
|
+
export { ComponentCollector, OpenApiSchemaOptions, buildOpenApiSchema, createComponentCollector };
|
package/dist/openapi.d.mts
CHANGED
|
@@ -1,27 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
-
/** The schemes operations name in their `security` requirements. */
|
|
11
|
-
securitySchemes: Record<string, OpenAPIV3_1.SecuritySchemeObject>;
|
|
12
|
-
addSchema(id: string, schema: OpenAPIV3_1.SchemaObject): void;
|
|
13
|
-
addSecurityScheme(name: string, scheme: OpenAPIV3_1.SecuritySchemeObject): void;
|
|
14
|
-
getReference(id: string): OpenAPIV3_1.ReferenceObject;
|
|
15
|
-
}
|
|
16
|
-
export declare function createComponentCollector(): ComponentCollector;
|
|
17
|
-
/**
|
|
18
|
-
* Builds OpenAPI 3.1 schema from an array of endpoints.
|
|
19
|
-
*
|
|
20
|
-
* Note: This function requires endpoints with toOpenApi3Route method.
|
|
21
|
-
* The actual implementation is in @geekmidas/constructs to avoid circular dependencies.
|
|
22
|
-
*/
|
|
23
|
-
export declare function buildOpenApiSchema(endpoints: Array<{
|
|
24
|
-
toOpenApi3Route(collector?: ComponentCollector): Promise<any>;
|
|
25
|
-
}>, options?: OpenApiSchemaOptions): Promise<OpenAPIV3_1.Document>;
|
|
26
|
-
//#endregion
|
|
27
|
-
//# sourceMappingURL=openapi.d.mts.map
|
|
1
|
+
import { ComponentCollector, OpenApiSchemaOptions, buildOpenApiSchema, createComponentCollector } from "./openapi-Dxc4FuMP.mjs";
|
|
2
|
+
export { ComponentCollector, OpenApiSchemaOptions, buildOpenApiSchema, createComponentCollector };
|
package/dist/openapi.mjs
CHANGED
|
@@ -1,55 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
function createComponentCollector() {
|
|
3
|
-
const schemas = {};
|
|
4
|
-
const securitySchemes = {};
|
|
5
|
-
return {
|
|
6
|
-
schemas,
|
|
7
|
-
securitySchemes,
|
|
8
|
-
addSchema(id, schema) {
|
|
9
|
-
schemas[id] = schema;
|
|
10
|
-
},
|
|
11
|
-
addSecurityScheme(name, scheme) {
|
|
12
|
-
securitySchemes[name] = scheme;
|
|
13
|
-
},
|
|
14
|
-
getReference(id) {
|
|
15
|
-
return { $ref: `#/components/schemas/${id}` };
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Builds OpenAPI 3.1 schema from an array of endpoints.
|
|
21
|
-
*
|
|
22
|
-
* Note: This function requires endpoints with toOpenApi3Route method.
|
|
23
|
-
* The actual implementation is in @geekmidas/constructs to avoid circular dependencies.
|
|
24
|
-
*/
|
|
25
|
-
async function buildOpenApiSchema(endpoints, options = {}) {
|
|
26
|
-
const { title = "API", version = "1.0.0", description } = options;
|
|
27
|
-
const paths = {};
|
|
28
|
-
const componentCollector = createComponentCollector();
|
|
29
|
-
for (const endpoint of endpoints) {
|
|
30
|
-
const route = await endpoint.toOpenApi3Route(componentCollector);
|
|
31
|
-
for (const [path, methods] of Object.entries(route)) {
|
|
32
|
-
if (!paths[path]) paths[path] = {};
|
|
33
|
-
Object.assign(paths[path], methods);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
const doc = {
|
|
37
|
-
openapi: "3.1.0",
|
|
38
|
-
info: {
|
|
39
|
-
title,
|
|
40
|
-
version,
|
|
41
|
-
...description && { description }
|
|
42
|
-
},
|
|
43
|
-
paths
|
|
44
|
-
};
|
|
45
|
-
const { schemas, securitySchemes } = componentCollector;
|
|
46
|
-
if (Object.keys(schemas).length > 0 || Object.keys(securitySchemes).length > 0) doc.components = {
|
|
47
|
-
...Object.keys(schemas).length > 0 && { schemas },
|
|
48
|
-
...Object.keys(securitySchemes).length > 0 && { securitySchemes }
|
|
49
|
-
};
|
|
50
|
-
return doc;
|
|
51
|
-
}
|
|
52
|
-
//#endregion
|
|
53
|
-
export { buildOpenApiSchema, createComponentCollector };
|
|
1
|
+
import { buildOpenApiSchema, createComponentCollector } from "./openapi-DH5yCqKh.mjs";
|
|
54
2
|
|
|
55
|
-
|
|
3
|
+
export { buildOpenApiSchema, createComponentCollector };
|
package/dist/parser.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
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 void 0;
|
|
15
15
|
const parsed = await validate(schema, data);
|
|
16
16
|
if (parsed.issues) throw parsed.issues;
|
|
17
17
|
return parsed.value;
|
|
18
18
|
}
|
|
19
|
+
|
|
19
20
|
//#endregion
|
|
20
21
|
exports.parseSchema = parseSchema;
|
|
21
22
|
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":[],"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,
|
|
1
|
+
{"version":3,"file":"parser.cjs","names":["schema: T","data: unknown"],"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,SAAqCA,QAAWC,MAAe;AAC9E,QAAO,OAAO,aAAa,SAAS,KAAK;AACzC;AAED,eAAsB,YACrBD,QACAC,MACkC;AAClC,MAAK,OACJ;CAGD,MAAM,SAAS,MAAM,SAAS,QAAuC,KAAK;AAE1E,KAAI,OAAO,OACV,OAAM,OAAO;AAGd,QAAO,OAAO;AACd"}
|
package/dist/parser.d.cts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { InferStandardSchema } from "./types.cjs";
|
|
1
|
+
import { InferStandardSchema } from "./types-Bm3VhqVE.cjs";
|
|
2
2
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
+
|
|
3
4
|
//#region src/parser.d.ts
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* Validates data against a StandardSchema.
|
|
6
8
|
*
|
|
@@ -8,7 +10,10 @@ import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
|
8
10
|
* @param data - The data to validate
|
|
9
11
|
* @returns Validation result with value or issues
|
|
10
12
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
|
|
13
17
|
//#endregion
|
|
18
|
+
export { parseSchema, validate };
|
|
14
19
|
//# sourceMappingURL=parser.d.cts.map
|
package/dist/parser.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.cts","names":[],"sources":["../src/parser.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"parser.d.cts","names":[],"sources":["../src/parser.ts"],"sourcesContent":[],"mappings":";;;;;;;AAUA;;;;;AAA6E,iBAA7D,QAA6D,CAAA,UAA1C,gBAA0C,CAAA,CAAA,MAAA,EAAhB,CAAgB,EAAA,IAAA,EAAA,OAAA,CAAA,EAAA,gBAAA,CAAA,MAAA,CAAA,OAAA,CAAA,GAAA,OAAA,CAAA,gBAAA,CAAA,MAAA,CAAA,OAAA,CAAA,CAAA;AAAA,iBAIvD,WAJuD,CAAA,UAIjC,gBAJiC,CAAA,CAAA,MAAA,EAKpE,CALoE,EAAA,IAAA,EAAA,OAAA,CAAA,EAO1E,OAP0E,CAOlE,mBAPkE,CAO9C,CAP8C,CAAA,CAAA;AAAA"}
|
package/dist/parser.d.mts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { InferStandardSchema } from "./types.mjs";
|
|
1
|
+
import { InferStandardSchema } from "./types-xm7EGhin.mjs";
|
|
2
2
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
+
|
|
3
4
|
//#region src/parser.d.ts
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* Validates data against a StandardSchema.
|
|
6
8
|
*
|
|
@@ -8,7 +10,10 @@ import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
|
8
10
|
* @param data - The data to validate
|
|
9
11
|
* @returns Validation result with value or issues
|
|
10
12
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
|
|
13
17
|
//#endregion
|
|
18
|
+
export { parseSchema, validate };
|
|
14
19
|
//# sourceMappingURL=parser.d.mts.map
|