schema-components 1.12.10 → 1.13.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.
Files changed (63) hide show
  1. package/README.md +31 -0
  2. package/dist/core/adapter.d.mts +1 -1
  3. package/dist/core/adapter.mjs +37 -8
  4. package/dist/core/constraints.d.mts +16 -0
  5. package/dist/core/constraints.mjs +138 -0
  6. package/dist/core/merge.d.mts +32 -0
  7. package/dist/core/merge.mjs +96 -0
  8. package/dist/core/normalise.d.mts +40 -0
  9. package/dist/core/normalise.mjs +171 -0
  10. package/dist/core/openapi30.d.mts +38 -0
  11. package/dist/core/openapi30.mjs +223 -0
  12. package/dist/core/ref.d.mts +25 -0
  13. package/dist/core/ref.mjs +86 -0
  14. package/dist/core/renderer.d.mts +2 -2
  15. package/dist/core/renderer.mjs +8 -0
  16. package/dist/core/swagger2.d.mts +10 -0
  17. package/dist/core/swagger2.mjs +294 -0
  18. package/dist/core/typeInference.d.mts +2 -0
  19. package/dist/core/typeInference.mjs +1 -0
  20. package/dist/core/types.d.mts +2 -3
  21. package/dist/core/types.mjs +55 -2
  22. package/dist/core/version.d.mts +2 -0
  23. package/dist/core/version.mjs +79 -0
  24. package/dist/core/walkBuilders.d.mts +52 -0
  25. package/dist/core/walkBuilders.mjs +152 -0
  26. package/dist/core/walker.d.mts +3 -10
  27. package/dist/core/walker.mjs +143 -231
  28. package/dist/html/a11y.d.mts +5 -4
  29. package/dist/html/renderToHtml.d.mts +3 -3
  30. package/dist/html/renderToHtml.mjs +23 -379
  31. package/dist/html/renderToHtmlStream.d.mts +29 -47
  32. package/dist/html/renderToHtmlStream.mjs +33 -305
  33. package/dist/html/renderers.d.mts +14 -0
  34. package/dist/html/renderers.mjs +406 -0
  35. package/dist/html/streamRenderers.d.mts +13 -0
  36. package/dist/html/streamRenderers.mjs +243 -0
  37. package/dist/openapi/components.d.mts +2 -1
  38. package/dist/openapi/parser.d.mts +59 -2
  39. package/dist/openapi/parser.mjs +189 -8
  40. package/dist/react/SchemaComponent.d.mts +4 -2
  41. package/dist/react/SchemaComponent.mjs +39 -85
  42. package/dist/react/SchemaView.d.mts +2 -1
  43. package/dist/react/SchemaView.mjs +21 -9
  44. package/dist/react/fieldPath.d.mts +20 -0
  45. package/dist/react/fieldPath.mjs +81 -0
  46. package/dist/react/headless.d.mts +2 -4
  47. package/dist/react/headless.mjs +3 -492
  48. package/dist/react/headlessRenderers.d.mts +23 -0
  49. package/dist/react/headlessRenderers.mjs +507 -0
  50. package/dist/renderer-DseHeliw.d.mts +160 -0
  51. package/dist/themes/mantine.d.mts +1 -1
  52. package/dist/themes/mantine.mjs +2 -1
  53. package/dist/themes/mui.d.mts +1 -1
  54. package/dist/themes/mui.mjs +2 -1
  55. package/dist/themes/radix.d.mts +1 -1
  56. package/dist/themes/radix.mjs +2 -1
  57. package/dist/themes/shadcn.d.mts +1 -1
  58. package/dist/themes/shadcn.mjs +10 -6
  59. package/dist/typeInference-CRPqVwKu.d.mts +299 -0
  60. package/dist/types-ag2jYLqQ.d.mts +261 -0
  61. package/dist/version-CLchheaH.d.mts +40 -0
  62. package/package.json +1 -1
  63. package/dist/types-BJzEgJdX.d.mts +0 -335
@@ -0,0 +1,223 @@
1
+ import { isObject } from "./guards.mjs";
2
+ //#region src/core/openapi30.ts
3
+ /**
4
+ * OpenAPI 3.0.x schema normalisation.
5
+ *
6
+ * Transforms `nullable`, `discriminator`, `example` keywords, and walks
7
+ * all schema locations (components, paths, parameters, request bodies,
8
+ * responses) to apply normalisation.
9
+ */
10
+ /**
11
+ * Normalise OpenAPI 3.0.x `nullable` keyword to `anyOf [T, null]`.
12
+ *
13
+ * OpenAPI 3.0 uses `nullable: true` instead of the JSON Schema standard
14
+ * `anyOf: [T, { type: "null" }]`. The walker understands the latter form
15
+ * natively, so this normaliser converts `nullable` to `anyOf`.
16
+ *
17
+ * Only applied when `nullable` is explicitly `true`. `nullable: false` or
18
+ * absent is the default and requires no transformation.
19
+ */
20
+ function normaliseOpenApi30Node(node) {
21
+ if ("example" in node && !("examples" in node)) {
22
+ node.examples = [node.example];
23
+ delete node.example;
24
+ } else if ("example" in node) delete node.example;
25
+ if (node.nullable !== true) {
26
+ if ("nullable" in node) delete node.nullable;
27
+ return node;
28
+ }
29
+ const nullOption = { type: "null" };
30
+ if (Array.isArray(node.anyOf)) {
31
+ node.anyOf = [...node.anyOf, nullOption];
32
+ delete node.nullable;
33
+ return node;
34
+ }
35
+ if (Array.isArray(node.oneOf)) {
36
+ node.anyOf = [...node.oneOf, nullOption];
37
+ delete node.oneOf;
38
+ delete node.nullable;
39
+ return node;
40
+ }
41
+ if (Array.isArray(node.allOf)) {
42
+ node.anyOf = [{ allOf: node.allOf }, nullOption];
43
+ delete node.allOf;
44
+ delete node.nullable;
45
+ return node;
46
+ }
47
+ const wrapper = {};
48
+ for (const [key, value] of Object.entries(node)) if (key !== "nullable") wrapper[key] = value;
49
+ return { anyOf: [wrapper, nullOption] };
50
+ }
51
+ /**
52
+ * Normalise OpenAPI 3.0.x `discriminator` keyword by injecting `const`
53
+ * values into each `oneOf`/`anyOf` option's discriminator property.
54
+ *
55
+ * In OpenAPI 3.0, `discriminator` is a sibling of `oneOf`/`anyOf`:
56
+ * discriminator: { propertyName: "type" }
57
+ * The walker detects discriminated unions from `oneOf` + `const` on a
58
+ * property, so this normaliser injects the `const` values from the
59
+ * `mapping` or infers them from `$ref` fragment names.
60
+ */
61
+ function normaliseOpenApi30Discriminator(node) {
62
+ const discriminator = node.discriminator;
63
+ if (!isObject(discriminator)) return node;
64
+ const propertyName = discriminator.propertyName;
65
+ if (typeof propertyName !== "string") return node;
66
+ const mapping = isObject(discriminator.mapping) ? discriminator.mapping : void 0;
67
+ const composite = node.oneOf ?? node.anyOf;
68
+ if (!Array.isArray(composite)) return node;
69
+ const refToValue = /* @__PURE__ */ new Map();
70
+ if (mapping !== void 0) {
71
+ for (const [value, ref] of Object.entries(mapping)) if (typeof ref === "string") refToValue.set(ref, value);
72
+ }
73
+ const normalisedComposite = [];
74
+ for (const option of composite) {
75
+ if (!isObject(option)) {
76
+ normalisedComposite.push(option);
77
+ continue;
78
+ }
79
+ const props = isObject(option.properties) ? { ...option.properties } : void 0;
80
+ const discProp = props?.[propertyName];
81
+ if (isObject(discProp) && "const" in discProp) {
82
+ normalisedComposite.push(option);
83
+ continue;
84
+ }
85
+ let constValue;
86
+ if (isObject(discProp) && typeof discProp.$ref === "string") constValue = refToValue.get(discProp.$ref);
87
+ if (constValue === void 0 && typeof option.$ref === "string") {
88
+ constValue = refToValue.get(option.$ref);
89
+ if (constValue === void 0) {
90
+ const fragment = option.$ref.split("/").pop();
91
+ if (fragment !== void 0) constValue = fragment;
92
+ }
93
+ }
94
+ if (constValue === void 0 && mapping !== void 0) {
95
+ const optionIndex = composite.indexOf(option);
96
+ const mappingEntries = Object.entries(mapping);
97
+ const entry = optionIndex >= 0 && optionIndex < mappingEntries.length ? mappingEntries[optionIndex] : void 0;
98
+ if (entry !== void 0) constValue = entry[0];
99
+ }
100
+ if (constValue !== void 0) {
101
+ const normalisedProps = props ?? {};
102
+ normalisedProps[propertyName] = {
103
+ ...isObject(discProp) ? discProp : {},
104
+ const: constValue
105
+ };
106
+ normalisedComposite.push({
107
+ ...option,
108
+ properties: normalisedProps
109
+ });
110
+ } else normalisedComposite.push(option);
111
+ }
112
+ if ("oneOf" in node) node.oneOf = normalisedComposite;
113
+ else if ("anyOf" in node) node.anyOf = normalisedComposite;
114
+ delete node.discriminator;
115
+ return node;
116
+ }
117
+ /**
118
+ * Combined OpenAPI 3.0.x node transform: nullable + discriminator.
119
+ * Applied to every schema node in an OpenAPI 3.0 document.
120
+ */
121
+ function normaliseOpenApi30Combined(node) {
122
+ return normaliseOpenApi30Discriminator(normaliseOpenApi30Node(node));
123
+ }
124
+ /**
125
+ * Deep-normalise all schemas in an OpenAPI 3.0.x document.
126
+ * Walks components/schemas, path operations, parameters, request bodies,
127
+ * and responses — applying `nullable` normalisation to each schema.
128
+ */
129
+ function deepNormaliseOpenApi30Doc(doc, deepNormalise) {
130
+ const result = { ...doc };
131
+ const components = doc.components;
132
+ if (isObject(components)) {
133
+ const schemas = components.schemas;
134
+ if (isObject(schemas)) {
135
+ const normalisedSchemas = {};
136
+ for (const [name, schema] of Object.entries(schemas)) normalisedSchemas[name] = isObject(schema) ? deepNormalise(schema, normaliseOpenApi30Combined) : schema;
137
+ result.components = {
138
+ ...components,
139
+ schemas: normalisedSchemas
140
+ };
141
+ }
142
+ }
143
+ const paths = doc.paths;
144
+ if (isObject(paths)) {
145
+ const normalisedPaths = {};
146
+ for (const [path, pathItem] of Object.entries(paths)) normalisedPaths[path] = isObject(pathItem) ? normalisePathItem(pathItem, deepNormalise) : pathItem;
147
+ result.paths = normalisedPaths;
148
+ }
149
+ return result;
150
+ }
151
+ function normalisePathItem(pathItem, deepNormalise) {
152
+ const result = { ...pathItem };
153
+ for (const method of [
154
+ "get",
155
+ "post",
156
+ "put",
157
+ "patch",
158
+ "delete"
159
+ ]) {
160
+ const operation = pathItem[method];
161
+ if (!isObject(operation)) continue;
162
+ result[method] = normaliseOperation(operation, deepNormalise);
163
+ }
164
+ const parameters = pathItem.parameters;
165
+ if (Array.isArray(parameters)) result.parameters = parameters.map((param) => isObject(param) ? normaliseParameter(param, deepNormalise) : param);
166
+ return result;
167
+ }
168
+ function normaliseOperation(operation, deepNormalise) {
169
+ const result = { ...operation };
170
+ const parameters = operation.parameters;
171
+ if (Array.isArray(parameters)) result.parameters = parameters.map((param) => isObject(param) ? normaliseParameter(param, deepNormalise) : param);
172
+ const requestBody = operation.requestBody;
173
+ if (isObject(requestBody)) result.requestBody = normaliseRequestBody(requestBody, deepNormalise);
174
+ const responses = operation.responses;
175
+ if (isObject(responses)) {
176
+ const normalisedResponses = {};
177
+ for (const [code, response] of Object.entries(responses)) normalisedResponses[code] = isObject(response) ? normaliseResponse(response, deepNormalise) : response;
178
+ result.responses = normalisedResponses;
179
+ }
180
+ return result;
181
+ }
182
+ function normaliseParameter(param, deepNormalise) {
183
+ const result = { ...param };
184
+ const schema = param.schema;
185
+ if (isObject(schema)) result.schema = deepNormalise(schema, normaliseOpenApi30Combined);
186
+ if ("example" in result && !("examples" in result)) {
187
+ result.examples = [result.example];
188
+ delete result.example;
189
+ } else if ("example" in result) delete result.example;
190
+ return result;
191
+ }
192
+ function normaliseRequestBody(requestBody, deepNormalise) {
193
+ const result = { ...requestBody };
194
+ const content = requestBody.content;
195
+ if (isObject(content)) result.content = normaliseContentMap(content, deepNormalise);
196
+ return result;
197
+ }
198
+ function normaliseResponse(response, deepNormalise) {
199
+ const result = { ...response };
200
+ const content = response.content;
201
+ if (isObject(content)) result.content = normaliseContentMap(content, deepNormalise);
202
+ return result;
203
+ }
204
+ function normaliseContentMap(content, deepNormalise) {
205
+ const result = {};
206
+ for (const [mediaType, mediaObj] of Object.entries(content)) {
207
+ if (!isObject(mediaObj)) {
208
+ result[mediaType] = mediaObj;
209
+ continue;
210
+ }
211
+ const normalised = { ...mediaObj };
212
+ const schema = mediaObj.schema;
213
+ if (isObject(schema)) normalised.schema = deepNormalise(schema, normaliseOpenApi30Combined);
214
+ if ("example" in normalised && !("examples" in normalised)) {
215
+ normalised.examples = { value: normalised.example };
216
+ delete normalised.example;
217
+ } else if ("example" in normalised) delete normalised.example;
218
+ result[mediaType] = normalised;
219
+ }
220
+ return result;
221
+ }
222
+ //#endregion
223
+ export { deepNormaliseOpenApi30Doc, normaliseOpenApi30Combined, normaliseOpenApi30Discriminator, normaliseOpenApi30Node };
@@ -0,0 +1,25 @@
1
+ //#region src/core/ref.d.ts
2
+ /**
3
+ * $ref resolution for JSON Schema.
4
+ *
5
+ * Handles JSON Pointer dereference, $anchor lookup, cycle detection,
6
+ * and maximum depth limiting.
7
+ */
8
+ /**
9
+ * Resolve a `$ref` in a schema against a root document.
10
+ * Returns the original schema if no `$ref` is present.
11
+ * Returns an unknown-schema placeholder on cycle or depth exceeded.
12
+ */
13
+ declare function resolveRef(schema: Record<string, unknown>, rootDocument: Record<string, unknown>, visited: Set<string>): Record<string, unknown>;
14
+ /**
15
+ * Dereference a JSON Pointer fragment (`#/path/to/schema`) or an
16
+ * `$anchor` (`#SomeName`) against a root document.
17
+ */
18
+ declare function dereference(ref: string, root: Record<string, unknown>): Record<string, unknown> | undefined;
19
+ /**
20
+ * Recursively scan a schema document for a `$anchor` matching the given name.
21
+ * Returns the schema object containing the anchor, or undefined.
22
+ */
23
+ declare function findAnchor(node: unknown, anchorName: string): Record<string, unknown> | undefined;
24
+ //#endregion
25
+ export { dereference, findAnchor, resolveRef };
@@ -0,0 +1,86 @@
1
+ import { isObject } from "./guards.mjs";
2
+ //#region src/core/ref.ts
3
+ /**
4
+ * $ref resolution for JSON Schema.
5
+ *
6
+ * Handles JSON Pointer dereference, $anchor lookup, cycle detection,
7
+ * and maximum depth limiting.
8
+ */
9
+ function getString(obj, key) {
10
+ const value = obj[key];
11
+ return typeof value === "string" ? value : void 0;
12
+ }
13
+ const MAX_REF_DEPTH = 10;
14
+ /**
15
+ * Resolve a `$ref` in a schema against a root document.
16
+ * Returns the original schema if no `$ref` is present.
17
+ * Returns an unknown-schema placeholder on cycle or depth exceeded.
18
+ */
19
+ function resolveRef(schema, rootDocument, visited) {
20
+ const ref = getString(schema, "$ref");
21
+ if (ref === void 0) return schema;
22
+ if (visited.has(ref)) return {
23
+ type: "unknown",
24
+ editability: "editable",
25
+ meta: {},
26
+ constraints: {}
27
+ };
28
+ if (visited.size >= MAX_REF_DEPTH) return {
29
+ type: "unknown",
30
+ editability: "editable",
31
+ meta: {},
32
+ constraints: {}
33
+ };
34
+ const resolved = dereference(ref, rootDocument);
35
+ if (resolved === void 0) return {
36
+ type: "unknown",
37
+ editability: "editable",
38
+ meta: {},
39
+ constraints: {}
40
+ };
41
+ const nextVisited = new Set(visited);
42
+ nextVisited.add(ref);
43
+ return resolveRef(resolved, rootDocument, nextVisited);
44
+ }
45
+ /**
46
+ * Dereference a JSON Pointer fragment (`#/path/to/schema`) or an
47
+ * `$anchor` (`#SomeName`) against a root document.
48
+ */
49
+ function dereference(ref, root) {
50
+ if (ref === "#") return root;
51
+ if (ref.startsWith("#/")) {
52
+ const parts = ref.slice(2).split("/");
53
+ if (parts.length === 1 && parts[0] === "") return root;
54
+ let current = root;
55
+ for (const part of parts) {
56
+ if (!isObject(current)) return void 0;
57
+ const decoded = part.replace(/~1/g, "/").replace(/~0/g, "~");
58
+ current = current[decoded];
59
+ }
60
+ return isObject(current) ? current : void 0;
61
+ }
62
+ if (ref.startsWith("#") && ref.length > 1) {
63
+ const found = findAnchor(root, ref.slice(1));
64
+ if (found !== void 0) return found;
65
+ }
66
+ }
67
+ /**
68
+ * Recursively scan a schema document for a `$anchor` matching the given name.
69
+ * Returns the schema object containing the anchor, or undefined.
70
+ */
71
+ function findAnchor(node, anchorName) {
72
+ if (!isObject(node)) return void 0;
73
+ if (node.$anchor === anchorName) return node;
74
+ for (const value of Object.values(node)) {
75
+ if (isObject(value)) {
76
+ const found = findAnchor(value, anchorName);
77
+ if (found !== void 0) return found;
78
+ }
79
+ if (Array.isArray(value)) for (const item of value) {
80
+ const found = findAnchor(item, anchorName);
81
+ if (found !== void 0) return found;
82
+ }
83
+ }
84
+ }
85
+ //#endregion
86
+ export { dereference, findAnchor, resolveRef };
@@ -1,2 +1,2 @@
1
- import { A as mergeResolvers, C as HtmlResolver, D as getHtmlRenderFn, E as RenderProps, O as getRenderFunction, S as HtmlRenderProps, T as RenderFunction, b as ComponentResolver, j as typeToKey, k as mergeHtmlResolvers, w as RESOLVER_KEYS, x as HtmlRenderFunction, y as BaseFieldProps } from "../types-BJzEgJdX.mjs";
2
- export { BaseFieldProps, ComponentResolver, HtmlRenderFunction, HtmlRenderProps, HtmlResolver, RESOLVER_KEYS, RenderFunction, RenderProps, getHtmlRenderFn, getRenderFunction, mergeHtmlResolvers, mergeResolvers, typeToKey };
1
+ import { a as HtmlRenderProps, c as RenderFunction, d as getRenderFunction, f as mergeHtmlResolvers, i as HtmlRenderFunction, l as RenderProps, m as typeToKey, n as BaseFieldProps, o as HtmlResolver, p as mergeResolvers, r as ComponentResolver, s as RESOLVER_KEYS, t as AllConstraints, u as getHtmlRenderFn } from "../renderer-DseHeliw.mjs";
2
+ export { AllConstraints, BaseFieldProps, ComponentResolver, HtmlRenderFunction, HtmlRenderProps, HtmlResolver, RESOLVER_KEYS, RenderFunction, RenderProps, getHtmlRenderFn, getRenderFunction, mergeHtmlResolvers, mergeResolvers, typeToKey };
@@ -6,9 +6,13 @@ const RESOLVER_KEYS = [
6
6
  "enum",
7
7
  "object",
8
8
  "array",
9
+ "tuple",
9
10
  "record",
10
11
  "union",
11
12
  "discriminatedUnion",
13
+ "conditional",
14
+ "negation",
15
+ "recursive",
12
16
  "literal",
13
17
  "file",
14
18
  "unknown"
@@ -25,9 +29,13 @@ function typeToKey(type) {
25
29
  case "enum":
26
30
  case "object":
27
31
  case "array":
32
+ case "tuple":
28
33
  case "record":
29
34
  case "union":
30
35
  case "discriminatedUnion":
36
+ case "conditional":
37
+ case "negation":
38
+ case "recursive":
31
39
  case "literal":
32
40
  case "file":
33
41
  case "unknown": return type;
@@ -0,0 +1,10 @@
1
+ import { NodeTransform } from "./normalise.mjs";
2
+
3
+ //#region src/core/swagger2.d.ts
4
+ /**
5
+ * Transform a Swagger 2.0 document into an OpenAPI 3.1-compatible
6
+ * structure.
7
+ */
8
+ declare function normaliseSwagger2Document(doc: Record<string, unknown>, deepNormalise: (schema: Record<string, unknown>, transform: NodeTransform) => Record<string, unknown>, normaliseDraft04Node: NodeTransform): Record<string, unknown>;
9
+ //#endregion
10
+ export { normaliseSwagger2Document };
@@ -0,0 +1,294 @@
1
+ import { isObject } from "./guards.mjs";
2
+ import { normaliseOpenApi30Combined } from "./openapi30.mjs";
3
+ //#region src/core/swagger2.ts
4
+ /**
5
+ * Swagger 2.0 → OpenAPI 3.1 document normalisation.
6
+ *
7
+ * Transforms a Swagger 2.0 document into an OpenAPI 3.1-compatible
8
+ * structure: host/basePath/schemes → servers, definitions → components,
9
+ * body/formData params → requestBody, response schemas → content.
10
+ *
11
+ * Individual schemas within the document are also normalised for
12
+ * Draft 04 semantics (exclusiveMinimum/exclusiveMaximum booleans).
13
+ */
14
+ /**
15
+ * Transform a Swagger 2.0 document into an OpenAPI 3.1-compatible
16
+ * structure.
17
+ */
18
+ function normaliseSwagger2Document(doc, deepNormalise, normaliseDraft04Node) {
19
+ const result = {
20
+ openapi: "3.1.0",
21
+ info: isObject(doc.info) ? { ...doc.info } : {
22
+ title: "API",
23
+ version: "0.0.0"
24
+ }
25
+ };
26
+ if (typeof doc.host === "string" || typeof doc.basePath === "string" || Array.isArray(doc.schemes)) {
27
+ const host = typeof doc.host === "string" ? doc.host : "localhost";
28
+ const basePath = typeof doc.basePath === "string" ? doc.basePath : "/";
29
+ const schemes = Array.isArray(doc.schemes) ? doc.schemes : ["https"];
30
+ result.servers = [{ url: `${typeof schemes[0] === "string" ? schemes[0] : "https"}://${host}${basePath}` }];
31
+ }
32
+ const paths = doc.paths;
33
+ if (isObject(paths)) result.paths = normaliseSwaggerPaths(paths, doc);
34
+ const components = {};
35
+ const definitions = doc.definitions;
36
+ if (isObject(definitions)) {
37
+ const schemas = {};
38
+ for (const [name, schema] of Object.entries(definitions)) schemas[name] = isObject(schema) ? deepNormalise(schema, (node) => normaliseOpenApi30Combined(normaliseDraft04Node(node))) : schema;
39
+ components.schemas = schemas;
40
+ }
41
+ const parameters = doc.parameters;
42
+ if (isObject(parameters)) components.parameters = { ...parameters };
43
+ const responses = doc.responses;
44
+ if (isObject(responses)) components.responses = { ...responses };
45
+ const securityDefinitions = doc.securityDefinitions;
46
+ if (isObject(securityDefinitions)) components.securitySchemes = { ...securityDefinitions };
47
+ if (Object.keys(components).length > 0) result.components = components;
48
+ if (Array.isArray(doc.tags)) result.tags = doc.tags;
49
+ if (isObject(doc.externalDocs)) result.externalDocs = doc.externalDocs;
50
+ rewriteSwaggerRefs(result);
51
+ return result;
52
+ }
53
+ function normaliseSwaggerPaths(paths, doc) {
54
+ const result = {};
55
+ const METHODS = [
56
+ "get",
57
+ "post",
58
+ "put",
59
+ "patch",
60
+ "delete",
61
+ "head",
62
+ "options"
63
+ ];
64
+ for (const [path, pathItem] of Object.entries(paths)) {
65
+ if (!isObject(pathItem)) {
66
+ result[path] = pathItem;
67
+ continue;
68
+ }
69
+ const normalisedPath = {};
70
+ for (const method of METHODS) {
71
+ const operation = pathItem[method];
72
+ if (!isObject(operation)) continue;
73
+ normalisedPath[method] = normaliseSwaggerOperation(operation, doc);
74
+ }
75
+ const pathParams = pathItem.parameters;
76
+ if (Array.isArray(pathParams)) normalisedPath.parameters = pathParams.map((p) => isObject(p) ? normaliseSwaggerParameter(p, doc) : p);
77
+ result[path] = normalisedPath;
78
+ }
79
+ return result;
80
+ }
81
+ function normaliseSwaggerOperation(operation, doc) {
82
+ const result = {};
83
+ const globalProduces = Array.isArray(doc.produces) ? doc.produces : ["application/json"];
84
+ const globalConsumes = Array.isArray(doc.consumes) ? doc.consumes : ["application/json"];
85
+ const produces = Array.isArray(operation.produces) ? operation.produces : globalProduces;
86
+ const consumes = Array.isArray(operation.consumes) ? operation.consumes : globalConsumes;
87
+ for (const [key, value] of Object.entries(operation)) if (key !== "parameters" && key !== "responses" && key !== "produces" && key !== "consumes") result[key] = value;
88
+ const params = operation.parameters;
89
+ if (Array.isArray(params)) {
90
+ const nonBodyParams = [];
91
+ let bodyParam;
92
+ let usesFormData = false;
93
+ for (const param of params) {
94
+ if (!isObject(param)) {
95
+ nonBodyParams.push(param);
96
+ continue;
97
+ }
98
+ const resolvedParam = resolveSwaggerParameter(param, doc);
99
+ const location = resolvedParam.in;
100
+ if (location === "body") bodyParam = resolvedParam;
101
+ else if (location === "formData") {
102
+ bodyParam = buildFormDataBody(resolvedParam, params);
103
+ usesFormData = true;
104
+ } else nonBodyParams.push(normaliseSwaggerParameter(resolvedParam, doc));
105
+ }
106
+ if (nonBodyParams.length > 0) result.parameters = nonBodyParams;
107
+ if (bodyParam !== void 0) result.requestBody = buildRequestBody(bodyParam, usesFormData ? ["multipart/form-data"] : consumes);
108
+ }
109
+ const responses = operation.responses;
110
+ if (isObject(responses)) result.responses = normaliseSwaggerResponses(responses, doc, produces);
111
+ return result;
112
+ }
113
+ /**
114
+ * Resolve a Swagger parameter that may be a `$ref`.
115
+ */
116
+ function resolveSwaggerParameter(param, doc, visited = /* @__PURE__ */ new Set()) {
117
+ const ref = param.$ref;
118
+ if (typeof ref !== "string" || !ref.startsWith("#/parameters/")) return param;
119
+ if (visited.has(ref)) return param;
120
+ const nextVisited = new Set(visited);
121
+ nextVisited.add(ref);
122
+ const name = ref.slice(13);
123
+ const globalParams = doc.parameters;
124
+ if (isObject(globalParams)) {
125
+ const resolved = globalParams[name];
126
+ if (isObject(resolved)) {
127
+ if (typeof resolved.$ref === "string") return resolveSwaggerParameter(resolved, doc, nextVisited);
128
+ return resolved;
129
+ }
130
+ }
131
+ return param;
132
+ }
133
+ /**
134
+ * Normalise a single Swagger parameter to OpenAPI 3.x form.
135
+ */
136
+ function normaliseSwaggerParameter(param, doc) {
137
+ if (typeof param.$ref === "string") {
138
+ const resolved = resolveSwaggerParameter(param, doc);
139
+ if (resolved !== param) return normaliseSwaggerParameter(resolved, doc);
140
+ }
141
+ const result = {};
142
+ for (const [key, value] of Object.entries(param)) {
143
+ if (key === "type" || key === "format" || key === "collectionFormat") continue;
144
+ result[key] = value;
145
+ }
146
+ if (typeof param.type === "string") {
147
+ const schema = { type: param.type };
148
+ if (typeof param.format === "string") schema.format = param.format;
149
+ if (param.enum !== void 0) schema.enum = param.enum;
150
+ if (param.default !== void 0) schema.default = param.default;
151
+ if (param.minimum !== void 0) schema.minimum = param.minimum;
152
+ if (param.maximum !== void 0) schema.maximum = param.maximum;
153
+ result.schema = schema;
154
+ }
155
+ const cf = param.collectionFormat;
156
+ if (typeof cf === "string") switch (cf) {
157
+ case "csv":
158
+ result.style = "form";
159
+ result.explode = false;
160
+ break;
161
+ case "ssv":
162
+ result.style = "spaceDelimited";
163
+ result.explode = false;
164
+ break;
165
+ case "tsv":
166
+ result.style = "tabDelimited";
167
+ result.explode = false;
168
+ break;
169
+ case "pipes":
170
+ result.style = "pipeDelimited";
171
+ result.explode = false;
172
+ break;
173
+ case "multi":
174
+ result.style = "form";
175
+ result.explode = true;
176
+ break;
177
+ }
178
+ return result;
179
+ }
180
+ /**
181
+ * Build a request body from a `formData` parameter.
182
+ */
183
+ function buildFormDataBody(param, allParams) {
184
+ const properties = {};
185
+ const required = [];
186
+ for (const p of allParams) {
187
+ if (!isObject(p) || p.in !== "formData") continue;
188
+ const name = p.name;
189
+ if (typeof name !== "string") continue;
190
+ const schema = {};
191
+ if (p.type === "file") {
192
+ schema.type = "string";
193
+ schema.format = "binary";
194
+ } else {
195
+ if (typeof p.type === "string") schema.type = p.type;
196
+ if (typeof p.format === "string") schema.format = p.format;
197
+ if (p.enum !== void 0) schema.enum = p.enum;
198
+ }
199
+ properties[name] = schema;
200
+ if (p.required === true) required.push(name);
201
+ }
202
+ return {
203
+ name: param.name,
204
+ in: "body",
205
+ schema: {
206
+ type: "object",
207
+ properties,
208
+ ...required.length > 0 ? { required } : {}
209
+ }
210
+ };
211
+ }
212
+ /**
213
+ * Build an OpenAPI 3.x request body from a Swagger 2.0 body parameter.
214
+ */
215
+ function buildRequestBody(bodyParam, consumes) {
216
+ const schema = bodyParam.schema;
217
+ const content = {};
218
+ const contentTypes = consumes.length > 0 ? consumes : ["application/json"];
219
+ for (const ct of contentTypes) if (typeof ct === "string") content[ct] = isObject(schema) ? { schema } : {};
220
+ const result = { content };
221
+ if (bodyParam.required === true) result.required = true;
222
+ if (typeof bodyParam.description === "string") result.description = bodyParam.description;
223
+ return result;
224
+ }
225
+ /**
226
+ * Resolve a Swagger 2.0 response `$ref` (e.g. `#/responses/NotFound`).
227
+ */
228
+ function resolveSwaggerResponse(response, doc, visited = /* @__PURE__ */ new Set()) {
229
+ const ref = response.$ref;
230
+ if (typeof ref !== "string" || !ref.startsWith("#/responses/")) return response;
231
+ if (visited.has(ref)) return response;
232
+ const nextVisited = new Set(visited);
233
+ nextVisited.add(ref);
234
+ const name = ref.slice(12);
235
+ const globalResponses = doc.responses;
236
+ if (isObject(globalResponses)) {
237
+ const resolved = globalResponses[name];
238
+ if (isObject(resolved)) {
239
+ if (typeof resolved.$ref === "string") return resolveSwaggerResponse(resolved, doc, nextVisited);
240
+ return resolved;
241
+ }
242
+ }
243
+ return response;
244
+ }
245
+ function normaliseSwaggerResponses(responses, doc, produces) {
246
+ const result = {};
247
+ for (const [code, response] of Object.entries(responses)) {
248
+ if (!isObject(response)) {
249
+ result[code] = response;
250
+ continue;
251
+ }
252
+ const resolved = resolveSwaggerResponse(response, doc);
253
+ const normalised = {};
254
+ for (const [key, value] of Object.entries(resolved)) if (key !== "schema") normalised[key] = value;
255
+ const schema = resolved.schema;
256
+ if (isObject(schema)) {
257
+ const content = {};
258
+ const contentTypes = produces.length > 0 ? produces : ["application/json"];
259
+ for (const ct of contentTypes) if (typeof ct === "string") content[ct] = { schema };
260
+ normalised.content = content;
261
+ }
262
+ result[code] = normalised;
263
+ }
264
+ return result;
265
+ }
266
+ /**
267
+ * Mapping of Swagger 2.0 $ref prefixes to OpenAPI 3.x equivalents.
268
+ * Applied after document restructuring so all $ref strings point
269
+ * to the correct locations in the normalised document.
270
+ */
271
+ const REF_REWRITES = [
272
+ ["#/definitions/", "#/components/schemas/"],
273
+ ["#/parameters/", "#/components/parameters/"],
274
+ ["#/responses/", "#/components/responses/"]
275
+ ];
276
+ /**
277
+ * Deep-rewrite $ref strings in a normalised Swagger 2.0 document
278
+ * from Swagger 2.0 locations to OpenAPI 3.x locations.
279
+ * Mutates the object in place \u2014 called only on the fresh clone
280
+ * produced by normaliseSwagger2Document.
281
+ */
282
+ function rewriteSwaggerRefs(node) {
283
+ if (!isObject(node)) return;
284
+ if (typeof node.$ref === "string") {
285
+ for (const [from, to] of REF_REWRITES) if (node.$ref.startsWith(from)) {
286
+ node.$ref = to + node.$ref.slice(from.length);
287
+ break;
288
+ }
289
+ }
290
+ for (const value of Object.values(node)) if (isObject(value)) rewriteSwaggerRefs(value);
291
+ else if (Array.isArray(value)) for (const item of value) rewriteSwaggerRefs(item);
292
+ }
293
+ //#endregion
294
+ export { normaliseSwagger2Document };
@@ -0,0 +1,2 @@
1
+ import { a as OpenAPIRequestBodyType, c as ResolveOpenAPIRef, i as InferResponseFields, l as TypeAtPath, n as InferParameterOverrides, o as OpenAPIResponseType, r as InferRequestBodyFields, s as PathOfType, t as FromJSONSchema } from "../typeInference-CRPqVwKu.mjs";
2
+ export { FromJSONSchema, InferParameterOverrides, InferRequestBodyFields, InferResponseFields, OpenAPIRequestBodyType, OpenAPIResponseType, PathOfType, ResolveOpenAPIRef, TypeAtPath };
@@ -0,0 +1 @@
1
+ export {};