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/swagger2.mjs
CHANGED
|
@@ -1,294 +1,2 @@
|
|
|
1
|
-
import {
|
|
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
|
|
1
|
+
import { a as normaliseSwagger2Document } from "../normalise-tL9FckAk.mjs";
|
|
294
2
|
export { normaliseSwagger2Document };
|
|
@@ -1,2 +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-
|
|
2
|
-
export { FromJSONSchema, InferParameterOverrides, InferRequestBodyFields, InferResponseFields, OpenAPIRequestBodyType, OpenAPIResponseType, PathOfType, ResolveOpenAPIRef, TypeAtPath };
|
|
1
|
+
import { a as OpenAPIRequestBodyType, c as ResolveOpenAPIRef, d as __SchemaInferenceFellBack, i as InferResponseFields, l as TypeAtPath, n as InferParameterOverrides, o as OpenAPIResponseType, r as InferRequestBodyFields, s as PathOfType, t as FromJSONSchema, u as UnsafeFields } from "../typeInference-k7FXfTVO.mjs";
|
|
2
|
+
export { FromJSONSchema, InferParameterOverrides, InferRequestBodyFields, InferResponseFields, OpenAPIRequestBodyType, OpenAPIResponseType, PathOfType, ResolveOpenAPIRef, TypeAtPath, UnsafeFields, __SchemaInferenceFellBack };
|
package/dist/core/types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
export { ArrayConstraints, ArrayField, BooleanField, ConditionalField, DiscriminatedUnionField, Editability, EnumField, FieldBase, FieldConstraints, FieldOverride, FieldOverrides, FileConstraints, FileField, JsonObject, LiteralField, NegationField, NullField, NumberConstraints, NumberField, ObjectConstraints, ObjectField, RecordField, RecursiveField, SchemaMeta, SchemaType, StringConstraints, StringField, TupleField, UnionField, UnknownField, WalkedField, isArrayField, isBooleanField, isConditionalField, isDiscriminatedUnionField, isEnumField, isFileField, isLiteralField, isNegationField, isNullField, isNumberField, isObjectField, isRecordField, isRecursiveField, isStringField, isTupleField, isUnionField, isUnknownField, resolveEditability };
|
|
1
|
+
import { A as UnionField, B as isNegationField, C as RecordField, D as StringConstraints, E as SchemaType, F as isConditionalField, G as isRecordField, H as isNullField, I as isDiscriminatedUnionField, J as isTupleField, K as isRecursiveField, L as isEnumField, M as WalkedField, N as isArrayField, O as StringField, P as isBooleanField, R as isFileField, S as ObjectField, T as SchemaMeta, U as isNumberField, V as isNeverField, W as isObjectField, X as isUnknownField, Y as isUnionField, Z as resolveEditability, _ as NeverField, a as DiscriminatedUnionField, b as NumberField, c as FieldBase, d as FieldOverrides, f as FileConstraints, g as NegationField, h as LiteralField, i as ConditionalField, j as UnknownField, k as TupleField, l as FieldConstraints, m as JsonObject, n as ArrayField, o as Editability, p as FileField, q as isStringField, r as BooleanField, s as EnumField, t as ArrayConstraints, u as FieldOverride, v as NullField, w as RecursiveField, x as ObjectConstraints, y as NumberConstraints, z as isLiteralField } from "../types-D_5ST7SS.mjs";
|
|
2
|
+
export { ArrayConstraints, ArrayField, BooleanField, ConditionalField, DiscriminatedUnionField, Editability, EnumField, FieldBase, FieldConstraints, FieldOverride, FieldOverrides, FileConstraints, FileField, JsonObject, LiteralField, NegationField, NeverField, NullField, NumberConstraints, NumberField, ObjectConstraints, ObjectField, RecordField, RecursiveField, SchemaMeta, SchemaType, StringConstraints, StringField, TupleField, UnionField, UnknownField, WalkedField, isArrayField, isBooleanField, isConditionalField, isDiscriminatedUnionField, isEnumField, isFileField, isLiteralField, isNegationField, isNeverField, isNullField, isNumberField, isObjectField, isRecordField, isRecursiveField, isStringField, isTupleField, isUnionField, isUnknownField, resolveEditability };
|
package/dist/core/types.mjs
CHANGED
|
@@ -86,8 +86,11 @@ function isFileField(field) {
|
|
|
86
86
|
function isRecursiveField(field) {
|
|
87
87
|
return isField(field, "recursive");
|
|
88
88
|
}
|
|
89
|
+
function isNeverField(field) {
|
|
90
|
+
return isField(field, "never");
|
|
91
|
+
}
|
|
89
92
|
function isUnknownField(field) {
|
|
90
93
|
return isField(field, "unknown");
|
|
91
94
|
}
|
|
92
95
|
//#endregion
|
|
93
|
-
export { isArrayField, isBooleanField, isConditionalField, isDiscriminatedUnionField, isEnumField, isFileField, isLiteralField, isNegationField, isNullField, isNumberField, isObjectField, isRecordField, isRecursiveField, isStringField, isTupleField, isUnionField, isUnknownField, resolveEditability };
|
|
96
|
+
export { isArrayField, isBooleanField, isConditionalField, isDiscriminatedUnionField, isEnumField, isFileField, isLiteralField, isNegationField, isNeverField, isNullField, isNumberField, isObjectField, isRecordField, isRecursiveField, isStringField, isTupleField, isUnionField, isUnknownField, resolveEditability };
|
package/dist/core/version.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as isOpenApi30, i as
|
|
2
|
-
export { JsonSchemaDraft, OpenApiVersionInfo, detectJsonSchemaDraft, detectOpenApiVersion, isOpenApi30, isOpenApi31, isSwagger2 };
|
|
1
|
+
import { a as detectOpenApiVersion, c as isOpenApi30, i as detectJsonSchemaDraft, l as isOpenApi31, n as JsonSchemaDraft, o as inferJsonSchemaDraft, r as OpenApiVersionInfo, s as inferJsonSchemaDraftWithReason, t as InferredDraft, u as isSwagger2 } from "../version-B5NV-35j.mjs";
|
|
2
|
+
export { InferredDraft, JsonSchemaDraft, OpenApiVersionInfo, detectJsonSchemaDraft, detectOpenApiVersion, inferJsonSchemaDraft, inferJsonSchemaDraftWithReason, isOpenApi30, isOpenApi31, isSwagger2 };
|
package/dist/core/version.mjs
CHANGED
|
@@ -16,23 +16,95 @@ const DRAFT_URIS = new Map([
|
|
|
16
16
|
]);
|
|
17
17
|
/**
|
|
18
18
|
* Detect the JSON Schema draft version from a schema's `$schema` URI.
|
|
19
|
-
*
|
|
20
|
-
*
|
|
19
|
+
* When `$schema` is absent, uses heuristic keyword detection via
|
|
20
|
+
* `inferJsonSchemaDraft` to guess the draft version.
|
|
21
|
+
* Returns `"draft-2020-12"` as the final fallback when no heuristic
|
|
22
|
+
* matches either.
|
|
21
23
|
*/
|
|
22
24
|
function detectJsonSchemaDraft(schema) {
|
|
23
25
|
const $schema = schema.$schema;
|
|
24
|
-
if (typeof $schema
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
if (typeof $schema === "string") {
|
|
27
|
+
const exact = DRAFT_URIS.get($schema);
|
|
28
|
+
if (exact !== void 0) return exact;
|
|
29
|
+
for (const [uri, draft] of DRAFT_URIS) if ($schema.startsWith(uri) || $schema === uri) return draft;
|
|
30
|
+
if ($schema.includes("/draft/2020-12/")) return "draft-2020-12";
|
|
31
|
+
if ($schema.includes("/draft/2019-09/")) return "draft-2019-09";
|
|
32
|
+
if ($schema.includes("/draft-07")) return "draft-07";
|
|
33
|
+
if ($schema.includes("/draft-06")) return "draft-06";
|
|
34
|
+
if ($schema.includes("/draft-04")) return "draft-04";
|
|
35
|
+
return "draft-2020-12";
|
|
36
|
+
}
|
|
37
|
+
return inferJsonSchemaDraft(schema);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Infer the JSON Schema draft from keyword presence when `$schema`
|
|
41
|
+
* is absent. Examined from highest-confidence to lowest.
|
|
42
|
+
*
|
|
43
|
+
* Heuristics:
|
|
44
|
+
* 1. `$dynamicRef` / `$dynamicAnchor` / `prefixItems` → Draft 2020-12
|
|
45
|
+
* 2. `$recursiveRef` / `$recursiveAnchor` / `unevaluatedProperties` /
|
|
46
|
+
* `dependentSchemas` → Draft 2019-09
|
|
47
|
+
* 3. `if` / `then` / `else`, `contentEncoding` / `contentMediaType` → Draft 07
|
|
48
|
+
* 4. `const`, `examples` (array), `propertyNames` → Draft 06
|
|
49
|
+
* 5. Boolean `exclusiveMinimum`, `id` (no `$`), `definitions` only → Draft 04
|
|
50
|
+
* 6. No signal → Draft 2020-12
|
|
51
|
+
*/
|
|
52
|
+
function inferJsonSchemaDraft(schema) {
|
|
53
|
+
if ("$dynamicRef" in schema || "$dynamicAnchor" in schema || "prefixItems" in schema) return "draft-2020-12";
|
|
54
|
+
if ("$recursiveRef" in schema || "$recursiveAnchor" in schema || "unevaluatedProperties" in schema || "unevaluatedItems" in schema) return "draft-2019-09";
|
|
55
|
+
if ("if" in schema || "then" in schema || "else" in schema) return "draft-07";
|
|
56
|
+
if ("contentEncoding" in schema || "contentMediaType" in schema) return "draft-07";
|
|
57
|
+
if ("const" in schema || "propertyNames" in schema) return "draft-06";
|
|
58
|
+
const examples = schema.examples;
|
|
59
|
+
if (Array.isArray(examples)) return "draft-06";
|
|
60
|
+
if (typeof schema.exclusiveMinimum === "boolean" || typeof schema.exclusiveMaximum === "boolean") return "draft-04";
|
|
61
|
+
if ("id" in schema && !("$id" in schema)) return "draft-04";
|
|
33
62
|
return "draft-2020-12";
|
|
34
63
|
}
|
|
35
64
|
/**
|
|
65
|
+
* Like `inferJsonSchemaDraft` but also returns the heuristic that
|
|
66
|
+
* triggered the inference, for diagnostic emission.
|
|
67
|
+
*/
|
|
68
|
+
function inferJsonSchemaDraftWithReason(schema) {
|
|
69
|
+
if ("$dynamicRef" in schema || "$dynamicAnchor" in schema || "prefixItems" in schema) return {
|
|
70
|
+
draft: "draft-2020-12",
|
|
71
|
+
inferredFrom: "dynamic-ref-or-anchor-or-prefixItems"
|
|
72
|
+
};
|
|
73
|
+
if ("$recursiveRef" in schema || "$recursiveAnchor" in schema || "unevaluatedProperties" in schema || "unevaluatedItems" in schema) return {
|
|
74
|
+
draft: "draft-2019-09",
|
|
75
|
+
inferredFrom: "recursive-ref-or-anchor-or-unevaluated"
|
|
76
|
+
};
|
|
77
|
+
if ("if" in schema || "then" in schema || "else" in schema) return {
|
|
78
|
+
draft: "draft-07",
|
|
79
|
+
inferredFrom: "if-then-else"
|
|
80
|
+
};
|
|
81
|
+
if ("contentEncoding" in schema || "contentMediaType" in schema) return {
|
|
82
|
+
draft: "draft-07",
|
|
83
|
+
inferredFrom: "content-encoding-or-media-type"
|
|
84
|
+
};
|
|
85
|
+
if ("const" in schema || "propertyNames" in schema) return {
|
|
86
|
+
draft: "draft-06",
|
|
87
|
+
inferredFrom: "const-or-propertyNames"
|
|
88
|
+
};
|
|
89
|
+
const examples = schema.examples;
|
|
90
|
+
if (Array.isArray(examples)) return {
|
|
91
|
+
draft: "draft-06",
|
|
92
|
+
inferredFrom: "examples"
|
|
93
|
+
};
|
|
94
|
+
if (typeof schema.exclusiveMinimum === "boolean" || typeof schema.exclusiveMaximum === "boolean") return {
|
|
95
|
+
draft: "draft-04",
|
|
96
|
+
inferredFrom: "boolean-exclusive-min-max"
|
|
97
|
+
};
|
|
98
|
+
if ("id" in schema && !("$id" in schema)) return {
|
|
99
|
+
draft: "draft-04",
|
|
100
|
+
inferredFrom: "id-without-dollar"
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
draft: "draft-2020-12",
|
|
104
|
+
inferredFrom: "no-signal"
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
36
108
|
* Detect the OpenAPI/Swagger version from a document.
|
|
37
109
|
* Returns `undefined` for documents that are not OpenAPI or Swagger.
|
|
38
110
|
*/
|
|
@@ -76,4 +148,4 @@ function isSwagger2(version) {
|
|
|
76
148
|
return version.major === 2;
|
|
77
149
|
}
|
|
78
150
|
//#endregion
|
|
79
|
-
export { detectJsonSchemaDraft, detectOpenApiVersion, isOpenApi30, isOpenApi31, isSwagger2 };
|
|
151
|
+
export { detectJsonSchemaDraft, detectOpenApiVersion, inferJsonSchemaDraft, inferJsonSchemaDraftWithReason, isOpenApi30, isOpenApi31, isSwagger2 };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { M as WalkedField, O as StringField, T as SchemaMeta, b as NumberField, c as FieldBase, j as UnknownField, o as Editability, p as FileField, r as BooleanField, v as NullField } from "../types-D_5ST7SS.mjs";
|
|
2
|
+
import { i as DiagnosticsOptions } from "../diagnostics-DzbZmcLI.mjs";
|
|
3
|
+
import { t as ExternalResolver } from "../ref-DvWoULcy.mjs";
|
|
2
4
|
|
|
3
5
|
//#region src/core/walkBuilders.d.ts
|
|
4
6
|
declare function getString(obj: Record<string, unknown>, key: string): string | undefined;
|
|
@@ -11,6 +13,10 @@ interface WalkOptions {
|
|
|
11
13
|
fieldOverrides?: Record<string, unknown> | undefined;
|
|
12
14
|
/** The root document for $ref resolution. */
|
|
13
15
|
rootDocument?: Record<string, unknown> | undefined;
|
|
16
|
+
/** Diagnostics channel for surfacing silent fallbacks. */
|
|
17
|
+
diagnostics?: DiagnosticsOptions;
|
|
18
|
+
/** Sync resolver for external $ref URIs. */
|
|
19
|
+
externalResolver?: ExternalResolver;
|
|
14
20
|
}
|
|
15
21
|
declare function extractMetaFromJson(schema: Record<string, unknown>): SchemaMeta;
|
|
16
22
|
declare function extractSchemaMetaFields(overrides: Record<string, unknown> | undefined): SchemaMeta | undefined;
|
|
@@ -25,6 +31,14 @@ interface WalkContext {
|
|
|
25
31
|
defaultValue: unknown;
|
|
26
32
|
/** Cache of $ref → WalkedField for recursive schema support. */
|
|
27
33
|
refResults: Map<string, WalkedField>;
|
|
34
|
+
/** JSON Pointer tracking for diagnostics. */
|
|
35
|
+
pointer: string;
|
|
36
|
+
/** Diagnostics channel for surfacing silent fallbacks. */
|
|
37
|
+
diagnostics: DiagnosticsOptions | undefined;
|
|
38
|
+
/** Derived $ref depth bound from the root document. */
|
|
39
|
+
maxRefDepth: number;
|
|
40
|
+
/** Sync resolver for external $ref URIs. */
|
|
41
|
+
externalResolver: ExternalResolver | undefined;
|
|
28
42
|
}
|
|
29
43
|
/**
|
|
30
44
|
* Build the common base shared by every field variant.
|
|
@@ -86,7 +86,7 @@ function buildStringField(schema, ctx) {
|
|
|
86
86
|
return {
|
|
87
87
|
...buildBase(schema, ctx),
|
|
88
88
|
type: "string",
|
|
89
|
-
constraints: extractStringConstraints(schema)
|
|
89
|
+
constraints: extractStringConstraints(schema, ctx.diagnostics, ctx.pointer)
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
92
|
function buildNumberField(schema, ctx) {
|
package/dist/core/walker.d.mts
CHANGED