schema-components 1.13.0 → 1.15.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/README.md +4 -0
- package/dist/core/adapter.d.mts +8 -3
- package/dist/core/adapter.mjs +25 -10
- package/dist/core/constraints.d.mts +3 -2
- package/dist/core/constraints.mjs +14 -2
- package/dist/core/diagnostics.d.mts +2 -0
- package/dist/core/diagnostics.mjs +33 -0
- package/dist/core/errors.d.mts +1 -1
- package/dist/core/formats.d.mts +33 -0
- package/dist/core/formats.mjs +67 -0
- package/dist/core/merge.d.mts +17 -1
- package/dist/core/merge.mjs +30 -1
- package/dist/core/normalise.d.mts +3 -2
- package/dist/core/normalise.mjs +1 -170
- package/dist/core/openapi30.d.mts +4 -1
- package/dist/core/openapi30.mjs +1 -222
- package/dist/core/ref.d.mts +2 -25
- package/dist/core/ref.mjs +102 -23
- package/dist/core/renderer.d.mts +1 -1
- package/dist/core/swagger2.d.mts +2 -1
- package/dist/core/swagger2.mjs +1 -293
- package/dist/core/typeInference.d.mts +2 -2
- package/dist/core/types.d.mts +2 -2
- package/dist/core/types.mjs +4 -1
- package/dist/core/version.d.mts +2 -2
- package/dist/core/version.mjs +84 -12
- package/dist/core/walkBuilders.d.mts +15 -1
- package/dist/core/walkBuilders.mjs +1 -1
- package/dist/core/walker.d.mts +1 -1
- package/dist/core/walker.mjs +122 -22
- package/dist/diagnostics-DzbZmcLI.d.mts +64 -0
- package/dist/html/a11y.d.mts +2 -2
- package/dist/html/renderToHtml.d.mts +2 -2
- package/dist/html/renderToHtmlStream.d.mts +2 -2
- package/dist/html/renderers.d.mts +2 -2
- package/dist/html/streamRenderers.d.mts +2 -2
- package/dist/normalise-tL9FckAk.mjs +748 -0
- package/dist/openapi/ApiCallbacks.d.mts +16 -0
- package/dist/openapi/ApiCallbacks.mjs +34 -0
- package/dist/openapi/ApiLinks.d.mts +16 -0
- package/dist/openapi/ApiLinks.mjs +42 -0
- package/dist/openapi/ApiResponseHeaders.d.mts +16 -0
- package/dist/openapi/ApiResponseHeaders.mjs +35 -0
- package/dist/openapi/ApiSecurity.d.mts +19 -0
- package/dist/openapi/ApiSecurity.mjs +33 -0
- package/dist/openapi/bundle.d.mts +47 -0
- package/dist/openapi/bundle.mjs +95 -0
- package/dist/openapi/components.d.mts +7 -2
- package/dist/openapi/components.mjs +30 -6
- package/dist/openapi/parser.d.mts +1 -1
- package/dist/react/SchemaComponent.d.mts +12 -5
- package/dist/react/SchemaComponent.mjs +13 -7
- package/dist/react/SchemaView.d.mts +10 -3
- package/dist/react/SchemaView.mjs +13 -7
- package/dist/react/fieldPath.d.mts +1 -1
- package/dist/react/headless.d.mts +1 -1
- package/dist/react/headlessRenderers.d.mts +1 -1
- package/dist/react/headlessRenderers.mjs +1 -1
- package/dist/ref-DvWoULcy.d.mts +44 -0
- package/dist/{renderer-DseHeliw.d.mts → renderer-BdSqllx5.d.mts} +1 -1
- package/dist/themes/mantine.d.mts +1 -1
- package/dist/themes/mui.d.mts +1 -1
- package/dist/themes/mui.mjs +1 -1
- package/dist/themes/radix.d.mts +1 -1
- package/dist/themes/shadcn.d.mts +1 -1
- package/dist/{typeInference-CRPqVwKu.d.mts → typeInference-k7FXfTVO.d.mts} +44 -8
- package/dist/{types-ag2jYLqQ.d.mts → types-D_5ST7SS.d.mts} +11 -3
- package/dist/version-B5NV-35j.d.mts +69 -0
- package/package.json +1 -1
- package/dist/version-CLchheaH.d.mts +0 -40
- /package/dist/{errors-DIKI2C78.d.mts → errors-C5zRC2PU.d.mts} +0 -0
package/dist/core/openapi30.mjs
CHANGED
|
@@ -1,223 +1,2 @@
|
|
|
1
|
-
import {
|
|
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
|
|
1
|
+
import { c as normaliseOpenApi30Discriminator, l as normaliseOpenApi30Node, o as deepNormaliseOpenApi30Doc, s as normaliseOpenApi30Combined } from "../normalise-tL9FckAk.mjs";
|
|
223
2
|
export { deepNormaliseOpenApi30Doc, normaliseOpenApi30Combined, normaliseOpenApi30Discriminator, normaliseOpenApi30Node };
|
package/dist/core/ref.d.mts
CHANGED
|
@@ -1,25 +1,2 @@
|
|
|
1
|
-
|
|
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 };
|
|
1
|
+
import { a as findAnchor, i as dereference, n as RefOptions, o as resolveRef, r as countDistinctRefs, t as ExternalResolver } from "../ref-DvWoULcy.mjs";
|
|
2
|
+
export { ExternalResolver, RefOptions, countDistinctRefs, dereference, findAnchor, resolveRef };
|
package/dist/core/ref.mjs
CHANGED
|
@@ -1,46 +1,125 @@
|
|
|
1
1
|
import { isObject } from "./guards.mjs";
|
|
2
|
+
import { emitDiagnostic } from "./diagnostics.mjs";
|
|
2
3
|
//#region src/core/ref.ts
|
|
3
4
|
/**
|
|
4
5
|
* $ref resolution for JSON Schema.
|
|
5
6
|
*
|
|
6
7
|
* Handles JSON Pointer dereference, $anchor lookup, cycle detection,
|
|
7
|
-
* and
|
|
8
|
+
* and depth limiting derived from the document's own $ref count.
|
|
8
9
|
*/
|
|
9
10
|
function getString(obj, key) {
|
|
10
11
|
const value = obj[key];
|
|
11
12
|
return typeof value === "string" ? value : void 0;
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Count all distinct `$ref` strings reachable from a root document.
|
|
16
|
+
* A chain longer than the number of distinct refs is necessarily cyclic.
|
|
17
|
+
* Returns at least 1 so that single-ref schemas have a usable bound.
|
|
18
|
+
*/
|
|
19
|
+
function countDistinctRefs(root) {
|
|
20
|
+
const refs = /* @__PURE__ */ new Set();
|
|
21
|
+
collectRefs(root, refs);
|
|
22
|
+
return Math.max(refs.size, 1);
|
|
23
|
+
}
|
|
24
|
+
function collectRefs(node, refs) {
|
|
25
|
+
if (!isObject(node)) return;
|
|
26
|
+
const ref = node.$ref;
|
|
27
|
+
if (typeof ref === "string") refs.add(ref);
|
|
28
|
+
for (const value of Object.values(node)) if (isObject(value)) collectRefs(value, refs);
|
|
29
|
+
else if (Array.isArray(value)) for (const item of value) collectRefs(item, refs);
|
|
30
|
+
}
|
|
14
31
|
/**
|
|
15
32
|
* Resolve a `$ref` in a schema against a root document.
|
|
16
33
|
* Returns the original schema if no `$ref` is present.
|
|
17
34
|
* Returns an unknown-schema placeholder on cycle or depth exceeded.
|
|
35
|
+
*
|
|
36
|
+
* The depth bound is derived from the number of distinct `$ref` strings
|
|
37
|
+
* in the root document — a chain longer than that count is necessarily
|
|
38
|
+
* cyclic. When `maxDepth` is not provided, a reasonable default is used.
|
|
18
39
|
*/
|
|
19
|
-
function resolveRef(schema, rootDocument, visited) {
|
|
40
|
+
function resolveRef(schema, rootDocument, visited, diagnostics, maxDepth, externalResolver) {
|
|
20
41
|
const ref = getString(schema, "$ref");
|
|
21
42
|
if (ref === void 0) return schema;
|
|
22
|
-
if (visited.has(ref))
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
43
|
+
if (visited.has(ref)) {
|
|
44
|
+
emitDiagnostic(diagnostics, {
|
|
45
|
+
code: "unresolved-ref",
|
|
46
|
+
message: `Circular $ref detected: ${ref}`,
|
|
47
|
+
pointer: ref,
|
|
48
|
+
detail: { ref }
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
type: "unknown",
|
|
52
|
+
editability: "editable",
|
|
53
|
+
meta: {},
|
|
54
|
+
constraints: {}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const depthLimit = maxDepth ?? 64;
|
|
58
|
+
if (visited.size >= depthLimit) {
|
|
59
|
+
emitDiagnostic(diagnostics, {
|
|
60
|
+
code: "depth-exceeded",
|
|
61
|
+
message: `$ref depth exceeded derived bound (${String(depthLimit)}): ${ref}`,
|
|
62
|
+
pointer: ref,
|
|
63
|
+
detail: {
|
|
64
|
+
ref,
|
|
65
|
+
depth: visited.size,
|
|
66
|
+
bound: depthLimit
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
type: "unknown",
|
|
71
|
+
editability: "editable",
|
|
72
|
+
meta: {},
|
|
73
|
+
constraints: {}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (!ref.startsWith("#") && externalResolver !== void 0) {
|
|
77
|
+
const hashIndex = ref.indexOf("#");
|
|
78
|
+
const uri = hashIndex >= 0 ? ref.slice(0, hashIndex) : ref;
|
|
79
|
+
const fragment = hashIndex >= 0 ? ref.slice(hashIndex) : "#";
|
|
80
|
+
const externalDoc = externalResolver(uri);
|
|
81
|
+
if (isObject(externalDoc)) {
|
|
82
|
+
const target = dereference(fragment, externalDoc);
|
|
83
|
+
if (target !== void 0) {
|
|
84
|
+
const nextVisited = new Set(visited);
|
|
85
|
+
nextVisited.add(ref);
|
|
86
|
+
return resolveRef(target, externalDoc, nextVisited, diagnostics, maxDepth, externalResolver);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
emitDiagnostic(diagnostics, {
|
|
90
|
+
code: "external-ref",
|
|
91
|
+
message: `External resolver returned no document for: ${ref}`,
|
|
92
|
+
pointer: ref,
|
|
93
|
+
detail: {
|
|
94
|
+
ref,
|
|
95
|
+
uri
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
type: "unknown",
|
|
100
|
+
editability: "editable",
|
|
101
|
+
meta: {},
|
|
102
|
+
constraints: {}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
34
105
|
const resolved = dereference(ref, rootDocument);
|
|
35
|
-
if (resolved === void 0)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
106
|
+
if (resolved === void 0) {
|
|
107
|
+
emitDiagnostic(diagnostics, {
|
|
108
|
+
code: "unresolved-ref",
|
|
109
|
+
message: `Could not resolve $ref: ${ref}`,
|
|
110
|
+
pointer: ref,
|
|
111
|
+
detail: { ref }
|
|
112
|
+
});
|
|
113
|
+
return {
|
|
114
|
+
type: "unknown",
|
|
115
|
+
editability: "editable",
|
|
116
|
+
meta: {},
|
|
117
|
+
constraints: {}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
41
120
|
const nextVisited = new Set(visited);
|
|
42
121
|
nextVisited.add(ref);
|
|
43
|
-
return resolveRef(resolved, rootDocument, nextVisited);
|
|
122
|
+
return resolveRef(resolved, rootDocument, nextVisited, diagnostics, maxDepth, externalResolver);
|
|
44
123
|
}
|
|
45
124
|
/**
|
|
46
125
|
* Dereference a JSON Pointer fragment (`#/path/to/schema`) or an
|
|
@@ -83,4 +162,4 @@ function findAnchor(node, anchorName) {
|
|
|
83
162
|
}
|
|
84
163
|
}
|
|
85
164
|
//#endregion
|
|
86
|
-
export { dereference, findAnchor, resolveRef };
|
|
165
|
+
export { countDistinctRefs, dereference, findAnchor, resolveRef };
|
package/dist/core/renderer.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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-
|
|
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-BdSqllx5.mjs";
|
|
2
2
|
export { AllConstraints, BaseFieldProps, ComponentResolver, HtmlRenderFunction, HtmlRenderProps, HtmlResolver, RESOLVER_KEYS, RenderFunction, RenderProps, getHtmlRenderFn, getRenderFunction, mergeHtmlResolvers, mergeResolvers, typeToKey };
|
package/dist/core/swagger2.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { i as DiagnosticsOptions } from "../diagnostics-DzbZmcLI.mjs";
|
|
1
2
|
import { NodeTransform } from "./normalise.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/core/swagger2.d.ts
|
|
@@ -5,6 +6,6 @@ import { NodeTransform } from "./normalise.mjs";
|
|
|
5
6
|
* Transform a Swagger 2.0 document into an OpenAPI 3.1-compatible
|
|
6
7
|
* structure.
|
|
7
8
|
*/
|
|
8
|
-
declare function normaliseSwagger2Document(doc: Record<string, unknown>, deepNormalise: (schema: Record<string, unknown>, transform: NodeTransform) => Record<string, unknown>, normaliseDraft04Node: NodeTransform): Record<string, unknown>;
|
|
9
|
+
declare function normaliseSwagger2Document(doc: Record<string, unknown>, deepNormalise: (schema: Record<string, unknown>, transform: NodeTransform) => Record<string, unknown>, normaliseDraft04Node: NodeTransform, diagnostics?: DiagnosticsOptions): Record<string, unknown>;
|
|
9
10
|
//#endregion
|
|
10
11
|
export { normaliseSwagger2Document };
|