@hey-api/shared 0.4.3 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +14 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +228 -171
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -968,17 +968,13 @@ function deduplicateSchema({ detectFormat = true, schema }) {
|
|
|
968
968
|
}
|
|
969
969
|
uniqueItems.push(item);
|
|
970
970
|
}
|
|
971
|
-
|
|
972
|
-
result.
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
...result,
|
|
979
|
-
...liftedSchema
|
|
980
|
-
};
|
|
981
|
-
}
|
|
971
|
+
const result = { ...schema };
|
|
972
|
+
if (uniqueItems.length <= 1 && result.type !== "array" && result.type !== "enum" && result.type !== "tuple") {
|
|
973
|
+
const liftedSchema = uniqueItems[0];
|
|
974
|
+
result.items = void 0;
|
|
975
|
+
result.logicalOperator = void 0;
|
|
976
|
+
Object.assign(result, liftedSchema);
|
|
977
|
+
} else result.items = uniqueItems;
|
|
982
978
|
if (result.type === "unknown") return {};
|
|
983
979
|
return result;
|
|
984
980
|
}
|
|
@@ -1000,10 +996,7 @@ function addItemsToSchema({ items, logicalOperator = "or", mutateSchemaOneItem =
|
|
|
1000
996
|
return schema;
|
|
1001
997
|
}
|
|
1002
998
|
if (mutateSchemaOneItem) {
|
|
1003
|
-
schema
|
|
1004
|
-
...schema,
|
|
1005
|
-
...items[0]
|
|
1006
|
-
};
|
|
999
|
+
Object.assign(schema, items[0]);
|
|
1007
1000
|
return schema;
|
|
1008
1001
|
}
|
|
1009
1002
|
schema.items = items;
|
|
@@ -1694,6 +1687,14 @@ const irTopLevelKinds = [
|
|
|
1694
1687
|
"server",
|
|
1695
1688
|
"webhook"
|
|
1696
1689
|
];
|
|
1690
|
+
const irPatterns = {
|
|
1691
|
+
operation: /^#\/paths\/[^/]+\/(get|put|post|delete|options|head|patch|trace)$/,
|
|
1692
|
+
parameter: /^#\/components\/parameters\/[^/]+$/,
|
|
1693
|
+
requestBody: /^#\/components\/requestBodies\/[^/]+$/,
|
|
1694
|
+
schema: /^#\/components\/schemas\/[^/]+$/,
|
|
1695
|
+
server: /^#\/servers\/(\d+|[^/]+)$/,
|
|
1696
|
+
webhook: /^#\/webhooks\/[^/]+\/(get|put|post|delete|options|head|patch|trace)$/
|
|
1697
|
+
};
|
|
1697
1698
|
/**
|
|
1698
1699
|
* Checks if a pointer matches a known top-level IR component (schema, parameter, etc) and returns match info.
|
|
1699
1700
|
*
|
|
@@ -1702,25 +1703,14 @@ const irTopLevelKinds = [
|
|
|
1702
1703
|
* @returns { matched: true, kind: IrTopLevelKind } | { matched: false } - Whether it matched, and the matched kind if so
|
|
1703
1704
|
*/
|
|
1704
1705
|
const matchIrPointerToGroup = (pointer, kind) => {
|
|
1705
|
-
|
|
1706
|
-
operation: /^#\/paths\/[^/]+\/(get|put|post|delete|options|head|patch|trace)$/,
|
|
1707
|
-
parameter: /^#\/components\/parameters\/[^/]+$/,
|
|
1708
|
-
requestBody: /^#\/components\/requestBodies\/[^/]+$/,
|
|
1709
|
-
schema: /^#\/components\/schemas\/[^/]+$/,
|
|
1710
|
-
server: /^#\/servers\/(\d+|[^/]+)$/,
|
|
1711
|
-
webhook: /^#\/webhooks\/[^/]+\/(get|put|post|delete|options|head|patch|trace)$/
|
|
1712
|
-
};
|
|
1713
|
-
if (kind) return patterns[kind].test(pointer) ? {
|
|
1706
|
+
if (kind) return irPatterns[kind].test(pointer) ? {
|
|
1714
1707
|
kind,
|
|
1715
1708
|
matched: true
|
|
1716
1709
|
} : { matched: false };
|
|
1717
|
-
for (const key of
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
matched: true
|
|
1722
|
-
};
|
|
1723
|
-
}
|
|
1710
|
+
for (const key of irTopLevelKinds) if (irPatterns[key].test(pointer)) return {
|
|
1711
|
+
kind: key,
|
|
1712
|
+
matched: true
|
|
1713
|
+
};
|
|
1724
1714
|
return { matched: false };
|
|
1725
1715
|
};
|
|
1726
1716
|
const preferGroups = [
|
|
@@ -1786,6 +1776,7 @@ function jsonPointerToPath(pointer) {
|
|
|
1786
1776
|
if (clean.startsWith("#")) clean = clean.slice(1);
|
|
1787
1777
|
if (clean.startsWith("/")) clean = clean.slice(1);
|
|
1788
1778
|
if (!clean) return [];
|
|
1779
|
+
if (!clean.includes("~")) return clean.split("/");
|
|
1789
1780
|
return clean.split("/").map((part) => part.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
1790
1781
|
}
|
|
1791
1782
|
/**
|
|
@@ -1830,9 +1821,21 @@ function pathToJsonPointer(path) {
|
|
|
1830
1821
|
* @returns true if the ref points to a top-level component, false otherwise
|
|
1831
1822
|
*/
|
|
1832
1823
|
function isTopLevelComponent(refOrPath) {
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1824
|
+
if (typeof refOrPath !== "string") {
|
|
1825
|
+
if (refOrPath[0] === "components") return refOrPath.length === 3;
|
|
1826
|
+
if (refOrPath[0] === "definitions") return refOrPath.length === 2;
|
|
1827
|
+
return false;
|
|
1828
|
+
}
|
|
1829
|
+
if (refOrPath.startsWith("#/components/")) {
|
|
1830
|
+
const typeEnd = refOrPath.indexOf("/", 13);
|
|
1831
|
+
if (typeEnd === -1) return false;
|
|
1832
|
+
const nameStart = typeEnd + 1;
|
|
1833
|
+
return nameStart < refOrPath.length && refOrPath.indexOf("/", nameStart) === -1;
|
|
1834
|
+
}
|
|
1835
|
+
if (refOrPath.startsWith("#/definitions/")) {
|
|
1836
|
+
const nameStart = 14;
|
|
1837
|
+
return nameStart < refOrPath.length && refOrPath.indexOf("/", nameStart) === -1;
|
|
1838
|
+
}
|
|
1836
1839
|
return false;
|
|
1837
1840
|
}
|
|
1838
1841
|
function resolveRef({ $ref, spec }) {
|
|
@@ -1988,6 +1991,15 @@ var PluginInstance = class {
|
|
|
1988
1991
|
}
|
|
1989
1992
|
}, options);
|
|
1990
1993
|
}
|
|
1994
|
+
getHooks(selector, ...customHooks) {
|
|
1995
|
+
const result = [];
|
|
1996
|
+
for (const hook of customHooks) if (hook) result.push(hook);
|
|
1997
|
+
const local = selector(this.config["~hooks"] ?? {});
|
|
1998
|
+
if (local) result.push(local);
|
|
1999
|
+
const global = selector(this.context.config.parser.hooks);
|
|
2000
|
+
if (global) result.push(global);
|
|
2001
|
+
return result;
|
|
2002
|
+
}
|
|
1991
2003
|
/**
|
|
1992
2004
|
* Retrieves a registered plugin instance by its name from the context. This
|
|
1993
2005
|
* allows plugins to access other plugins that have been registered in the
|
|
@@ -2048,7 +2060,10 @@ var PluginInstance = class {
|
|
|
2048
2060
|
return result;
|
|
2049
2061
|
}
|
|
2050
2062
|
querySymbol(filter) {
|
|
2051
|
-
return this.
|
|
2063
|
+
return this.querySymbols(filter)[0];
|
|
2064
|
+
}
|
|
2065
|
+
querySymbols(filter) {
|
|
2066
|
+
return this.gen.symbols.query(filter);
|
|
2052
2067
|
}
|
|
2053
2068
|
referenceSymbol(meta) {
|
|
2054
2069
|
return this.gen.symbols.reference(meta);
|
|
@@ -2072,7 +2087,7 @@ var PluginInstance = class {
|
|
|
2072
2087
|
if (symbol.external) {
|
|
2073
2088
|
if (!meta.category) meta.category = "external";
|
|
2074
2089
|
if (!meta.resource) meta.resource = `${symbol.external}.${name}`;
|
|
2075
|
-
const existing = this.
|
|
2090
|
+
const existing = this.querySymbols(meta).find((s) => s.name === name);
|
|
2076
2091
|
if (existing) return existing;
|
|
2077
2092
|
}
|
|
2078
2093
|
const symbolIn = {
|
|
@@ -2104,7 +2119,7 @@ var PluginInstance = class {
|
|
|
2104
2119
|
symbolOnce(name, symbol = {}) {
|
|
2105
2120
|
if (symbol.external) return this.symbol(name, symbol);
|
|
2106
2121
|
if (symbol.meta) {
|
|
2107
|
-
const existing = this.
|
|
2122
|
+
const existing = this.querySymbols(symbol.meta).find((s) => s.name === name);
|
|
2108
2123
|
if (existing) return existing;
|
|
2109
2124
|
}
|
|
2110
2125
|
return this.symbol(name, symbol);
|
|
@@ -2136,9 +2151,8 @@ var PluginInstance = class {
|
|
|
2136
2151
|
});
|
|
2137
2152
|
}
|
|
2138
2153
|
getSymbolExportFromFilePath(symbol) {
|
|
2139
|
-
const
|
|
2140
|
-
|
|
2141
|
-
const result = hook?.getExportFromFilePath?.(symbol);
|
|
2154
|
+
for (const hook of this.getHooks((hooks) => hooks.symbols?.getExportFromFilePath)) {
|
|
2155
|
+
const result = hook(symbol);
|
|
2142
2156
|
if (result !== void 0) return result;
|
|
2143
2157
|
}
|
|
2144
2158
|
const entryFile = this.context.config.output.indexFile ?? this.context.config.output.entryFile;
|
|
@@ -2152,9 +2166,8 @@ var PluginInstance = class {
|
|
|
2152
2166
|
return [moduleEntryName];
|
|
2153
2167
|
}
|
|
2154
2168
|
getSymbolFilePath(symbol) {
|
|
2155
|
-
const
|
|
2156
|
-
|
|
2157
|
-
const result = hook?.getFilePath?.(symbol);
|
|
2169
|
+
for (const hook of this.getHooks((hooks) => hooks.symbols?.getFilePath)) {
|
|
2170
|
+
const result = hook(symbol);
|
|
2158
2171
|
if (result !== void 0) return result;
|
|
2159
2172
|
}
|
|
2160
2173
|
return defaultGetFilePath(symbol);
|
|
@@ -2404,8 +2417,8 @@ function visitTyped(schema, ctx, visitor, walk) {
|
|
|
2404
2417
|
*/
|
|
2405
2418
|
function childContext(ctx, ...segments) {
|
|
2406
2419
|
return {
|
|
2407
|
-
...ctx,
|
|
2408
|
-
|
|
2420
|
+
path: ref([...fromRef(ctx.path), ...segments]),
|
|
2421
|
+
plugin: ctx.plugin
|
|
2409
2422
|
};
|
|
2410
2423
|
}
|
|
2411
2424
|
//#endregion
|
|
@@ -3332,42 +3345,37 @@ const annotateChildScopes = (nodes) => {
|
|
|
3332
3345
|
* Recursively collects all $ref dependencies in the subtree rooted at `pointer`.
|
|
3333
3346
|
*/
|
|
3334
3347
|
const collectPointerDependencies = ({ cache, graph, pointer, visited }) => {
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
transitiveDependencies: cached
|
|
3348
|
+
if (cache.transitiveDependencies.has(pointer)) return {
|
|
3349
|
+
subtreeDependencies: cache.subtreeDependencies.get(pointer) ?? null,
|
|
3350
|
+
transitiveDependencies: cache.transitiveDependencies.get(pointer) ?? null
|
|
3339
3351
|
};
|
|
3340
3352
|
if (visited.has(pointer)) return {
|
|
3341
|
-
subtreeDependencies:
|
|
3342
|
-
transitiveDependencies:
|
|
3353
|
+
subtreeDependencies: null,
|
|
3354
|
+
transitiveDependencies: null
|
|
3343
3355
|
};
|
|
3344
3356
|
visited.add(pointer);
|
|
3345
3357
|
if (!graph.nodes.get(pointer)) return {
|
|
3346
|
-
subtreeDependencies:
|
|
3347
|
-
transitiveDependencies:
|
|
3358
|
+
subtreeDependencies: null,
|
|
3359
|
+
transitiveDependencies: null
|
|
3348
3360
|
};
|
|
3349
|
-
|
|
3350
|
-
|
|
3361
|
+
let transitiveDependencies = null;
|
|
3362
|
+
let subtreeDependencies = null;
|
|
3351
3363
|
const nodeDependencies = graph.nodeDependencies.get(pointer);
|
|
3352
3364
|
if (nodeDependencies) for (const depPointer of nodeDependencies) {
|
|
3353
|
-
transitiveDependencies.add(depPointer);
|
|
3354
|
-
subtreeDependencies.add(depPointer);
|
|
3365
|
+
(transitiveDependencies ??= /* @__PURE__ */ new Set()).add(depPointer);
|
|
3366
|
+
(subtreeDependencies ??= /* @__PURE__ */ new Set()).add(depPointer);
|
|
3355
3367
|
const depResult = collectPointerDependencies({
|
|
3356
3368
|
cache,
|
|
3357
3369
|
graph,
|
|
3358
3370
|
pointer: depPointer,
|
|
3359
3371
|
visited
|
|
3360
3372
|
});
|
|
3361
|
-
for (const dependency of depResult.transitiveDependencies) transitiveDependencies.add(dependency);
|
|
3373
|
+
if (depResult.transitiveDependencies) for (const dependency of depResult.transitiveDependencies) transitiveDependencies.add(dependency);
|
|
3362
3374
|
}
|
|
3363
3375
|
const children = cache.parentToChildren.get(pointer) ?? [];
|
|
3364
3376
|
for (const childPointer of children) {
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
transitiveDependencies: cache.transitiveDependencies.get(childPointer)
|
|
3368
|
-
};
|
|
3369
|
-
if (!childResult.subtreeDependencies || !childResult.transitiveDependencies) {
|
|
3370
|
-
childResult = collectPointerDependencies({
|
|
3377
|
+
if (!cache.transitiveDependencies.has(childPointer)) {
|
|
3378
|
+
const childResult = collectPointerDependencies({
|
|
3371
3379
|
cache,
|
|
3372
3380
|
graph,
|
|
3373
3381
|
pointer: childPointer,
|
|
@@ -3376,8 +3384,10 @@ const collectPointerDependencies = ({ cache, graph, pointer, visited }) => {
|
|
|
3376
3384
|
cache.transitiveDependencies.set(childPointer, childResult.transitiveDependencies);
|
|
3377
3385
|
cache.subtreeDependencies.set(childPointer, childResult.subtreeDependencies);
|
|
3378
3386
|
}
|
|
3379
|
-
|
|
3380
|
-
|
|
3387
|
+
const childTransitive = cache.transitiveDependencies.get(childPointer) ?? null;
|
|
3388
|
+
const childSubtree = cache.subtreeDependencies.get(childPointer) ?? null;
|
|
3389
|
+
if (childTransitive) for (const dependency of childTransitive) (transitiveDependencies ??= /* @__PURE__ */ new Set()).add(dependency);
|
|
3390
|
+
if (childSubtree) for (const dependency of childSubtree) (subtreeDependencies ??= /* @__PURE__ */ new Set()).add(dependency);
|
|
3381
3391
|
}
|
|
3382
3392
|
cache.transitiveDependencies.set(pointer, transitiveDependencies);
|
|
3383
3393
|
cache.subtreeDependencies.set(pointer, subtreeDependencies);
|
|
@@ -3535,8 +3545,8 @@ function buildGraph(root, logger) {
|
|
|
3535
3545
|
pointer,
|
|
3536
3546
|
visited: /* @__PURE__ */ new Set()
|
|
3537
3547
|
});
|
|
3538
|
-
graph.transitiveDependencies.set(pointer, result.transitiveDependencies);
|
|
3539
|
-
graph.subtreeDependencies.set(pointer, result.subtreeDependencies);
|
|
3548
|
+
if (result.transitiveDependencies) graph.transitiveDependencies.set(pointer, result.transitiveDependencies);
|
|
3549
|
+
if (result.subtreeDependencies) graph.subtreeDependencies.set(pointer, result.subtreeDependencies);
|
|
3540
3550
|
}
|
|
3541
3551
|
eventBuildGraph.timeEnd();
|
|
3542
3552
|
return { graph };
|
|
@@ -4302,7 +4312,7 @@ const convertDiscriminatorValue = (value, propertyType) => {
|
|
|
4302
4312
|
};
|
|
4303
4313
|
}
|
|
4304
4314
|
case "integer": {
|
|
4305
|
-
const parsed = parseInt(value, 10);
|
|
4315
|
+
const parsed = Number.parseInt(value, 10);
|
|
4306
4316
|
if (Number.isNaN(parsed)) {
|
|
4307
4317
|
console.warn("🚨", `non-numeric discriminator mapping value "${value}" for integer property, falling back to string`);
|
|
4308
4318
|
return {
|
|
@@ -4343,7 +4353,7 @@ const discriminatorValues = ($ref, mapping, shouldUseRefAsValue) => {
|
|
|
4343
4353
|
};
|
|
4344
4354
|
//#endregion
|
|
4345
4355
|
//#region src/openApi/2.0.x/parser/schema.ts
|
|
4346
|
-
function getSchemaType$1(
|
|
4356
|
+
function getSchemaType$1(schema) {
|
|
4347
4357
|
if (schema.type) return schema.type;
|
|
4348
4358
|
if (schema.properties) return "object";
|
|
4349
4359
|
}
|
|
@@ -4382,10 +4392,7 @@ function parseArray$2({ context, irSchema = {}, schema, state }) {
|
|
|
4382
4392
|
else if ("$ref" in schema.items) schemaItems.push(irItemsSchema);
|
|
4383
4393
|
else {
|
|
4384
4394
|
const ofArray = schema.items.allOf;
|
|
4385
|
-
if (ofArray && ofArray.length > 1 && !schema.items["x-nullable"]) irSchema
|
|
4386
|
-
...irSchema,
|
|
4387
|
-
...irItemsSchema
|
|
4388
|
-
};
|
|
4395
|
+
if (ofArray && ofArray.length > 1 && !schema.items["x-nullable"]) Object.assign(irSchema, irItemsSchema);
|
|
4389
4396
|
else schemaItems.push(irItemsSchema);
|
|
4390
4397
|
}
|
|
4391
4398
|
}
|
|
@@ -4405,20 +4412,24 @@ function parseNumber$2({ irSchema = {}, schema }) {
|
|
|
4405
4412
|
}
|
|
4406
4413
|
function parseObject$2({ context, irSchema = {}, schema, state }) {
|
|
4407
4414
|
irSchema.type = "object";
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
const
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4415
|
+
let isSchemaPropertiesEmpty = true;
|
|
4416
|
+
if (schema.properties) {
|
|
4417
|
+
const schemaProperties = {};
|
|
4418
|
+
for (const name in schema.properties) {
|
|
4419
|
+
isSchemaPropertiesEmpty = false;
|
|
4420
|
+
const property = schema.properties[name];
|
|
4421
|
+
if (typeof property === "boolean") {} else schemaProperties[name] = schemaToIrSchema$2({
|
|
4422
|
+
context,
|
|
4423
|
+
schema: property,
|
|
4424
|
+
state
|
|
4425
|
+
});
|
|
4426
|
+
}
|
|
4427
|
+
if (!isSchemaPropertiesEmpty) irSchema.properties = schemaProperties;
|
|
4416
4428
|
}
|
|
4417
|
-
if (Object.keys(schemaProperties).length) irSchema.properties = schemaProperties;
|
|
4418
4429
|
if (schema.additionalProperties === void 0) {
|
|
4419
4430
|
if (!irSchema.properties) irSchema.additionalProperties = { type: "unknown" };
|
|
4420
4431
|
} else if (typeof schema.additionalProperties === "boolean") {
|
|
4421
|
-
if (!(state.inAllOf && schema.additionalProperties === false && (!schema.properties ||
|
|
4432
|
+
if (!(state.inAllOf && schema.additionalProperties === false && (!schema.properties || isSchemaPropertiesEmpty))) irSchema.additionalProperties = { type: schema.additionalProperties ? "unknown" : "never" };
|
|
4422
4433
|
} else irSchema.additionalProperties = schemaToIrSchema$2({
|
|
4423
4434
|
context,
|
|
4424
4435
|
schema: schema.additionalProperties,
|
|
@@ -4449,7 +4460,7 @@ function initIrSchema$2({ schema }) {
|
|
|
4449
4460
|
function parseAllOf$2({ context, schema, state }) {
|
|
4450
4461
|
let irSchema = initIrSchema$2({ schema });
|
|
4451
4462
|
const schemaItems = [];
|
|
4452
|
-
const schemaType = getSchemaType$1(
|
|
4463
|
+
const schemaType = getSchemaType$1(schema);
|
|
4453
4464
|
const compositionSchemas = schema.allOf;
|
|
4454
4465
|
for (const compositionSchema of compositionSchemas) {
|
|
4455
4466
|
const originalInAllOf = state.inAllOf;
|
|
@@ -4460,8 +4471,7 @@ function parseAllOf$2({ context, schema, state }) {
|
|
|
4460
4471
|
state
|
|
4461
4472
|
});
|
|
4462
4473
|
state.inAllOf = originalInAllOf;
|
|
4463
|
-
if (
|
|
4464
|
-
if (schema.required) if (irCompositionSchema.required) irCompositionSchema.required = [...irCompositionSchema.required, ...schema.required];
|
|
4474
|
+
if (schema.required) if (irCompositionSchema.required) irCompositionSchema.required.push(...schema.required);
|
|
4465
4475
|
else irCompositionSchema.required = schema.required;
|
|
4466
4476
|
schemaItems.push(irCompositionSchema);
|
|
4467
4477
|
if (compositionSchema.$ref) {
|
|
@@ -4495,7 +4505,7 @@ function parseAllOf$2({ context, schema, state }) {
|
|
|
4495
4505
|
if (irObjectSchema.properties) {
|
|
4496
4506
|
for (const requiredProperty of irObjectSchema.required ?? []) if (!irObjectSchema.properties[requiredProperty]) for (const compositionSchema of compositionSchemas) {
|
|
4497
4507
|
const finalCompositionSchema = compositionSchema.$ref ? context.resolveRef(compositionSchema.$ref) : compositionSchema;
|
|
4498
|
-
if (getSchemaType$1(
|
|
4508
|
+
if (getSchemaType$1(finalCompositionSchema) === "object") {
|
|
4499
4509
|
const irCompositionSchema = parseOneType$2({
|
|
4500
4510
|
context,
|
|
4501
4511
|
schema: {
|
|
@@ -4539,7 +4549,11 @@ function parseEnum$2({ context, schema, state }) {
|
|
|
4539
4549
|
});
|
|
4540
4550
|
irSchema.type = "enum";
|
|
4541
4551
|
const schemaItems = [];
|
|
4542
|
-
|
|
4552
|
+
const xEnumDescriptions = schema["x-enum-descriptions"];
|
|
4553
|
+
const xEnumVarnames = schema["x-enum-varnames"];
|
|
4554
|
+
const xEnumNames = schema["x-enumNames"];
|
|
4555
|
+
for (let index = 0, len = schema.enum.length; index < len; index++) {
|
|
4556
|
+
const enumValue = schema.enum[index];
|
|
4543
4557
|
const typeOfEnumValue = typeof enumValue;
|
|
4544
4558
|
let enumType;
|
|
4545
4559
|
if (typeOfEnumValue === "string" || typeOfEnumValue === "number" || typeOfEnumValue === "boolean") enumType = typeOfEnumValue;
|
|
@@ -4551,8 +4565,8 @@ function parseEnum$2({ context, schema, state }) {
|
|
|
4551
4565
|
const irTypeSchema = parseOneType$2({
|
|
4552
4566
|
context,
|
|
4553
4567
|
schema: {
|
|
4554
|
-
description:
|
|
4555
|
-
title:
|
|
4568
|
+
description: xEnumDescriptions?.[index],
|
|
4569
|
+
title: xEnumVarnames?.[index] ?? xEnumNames?.[index],
|
|
4556
4570
|
type: enumType === "null" ? "string" : enumType
|
|
4557
4571
|
},
|
|
4558
4572
|
state
|
|
@@ -4624,7 +4638,7 @@ function parseType$2({ context, schema, state }) {
|
|
|
4624
4638
|
irSchema,
|
|
4625
4639
|
schema
|
|
4626
4640
|
});
|
|
4627
|
-
const type = getSchemaType$1(
|
|
4641
|
+
const type = getSchemaType$1(schema);
|
|
4628
4642
|
if (!type) return irSchema;
|
|
4629
4643
|
if (schema["x-nullable"]) return parseNullableType$1({
|
|
4630
4644
|
context,
|
|
@@ -4776,7 +4790,7 @@ const paginationField$2 = ({ context, name, schema }) => {
|
|
|
4776
4790
|
for (const name in schema.properties) if (getPaginationKeywordsRegExp(context.config.parser.pagination).test(name)) {
|
|
4777
4791
|
const property = schema.properties[name];
|
|
4778
4792
|
if (typeof property !== "boolean" && !("$ref" in property)) {
|
|
4779
|
-
if (isPaginationType$2(getSchemaType$1(
|
|
4793
|
+
if (isPaginationType$2(getSchemaType$1(property))) return name;
|
|
4780
4794
|
}
|
|
4781
4795
|
}
|
|
4782
4796
|
for (const allOf of schema.allOf ?? []) {
|
|
@@ -5193,7 +5207,7 @@ const parseV2_0_X = (context) => {
|
|
|
5193
5207
|
securitySchemesMap.set(name, securitySchemeObject);
|
|
5194
5208
|
}
|
|
5195
5209
|
if (context.spec.definitions) for (const name in context.spec.definitions) {
|
|
5196
|
-
const $ref =
|
|
5210
|
+
const $ref = pathToJsonPointer(["definitions", name]);
|
|
5197
5211
|
const schema = context.spec.definitions[name];
|
|
5198
5212
|
parseSchema$2({
|
|
5199
5213
|
$ref,
|
|
@@ -5461,7 +5475,7 @@ const mediaTypeObjects$1 = ({ content }) => {
|
|
|
5461
5475
|
};
|
|
5462
5476
|
//#endregion
|
|
5463
5477
|
//#region src/openApi/3.0.x/parser/schema.ts
|
|
5464
|
-
function getSchemaType(
|
|
5478
|
+
function getSchemaType(schema) {
|
|
5465
5479
|
if (schema.type) return schema.type;
|
|
5466
5480
|
if (schema.properties) return "object";
|
|
5467
5481
|
}
|
|
@@ -5516,7 +5530,7 @@ function findDiscriminatorsInSchema$1({ context, discriminators = [], schema })
|
|
|
5516
5530
|
*/
|
|
5517
5531
|
function getAllDiscriminatorValues$1({ discriminator, schemaRef }) {
|
|
5518
5532
|
const values = [];
|
|
5519
|
-
for (const
|
|
5533
|
+
for (const value in discriminator.mapping) if (discriminator.mapping[value] === schemaRef) values.push(value);
|
|
5520
5534
|
return values;
|
|
5521
5535
|
}
|
|
5522
5536
|
function parseSchemaJsDoc$1({ irSchema, schema }) {
|
|
@@ -5556,10 +5570,7 @@ function parseArray$1({ context, irSchema = {}, schema, state }) {
|
|
|
5556
5570
|
else if ("$ref" in schema.items) schemaItems.push(irItemsSchema);
|
|
5557
5571
|
else {
|
|
5558
5572
|
const ofArray = schema.items.allOf || schema.items.anyOf || schema.items.oneOf;
|
|
5559
|
-
if (ofArray && ofArray.length > 1 && !schema.items.nullable) irSchema
|
|
5560
|
-
...irSchema,
|
|
5561
|
-
...irItemsSchema
|
|
5562
|
-
};
|
|
5573
|
+
if (ofArray && ofArray.length > 1 && !schema.items.nullable) Object.assign(irSchema, irItemsSchema);
|
|
5563
5574
|
else schemaItems.push(irItemsSchema);
|
|
5564
5575
|
}
|
|
5565
5576
|
}
|
|
@@ -5579,20 +5590,24 @@ function parseNumber$1({ irSchema = {}, schema }) {
|
|
|
5579
5590
|
}
|
|
5580
5591
|
function parseObject$1({ context, irSchema = {}, schema, state }) {
|
|
5581
5592
|
irSchema.type = "object";
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
const
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5593
|
+
let isSchemaPropertiesEmpty = true;
|
|
5594
|
+
if (schema.properties) {
|
|
5595
|
+
const schemaProperties = {};
|
|
5596
|
+
for (const name in schema.properties) {
|
|
5597
|
+
isSchemaPropertiesEmpty = false;
|
|
5598
|
+
const property = schema.properties[name];
|
|
5599
|
+
if (typeof property === "boolean") {} else schemaProperties[name] = schemaToIrSchema$1({
|
|
5600
|
+
context,
|
|
5601
|
+
schema: property,
|
|
5602
|
+
state
|
|
5603
|
+
});
|
|
5604
|
+
}
|
|
5605
|
+
if (!isSchemaPropertiesEmpty) irSchema.properties = schemaProperties;
|
|
5590
5606
|
}
|
|
5591
|
-
if (Object.keys(schemaProperties).length) irSchema.properties = schemaProperties;
|
|
5592
5607
|
if (schema.additionalProperties === void 0) {
|
|
5593
5608
|
if (!irSchema.properties) irSchema.additionalProperties = { type: "unknown" };
|
|
5594
5609
|
} else if (typeof schema.additionalProperties === "boolean") {
|
|
5595
|
-
if (!(state.inAllOf && schema.additionalProperties === false && (!schema.properties ||
|
|
5610
|
+
if (!(state.inAllOf && schema.additionalProperties === false && (!schema.properties || isSchemaPropertiesEmpty))) irSchema.additionalProperties = { type: schema.additionalProperties ? "unknown" : "never" };
|
|
5596
5611
|
} else irSchema.additionalProperties = schemaToIrSchema$1({
|
|
5597
5612
|
context,
|
|
5598
5613
|
schema: schema.additionalProperties,
|
|
@@ -5642,7 +5657,7 @@ function initIrSchema$1({ schema }) {
|
|
|
5642
5657
|
function parseAllOf$1({ context, schema, state }) {
|
|
5643
5658
|
let irSchema = initIrSchema$1({ schema });
|
|
5644
5659
|
const schemaItems = [];
|
|
5645
|
-
const schemaType = getSchemaType(
|
|
5660
|
+
const schemaType = getSchemaType(schema);
|
|
5646
5661
|
const compositionSchemas = schema.allOf;
|
|
5647
5662
|
const discriminatorsToAdd = [];
|
|
5648
5663
|
for (const compositionSchema of compositionSchemas) {
|
|
@@ -5654,8 +5669,7 @@ function parseAllOf$1({ context, schema, state }) {
|
|
|
5654
5669
|
state
|
|
5655
5670
|
});
|
|
5656
5671
|
state.inAllOf = originalInAllOf;
|
|
5657
|
-
if (
|
|
5658
|
-
if (schema.required) if (irCompositionSchema.required) irCompositionSchema.required = [...irCompositionSchema.required, ...schema.required];
|
|
5672
|
+
if (schema.required) if (irCompositionSchema.required) irCompositionSchema.required.push(...schema.required);
|
|
5659
5673
|
else irCompositionSchema.required = schema.required;
|
|
5660
5674
|
schemaItems.push(irCompositionSchema);
|
|
5661
5675
|
if ("$ref" in compositionSchema) {
|
|
@@ -5730,7 +5744,7 @@ function parseAllOf$1({ context, schema, state }) {
|
|
|
5730
5744
|
inlineSchema.properties[discriminator.propertyName] = discriminatorProperty;
|
|
5731
5745
|
if (isRequired) {
|
|
5732
5746
|
if (!inlineSchema.required) inlineSchema.required = [];
|
|
5733
|
-
if (!inlineSchema.required.includes(discriminator.propertyName)) inlineSchema.required
|
|
5747
|
+
if (!inlineSchema.required.includes(discriminator.propertyName)) inlineSchema.required.push(discriminator.propertyName);
|
|
5734
5748
|
}
|
|
5735
5749
|
} else {
|
|
5736
5750
|
const irDiscriminatorSchema = {
|
|
@@ -5753,7 +5767,7 @@ function parseAllOf$1({ context, schema, state }) {
|
|
|
5753
5767
|
if (irObjectSchema.properties) {
|
|
5754
5768
|
for (const requiredProperty of irObjectSchema.required ?? []) if (!irObjectSchema.properties[requiredProperty]) for (const compositionSchema of compositionSchemas) {
|
|
5755
5769
|
const finalCompositionSchema = "$ref" in compositionSchema ? context.resolveRef(compositionSchema.$ref) : compositionSchema;
|
|
5756
|
-
if (getSchemaType(
|
|
5770
|
+
if (getSchemaType(finalCompositionSchema) === "object") {
|
|
5757
5771
|
const irCompositionSchema = parseOneType$1({
|
|
5758
5772
|
context,
|
|
5759
5773
|
schema: {
|
|
@@ -5792,7 +5806,7 @@ function parseAllOf$1({ context, schema, state }) {
|
|
|
5792
5806
|
function parseAnyOf$1({ context, schema, state }) {
|
|
5793
5807
|
let irSchema = initIrSchema$1({ schema });
|
|
5794
5808
|
const schemaItems = [];
|
|
5795
|
-
const schemaType = getSchemaType(
|
|
5809
|
+
const schemaType = getSchemaType(schema);
|
|
5796
5810
|
const compositionSchemas = schema.anyOf;
|
|
5797
5811
|
const discriminatorPropertyType = schema.discriminator ? findDiscriminatorPropertyType$1({
|
|
5798
5812
|
context,
|
|
@@ -5851,7 +5865,11 @@ function parseEnum$1({ context, schema, state }) {
|
|
|
5851
5865
|
});
|
|
5852
5866
|
irSchema.type = "enum";
|
|
5853
5867
|
const schemaItems = [];
|
|
5854
|
-
|
|
5868
|
+
const xEnumDescriptions = schema["x-enum-descriptions"];
|
|
5869
|
+
const xEnumVarnames = schema["x-enum-varnames"];
|
|
5870
|
+
const xEnumNames = schema["x-enumNames"];
|
|
5871
|
+
for (let index = 0, len = schema.enum.length; index < len; index++) {
|
|
5872
|
+
const enumValue = schema.enum[index];
|
|
5855
5873
|
const typeOfEnumValue = typeof enumValue;
|
|
5856
5874
|
let enumType;
|
|
5857
5875
|
if (typeOfEnumValue === "string" || typeOfEnumValue === "number" || typeOfEnumValue === "boolean") enumType = typeOfEnumValue;
|
|
@@ -5863,8 +5881,8 @@ function parseEnum$1({ context, schema, state }) {
|
|
|
5863
5881
|
const irTypeSchema = parseOneType$1({
|
|
5864
5882
|
context,
|
|
5865
5883
|
schema: {
|
|
5866
|
-
description:
|
|
5867
|
-
title:
|
|
5884
|
+
description: xEnumDescriptions?.[index],
|
|
5885
|
+
title: xEnumVarnames?.[index] ?? xEnumNames?.[index],
|
|
5868
5886
|
type: enumType === "null" ? "string" : enumType
|
|
5869
5887
|
},
|
|
5870
5888
|
state
|
|
@@ -5883,7 +5901,7 @@ function parseEnum$1({ context, schema, state }) {
|
|
|
5883
5901
|
function parseOneOf$1({ context, schema, state }) {
|
|
5884
5902
|
let irSchema = initIrSchema$1({ schema });
|
|
5885
5903
|
let schemaItems = [];
|
|
5886
|
-
const schemaType = getSchemaType(
|
|
5904
|
+
const schemaType = getSchemaType(schema);
|
|
5887
5905
|
const compositionSchemas = schema.oneOf;
|
|
5888
5906
|
const discriminatorPropertyType = schema.discriminator ? findDiscriminatorPropertyType$1({
|
|
5889
5907
|
context,
|
|
@@ -5991,7 +6009,7 @@ function parseType$1({ context, schema, state }) {
|
|
|
5991
6009
|
irSchema,
|
|
5992
6010
|
schema
|
|
5993
6011
|
});
|
|
5994
|
-
const type = getSchemaType(
|
|
6012
|
+
const type = getSchemaType(schema);
|
|
5995
6013
|
if (!type) return irSchema;
|
|
5996
6014
|
if (!schema.nullable) return parseOneType$1({
|
|
5997
6015
|
context,
|
|
@@ -6149,7 +6167,7 @@ const paginationField$1 = ({ context, name, schema }) => {
|
|
|
6149
6167
|
for (const name in schema.properties) if (getPaginationKeywordsRegExp(context.config.parser.pagination).test(name)) {
|
|
6150
6168
|
const property = schema.properties[name];
|
|
6151
6169
|
if (typeof property !== "boolean" && !("$ref" in property)) {
|
|
6152
|
-
if (isPaginationType$1(getSchemaType(
|
|
6170
|
+
if (isPaginationType$1(getSchemaType(property))) return name;
|
|
6153
6171
|
}
|
|
6154
6172
|
}
|
|
6155
6173
|
for (const allOf of schema.allOf ?? []) {
|
|
@@ -6533,7 +6551,11 @@ const parseV3_0_X = (context) => {
|
|
|
6533
6551
|
securitySchemesMap.set(name, securitySchemeObject);
|
|
6534
6552
|
}
|
|
6535
6553
|
for (const name in context.spec.components.parameters) {
|
|
6536
|
-
const $ref =
|
|
6554
|
+
const $ref = pathToJsonPointer([
|
|
6555
|
+
"components",
|
|
6556
|
+
"parameters",
|
|
6557
|
+
name
|
|
6558
|
+
]);
|
|
6537
6559
|
const parameterOrReference = context.spec.components.parameters[name];
|
|
6538
6560
|
parseParameter$1({
|
|
6539
6561
|
$ref,
|
|
@@ -6542,7 +6564,11 @@ const parseV3_0_X = (context) => {
|
|
|
6542
6564
|
});
|
|
6543
6565
|
}
|
|
6544
6566
|
for (const name in context.spec.components.requestBodies) {
|
|
6545
|
-
const $ref =
|
|
6567
|
+
const $ref = pathToJsonPointer([
|
|
6568
|
+
"components",
|
|
6569
|
+
"requestBodies",
|
|
6570
|
+
name
|
|
6571
|
+
]);
|
|
6546
6572
|
const requestBodyOrReference = context.spec.components.requestBodies[name];
|
|
6547
6573
|
parseRequestBody$1({
|
|
6548
6574
|
$ref,
|
|
@@ -6551,7 +6577,11 @@ const parseV3_0_X = (context) => {
|
|
|
6551
6577
|
});
|
|
6552
6578
|
}
|
|
6553
6579
|
for (const name in context.spec.components.schemas) {
|
|
6554
|
-
const $ref =
|
|
6580
|
+
const $ref = pathToJsonPointer([
|
|
6581
|
+
"components",
|
|
6582
|
+
"schemas",
|
|
6583
|
+
name
|
|
6584
|
+
]);
|
|
6555
6585
|
const schema = context.spec.components.schemas[name];
|
|
6556
6586
|
parseSchema$1({
|
|
6557
6587
|
$ref,
|
|
@@ -6802,7 +6832,7 @@ const mediaTypeObjects = ({ content }) => {
|
|
|
6802
6832
|
};
|
|
6803
6833
|
//#endregion
|
|
6804
6834
|
//#region src/openApi/3.1.x/parser/schema.ts
|
|
6805
|
-
function getSchemaTypes(
|
|
6835
|
+
function getSchemaTypes(schema) {
|
|
6806
6836
|
if (typeof schema.type === "string") return [schema.type];
|
|
6807
6837
|
if (schema.type) return schema.type;
|
|
6808
6838
|
if (schema.properties) return ["object"];
|
|
@@ -6861,7 +6891,7 @@ function findDiscriminatorsInSchema({ context, discriminators = [], schema }) {
|
|
|
6861
6891
|
*/
|
|
6862
6892
|
function getAllDiscriminatorValues({ discriminator, schemaRef }) {
|
|
6863
6893
|
const values = [];
|
|
6864
|
-
for (const
|
|
6894
|
+
for (const value in discriminator.mapping) if (discriminator.mapping[value] === schemaRef) values.push(value);
|
|
6865
6895
|
return values;
|
|
6866
6896
|
}
|
|
6867
6897
|
function parseSchemaJsDoc({ irSchema, schema }) {
|
|
@@ -6923,10 +6953,7 @@ function parseArray({ context, irSchema = {}, schema, state }) {
|
|
|
6923
6953
|
if (!schemaItems.length && schema.maxItems && schema.maxItems === schema.minItems) schemaItems = Array(schema.maxItems).fill(irItemsSchema);
|
|
6924
6954
|
else {
|
|
6925
6955
|
const ofArray = schema.items.allOf || schema.items.anyOf || schema.items.oneOf;
|
|
6926
|
-
if (ofArray && ofArray.length > 1 && !getSchemaTypes(
|
|
6927
|
-
...irSchema,
|
|
6928
|
-
...irItemsSchema
|
|
6929
|
-
};
|
|
6956
|
+
if (ofArray && ofArray.length > 1 && !getSchemaTypes(schema.items).includes("null")) Object.assign(irSchema, irItemsSchema);
|
|
6930
6957
|
else schemaItems.push(irItemsSchema);
|
|
6931
6958
|
}
|
|
6932
6959
|
}
|
|
@@ -6950,25 +6977,21 @@ function parseNumber({ irSchema = {}, schema }) {
|
|
|
6950
6977
|
}
|
|
6951
6978
|
function parseObject({ context, irSchema = {}, schema, state }) {
|
|
6952
6979
|
irSchema.type = "object";
|
|
6953
|
-
|
|
6954
|
-
|
|
6955
|
-
const
|
|
6956
|
-
|
|
6957
|
-
|
|
6958
|
-
|
|
6959
|
-
|
|
6960
|
-
|
|
6980
|
+
let isSchemaPropertiesEmpty = true;
|
|
6981
|
+
if (schema.properties) {
|
|
6982
|
+
const schemaProperties = {};
|
|
6983
|
+
for (const name in schema.properties) {
|
|
6984
|
+
isSchemaPropertiesEmpty = false;
|
|
6985
|
+
const property = schema.properties[name];
|
|
6986
|
+
if (typeof property === "boolean") {} else schemaProperties[name] = schemaToIrSchema({
|
|
6987
|
+
context,
|
|
6988
|
+
schema: property,
|
|
6989
|
+
state
|
|
6990
|
+
});
|
|
6991
|
+
}
|
|
6992
|
+
if (!isSchemaPropertiesEmpty) irSchema.properties = schemaProperties;
|
|
6961
6993
|
}
|
|
6962
|
-
|
|
6963
|
-
if (schema.additionalProperties === void 0) {
|
|
6964
|
-
if (!irSchema.properties) irSchema.additionalProperties = { type: "unknown" };
|
|
6965
|
-
} else if (typeof schema.additionalProperties === "boolean") {
|
|
6966
|
-
if (!(state.inAllOf && schema.additionalProperties === false && (!schema.properties || !Object.keys(schema.properties).length) && (!schema.patternProperties || !Object.keys(schema.patternProperties).length))) irSchema.additionalProperties = { type: schema.additionalProperties ? "unknown" : "never" };
|
|
6967
|
-
} else irSchema.additionalProperties = schemaToIrSchema({
|
|
6968
|
-
context,
|
|
6969
|
-
schema: schema.additionalProperties,
|
|
6970
|
-
state
|
|
6971
|
-
});
|
|
6994
|
+
let isPatternPropertiesEmpty = true;
|
|
6972
6995
|
if (schema.patternProperties) {
|
|
6973
6996
|
const patternProperties = {};
|
|
6974
6997
|
for (const pattern in schema.patternProperties) {
|
|
@@ -6978,9 +7001,19 @@ function parseObject({ context, irSchema = {}, schema, state }) {
|
|
|
6978
7001
|
schema: patternSchema,
|
|
6979
7002
|
state
|
|
6980
7003
|
});
|
|
7004
|
+
isPatternPropertiesEmpty = false;
|
|
6981
7005
|
}
|
|
6982
|
-
if (
|
|
7006
|
+
if (!isPatternPropertiesEmpty) irSchema.patternProperties = patternProperties;
|
|
6983
7007
|
}
|
|
7008
|
+
if (schema.additionalProperties === void 0) {
|
|
7009
|
+
if (!irSchema.properties) irSchema.additionalProperties = { type: "unknown" };
|
|
7010
|
+
} else if (typeof schema.additionalProperties === "boolean") {
|
|
7011
|
+
if (!(state.inAllOf && schema.additionalProperties === false && (!schema.properties || isSchemaPropertiesEmpty) && (!schema.patternProperties || isPatternPropertiesEmpty))) irSchema.additionalProperties = { type: schema.additionalProperties ? "unknown" : "never" };
|
|
7012
|
+
} else irSchema.additionalProperties = schemaToIrSchema({
|
|
7013
|
+
context,
|
|
7014
|
+
schema: schema.additionalProperties,
|
|
7015
|
+
state
|
|
7016
|
+
});
|
|
6984
7017
|
if (schema.propertyNames) irSchema.propertyNames = schemaToIrSchema({
|
|
6985
7018
|
context,
|
|
6986
7019
|
schema: schema.propertyNames,
|
|
@@ -7034,7 +7067,7 @@ function parseAllOf({ context, schema, state }) {
|
|
|
7034
7067
|
schema
|
|
7035
7068
|
});
|
|
7036
7069
|
const schemaItems = [];
|
|
7037
|
-
const schemaTypes = getSchemaTypes(
|
|
7070
|
+
const schemaTypes = getSchemaTypes(schema);
|
|
7038
7071
|
const compositionSchemas = schema.allOf;
|
|
7039
7072
|
const discriminatorsToAdd = [];
|
|
7040
7073
|
for (const compositionSchema of compositionSchemas) {
|
|
@@ -7046,8 +7079,7 @@ function parseAllOf({ context, schema, state }) {
|
|
|
7046
7079
|
state
|
|
7047
7080
|
});
|
|
7048
7081
|
state.inAllOf = originalInAllOf;
|
|
7049
|
-
if (
|
|
7050
|
-
if (schema.required) if (irCompositionSchema.required) irCompositionSchema.required = [...irCompositionSchema.required, ...schema.required];
|
|
7082
|
+
if (schema.required) if (irCompositionSchema.required) irCompositionSchema.required.push(...schema.required);
|
|
7051
7083
|
else irCompositionSchema.required = schema.required;
|
|
7052
7084
|
schemaItems.push(irCompositionSchema);
|
|
7053
7085
|
if (compositionSchema.$ref) {
|
|
@@ -7122,7 +7154,7 @@ function parseAllOf({ context, schema, state }) {
|
|
|
7122
7154
|
inlineSchema.properties[discriminator.propertyName] = discriminatorProperty;
|
|
7123
7155
|
if (isRequired) {
|
|
7124
7156
|
if (!inlineSchema.required) inlineSchema.required = [];
|
|
7125
|
-
if (!inlineSchema.required.includes(discriminator.propertyName)) inlineSchema.required
|
|
7157
|
+
if (!inlineSchema.required.includes(discriminator.propertyName)) inlineSchema.required.push(discriminator.propertyName);
|
|
7126
7158
|
}
|
|
7127
7159
|
} else {
|
|
7128
7160
|
const irDiscriminatorSchema = {
|
|
@@ -7145,7 +7177,7 @@ function parseAllOf({ context, schema, state }) {
|
|
|
7145
7177
|
if (irObjectSchema.properties) {
|
|
7146
7178
|
for (const requiredProperty of irObjectSchema.required ?? []) if (!irObjectSchema.properties[requiredProperty]) for (const compositionSchema of compositionSchemas) {
|
|
7147
7179
|
const finalCompositionSchema = compositionSchema.$ref ? context.resolveRef(compositionSchema.$ref) : compositionSchema;
|
|
7148
|
-
if (getSchemaTypes(
|
|
7180
|
+
if (getSchemaTypes(finalCompositionSchema).includes("object")) {
|
|
7149
7181
|
const irCompositionSchema = parseOneType({
|
|
7150
7182
|
context,
|
|
7151
7183
|
schema: {
|
|
@@ -7186,7 +7218,7 @@ function parseAnyOf({ context, schema, state }) {
|
|
|
7186
7218
|
schema
|
|
7187
7219
|
});
|
|
7188
7220
|
const schemaItems = [];
|
|
7189
|
-
const schemaTypes = getSchemaTypes(
|
|
7221
|
+
const schemaTypes = getSchemaTypes(schema);
|
|
7190
7222
|
const compositionSchemas = schema.anyOf;
|
|
7191
7223
|
const discriminatorPropertyType = schema.discriminator ? findDiscriminatorPropertyType({
|
|
7192
7224
|
context,
|
|
@@ -7245,8 +7277,12 @@ function parseEnum({ context, schema, state }) {
|
|
|
7245
7277
|
});
|
|
7246
7278
|
irSchema.type = "enum";
|
|
7247
7279
|
const schemaItems = [];
|
|
7248
|
-
const schemaTypes = getSchemaTypes(
|
|
7249
|
-
|
|
7280
|
+
const schemaTypes = getSchemaTypes(schema);
|
|
7281
|
+
const xEnumDescriptions = schema["x-enum-descriptions"];
|
|
7282
|
+
const xEnumVarnames = schema["x-enum-varnames"];
|
|
7283
|
+
const xEnumNames = schema["x-enumNames"];
|
|
7284
|
+
for (let index = 0, len = schema.enum.length; index < len; index++) {
|
|
7285
|
+
const enumValue = schema.enum[index];
|
|
7250
7286
|
const typeOfEnumValue = typeof enumValue;
|
|
7251
7287
|
let enumType;
|
|
7252
7288
|
if (typeOfEnumValue === "string" || typeOfEnumValue === "number" || typeOfEnumValue === "boolean") enumType = typeOfEnumValue;
|
|
@@ -7259,8 +7295,8 @@ function parseEnum({ context, schema, state }) {
|
|
|
7259
7295
|
context,
|
|
7260
7296
|
schema: {
|
|
7261
7297
|
const: enumValue,
|
|
7262
|
-
description:
|
|
7263
|
-
title:
|
|
7298
|
+
description: xEnumDescriptions?.[index],
|
|
7299
|
+
title: xEnumVarnames?.[index] ?? xEnumNames?.[index],
|
|
7264
7300
|
type: enumType
|
|
7265
7301
|
},
|
|
7266
7302
|
state
|
|
@@ -7280,7 +7316,7 @@ function parseOneOf({ context, schema, state }) {
|
|
|
7280
7316
|
schema
|
|
7281
7317
|
});
|
|
7282
7318
|
let schemaItems = [];
|
|
7283
|
-
const schemaTypes = getSchemaTypes(
|
|
7319
|
+
const schemaTypes = getSchemaTypes(schema);
|
|
7284
7320
|
const compositionSchemas = schema.oneOf;
|
|
7285
7321
|
const discriminatorPropertyType = schema.discriminator ? findDiscriminatorPropertyType({
|
|
7286
7322
|
context,
|
|
@@ -7461,7 +7497,7 @@ function parseType({ context, schema, state }) {
|
|
|
7461
7497
|
irSchema,
|
|
7462
7498
|
schema
|
|
7463
7499
|
});
|
|
7464
|
-
const schemaTypes = getSchemaTypes(
|
|
7500
|
+
const schemaTypes = getSchemaTypes(schema);
|
|
7465
7501
|
if (schemaTypes.length === 1) return parseOneType({
|
|
7466
7502
|
context,
|
|
7467
7503
|
irSchema,
|
|
@@ -7579,11 +7615,11 @@ const paginationField = ({ context, name, schema }) => {
|
|
|
7579
7615
|
for (const name in schema.properties) if (getPaginationKeywordsRegExp(context.config.parser.pagination).test(name)) {
|
|
7580
7616
|
const property = schema.properties[name];
|
|
7581
7617
|
if (typeof property !== "boolean") {
|
|
7582
|
-
const schemaTypes = getSchemaTypes(
|
|
7618
|
+
const schemaTypes = getSchemaTypes(property);
|
|
7583
7619
|
if (!schemaTypes.length) {
|
|
7584
7620
|
const nonNullCompositionSchemas = (property.anyOf ?? property.oneOf ?? []).filter((schema) => schema.type !== "null");
|
|
7585
7621
|
if (nonNullCompositionSchemas.length === 1) {
|
|
7586
|
-
if (isPaginationType(getSchemaTypes(
|
|
7622
|
+
if (isPaginationType(getSchemaTypes(nonNullCompositionSchemas[0]))) return name;
|
|
7587
7623
|
}
|
|
7588
7624
|
}
|
|
7589
7625
|
if (isPaginationType(schemaTypes)) return name;
|
|
@@ -8125,7 +8161,11 @@ const parseV3_1_X = (context) => {
|
|
|
8125
8161
|
securitySchemesMap.set(name, securitySchemeObject);
|
|
8126
8162
|
}
|
|
8127
8163
|
for (const name in context.spec.components.parameters) {
|
|
8128
|
-
const $ref =
|
|
8164
|
+
const $ref = pathToJsonPointer([
|
|
8165
|
+
"components",
|
|
8166
|
+
"parameters",
|
|
8167
|
+
name
|
|
8168
|
+
]);
|
|
8129
8169
|
const parameterOrReference = context.spec.components.parameters[name];
|
|
8130
8170
|
parseParameter({
|
|
8131
8171
|
$ref,
|
|
@@ -8134,7 +8174,11 @@ const parseV3_1_X = (context) => {
|
|
|
8134
8174
|
});
|
|
8135
8175
|
}
|
|
8136
8176
|
for (const name in context.spec.components.requestBodies) {
|
|
8137
|
-
const $ref =
|
|
8177
|
+
const $ref = pathToJsonPointer([
|
|
8178
|
+
"components",
|
|
8179
|
+
"requestBodies",
|
|
8180
|
+
name
|
|
8181
|
+
]);
|
|
8138
8182
|
const requestBodyOrReference = context.spec.components.requestBodies[name];
|
|
8139
8183
|
parseRequestBody({
|
|
8140
8184
|
$ref,
|
|
@@ -8143,7 +8187,11 @@ const parseV3_1_X = (context) => {
|
|
|
8143
8187
|
});
|
|
8144
8188
|
}
|
|
8145
8189
|
for (const name in context.spec.components.schemas) {
|
|
8146
|
-
const $ref =
|
|
8190
|
+
const $ref = pathToJsonPointer([
|
|
8191
|
+
"components",
|
|
8192
|
+
"schemas",
|
|
8193
|
+
name
|
|
8194
|
+
]);
|
|
8147
8195
|
const schema = context.spec.components.schemas[name];
|
|
8148
8196
|
parseSchema({
|
|
8149
8197
|
$ref,
|
|
@@ -8523,8 +8571,18 @@ const definePluginConfig = (defaultConfig) => (userConfig) => ({
|
|
|
8523
8571
|
*/
|
|
8524
8572
|
const mappers = {
|
|
8525
8573
|
boolean: (enabled) => ({ enabled }),
|
|
8526
|
-
function: (name) => ({
|
|
8527
|
-
|
|
8574
|
+
function: (name) => ({
|
|
8575
|
+
enabled: true,
|
|
8576
|
+
name
|
|
8577
|
+
}),
|
|
8578
|
+
object: (fields) => ({
|
|
8579
|
+
enabled: true,
|
|
8580
|
+
...fields
|
|
8581
|
+
}),
|
|
8582
|
+
string: (name) => ({
|
|
8583
|
+
enabled: true,
|
|
8584
|
+
name
|
|
8585
|
+
})
|
|
8528
8586
|
};
|
|
8529
8587
|
//#endregion
|
|
8530
8588
|
//#region src/plugins/symbol.ts
|
|
@@ -8532,9 +8590,8 @@ const mappers = {
|
|
|
8532
8590
|
* Helper function to build the input for symbol registration, applying naming hooks if provided.
|
|
8533
8591
|
*/
|
|
8534
8592
|
function buildSymbolIn({ plugin, ...ctx }) {
|
|
8535
|
-
const hooks =
|
|
8593
|
+
const hooks = plugin.getHooks((hooks) => hooks.symbols?.getName);
|
|
8536
8594
|
for (const hook of hooks) {
|
|
8537
|
-
if (!hook) continue;
|
|
8538
8595
|
const result = hook(ctx);
|
|
8539
8596
|
if (typeof result === "function") {
|
|
8540
8597
|
const name = result(ctx);
|