@hey-api/shared 0.4.4 → 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.mjs CHANGED
@@ -968,17 +968,13 @@ function deduplicateSchema({ detectFormat = true, schema }) {
968
968
  }
969
969
  uniqueItems.push(item);
970
970
  }
971
- let result = { ...schema };
972
- result.items = uniqueItems;
973
- if (result.items.length <= 1 && result.type !== "array" && result.type !== "enum" && result.type !== "tuple") {
974
- const liftedSchema = result.items[0];
975
- delete result.logicalOperator;
976
- delete result.items;
977
- result = {
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
- const patterns = {
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 Object.keys(patterns)) {
1718
- const kind = key;
1719
- if (patterns[kind].test(pointer)) return {
1720
- kind,
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
- const path = refOrPath instanceof Array ? refOrPath : jsonPointerToPath(refOrPath);
1834
- if (path[0] === "components") return path.length === 3;
1835
- if (path[0] === "definitions") return path.length === 2;
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
@@ -2139,9 +2151,8 @@ var PluginInstance = class {
2139
2151
  });
2140
2152
  }
2141
2153
  getSymbolExportFromFilePath(symbol) {
2142
- const hooks = [this.config["~hooks"]?.symbols, this.context.config.parser.hooks.symbols];
2143
- for (const hook of hooks) {
2144
- const result = hook?.getExportFromFilePath?.(symbol);
2154
+ for (const hook of this.getHooks((hooks) => hooks.symbols?.getExportFromFilePath)) {
2155
+ const result = hook(symbol);
2145
2156
  if (result !== void 0) return result;
2146
2157
  }
2147
2158
  const entryFile = this.context.config.output.indexFile ?? this.context.config.output.entryFile;
@@ -2155,9 +2166,8 @@ var PluginInstance = class {
2155
2166
  return [moduleEntryName];
2156
2167
  }
2157
2168
  getSymbolFilePath(symbol) {
2158
- const hooks = [this.config["~hooks"]?.symbols, this.context.config.parser.hooks.symbols];
2159
- for (const hook of hooks) {
2160
- const result = hook?.getFilePath?.(symbol);
2169
+ for (const hook of this.getHooks((hooks) => hooks.symbols?.getFilePath)) {
2170
+ const result = hook(symbol);
2161
2171
  if (result !== void 0) return result;
2162
2172
  }
2163
2173
  return defaultGetFilePath(symbol);
@@ -2407,8 +2417,8 @@ function visitTyped(schema, ctx, visitor, walk) {
2407
2417
  */
2408
2418
  function childContext(ctx, ...segments) {
2409
2419
  return {
2410
- ...ctx,
2411
- path: ref([...fromRef(ctx.path), ...segments])
2420
+ path: ref([...fromRef(ctx.path), ...segments]),
2421
+ plugin: ctx.plugin
2412
2422
  };
2413
2423
  }
2414
2424
  //#endregion
@@ -3335,42 +3345,37 @@ const annotateChildScopes = (nodes) => {
3335
3345
  * Recursively collects all $ref dependencies in the subtree rooted at `pointer`.
3336
3346
  */
3337
3347
  const collectPointerDependencies = ({ cache, graph, pointer, visited }) => {
3338
- const cached = cache.transitiveDependencies.get(pointer);
3339
- if (cached) return {
3340
- subtreeDependencies: cache.subtreeDependencies.get(pointer),
3341
- transitiveDependencies: cached
3348
+ if (cache.transitiveDependencies.has(pointer)) return {
3349
+ subtreeDependencies: cache.subtreeDependencies.get(pointer) ?? null,
3350
+ transitiveDependencies: cache.transitiveDependencies.get(pointer) ?? null
3342
3351
  };
3343
3352
  if (visited.has(pointer)) return {
3344
- subtreeDependencies: /* @__PURE__ */ new Set(),
3345
- transitiveDependencies: /* @__PURE__ */ new Set()
3353
+ subtreeDependencies: null,
3354
+ transitiveDependencies: null
3346
3355
  };
3347
3356
  visited.add(pointer);
3348
3357
  if (!graph.nodes.get(pointer)) return {
3349
- subtreeDependencies: /* @__PURE__ */ new Set(),
3350
- transitiveDependencies: /* @__PURE__ */ new Set()
3358
+ subtreeDependencies: null,
3359
+ transitiveDependencies: null
3351
3360
  };
3352
- const transitiveDependencies = /* @__PURE__ */ new Set();
3353
- const subtreeDependencies = /* @__PURE__ */ new Set();
3361
+ let transitiveDependencies = null;
3362
+ let subtreeDependencies = null;
3354
3363
  const nodeDependencies = graph.nodeDependencies.get(pointer);
3355
3364
  if (nodeDependencies) for (const depPointer of nodeDependencies) {
3356
- transitiveDependencies.add(depPointer);
3357
- subtreeDependencies.add(depPointer);
3365
+ (transitiveDependencies ??= /* @__PURE__ */ new Set()).add(depPointer);
3366
+ (subtreeDependencies ??= /* @__PURE__ */ new Set()).add(depPointer);
3358
3367
  const depResult = collectPointerDependencies({
3359
3368
  cache,
3360
3369
  graph,
3361
3370
  pointer: depPointer,
3362
3371
  visited
3363
3372
  });
3364
- for (const dependency of depResult.transitiveDependencies) transitiveDependencies.add(dependency);
3373
+ if (depResult.transitiveDependencies) for (const dependency of depResult.transitiveDependencies) transitiveDependencies.add(dependency);
3365
3374
  }
3366
3375
  const children = cache.parentToChildren.get(pointer) ?? [];
3367
3376
  for (const childPointer of children) {
3368
- let childResult = {
3369
- subtreeDependencies: cache.subtreeDependencies.get(childPointer),
3370
- transitiveDependencies: cache.transitiveDependencies.get(childPointer)
3371
- };
3372
- if (!childResult.subtreeDependencies || !childResult.transitiveDependencies) {
3373
- childResult = collectPointerDependencies({
3377
+ if (!cache.transitiveDependencies.has(childPointer)) {
3378
+ const childResult = collectPointerDependencies({
3374
3379
  cache,
3375
3380
  graph,
3376
3381
  pointer: childPointer,
@@ -3379,8 +3384,10 @@ const collectPointerDependencies = ({ cache, graph, pointer, visited }) => {
3379
3384
  cache.transitiveDependencies.set(childPointer, childResult.transitiveDependencies);
3380
3385
  cache.subtreeDependencies.set(childPointer, childResult.subtreeDependencies);
3381
3386
  }
3382
- for (const dependency of childResult.transitiveDependencies) transitiveDependencies.add(dependency);
3383
- for (const dependency of childResult.subtreeDependencies) subtreeDependencies.add(dependency);
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);
3384
3391
  }
3385
3392
  cache.transitiveDependencies.set(pointer, transitiveDependencies);
3386
3393
  cache.subtreeDependencies.set(pointer, subtreeDependencies);
@@ -3538,8 +3545,8 @@ function buildGraph(root, logger) {
3538
3545
  pointer,
3539
3546
  visited: /* @__PURE__ */ new Set()
3540
3547
  });
3541
- graph.transitiveDependencies.set(pointer, result.transitiveDependencies);
3542
- 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);
3543
3550
  }
3544
3551
  eventBuildGraph.timeEnd();
3545
3552
  return { graph };
@@ -4346,7 +4353,7 @@ const discriminatorValues = ($ref, mapping, shouldUseRefAsValue) => {
4346
4353
  };
4347
4354
  //#endregion
4348
4355
  //#region src/openApi/2.0.x/parser/schema.ts
4349
- function getSchemaType$1({ schema }) {
4356
+ function getSchemaType$1(schema) {
4350
4357
  if (schema.type) return schema.type;
4351
4358
  if (schema.properties) return "object";
4352
4359
  }
@@ -4385,10 +4392,7 @@ function parseArray$2({ context, irSchema = {}, schema, state }) {
4385
4392
  else if ("$ref" in schema.items) schemaItems.push(irItemsSchema);
4386
4393
  else {
4387
4394
  const ofArray = schema.items.allOf;
4388
- if (ofArray && ofArray.length > 1 && !schema.items["x-nullable"]) irSchema = {
4389
- ...irSchema,
4390
- ...irItemsSchema
4391
- };
4395
+ if (ofArray && ofArray.length > 1 && !schema.items["x-nullable"]) Object.assign(irSchema, irItemsSchema);
4392
4396
  else schemaItems.push(irItemsSchema);
4393
4397
  }
4394
4398
  }
@@ -4408,20 +4412,24 @@ function parseNumber$2({ irSchema = {}, schema }) {
4408
4412
  }
4409
4413
  function parseObject$2({ context, irSchema = {}, schema, state }) {
4410
4414
  irSchema.type = "object";
4411
- const schemaProperties = {};
4412
- for (const name in schema.properties) {
4413
- const property = schema.properties[name];
4414
- if (typeof property === "boolean") {} else schemaProperties[name] = schemaToIrSchema$2({
4415
- context,
4416
- schema: property,
4417
- state
4418
- });
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;
4419
4428
  }
4420
- if (Object.keys(schemaProperties).length) irSchema.properties = schemaProperties;
4421
4429
  if (schema.additionalProperties === void 0) {
4422
4430
  if (!irSchema.properties) irSchema.additionalProperties = { type: "unknown" };
4423
4431
  } else if (typeof schema.additionalProperties === "boolean") {
4424
- if (!(state.inAllOf && schema.additionalProperties === false && (!schema.properties || !Object.keys(schema.properties).length))) irSchema.additionalProperties = { type: schema.additionalProperties ? "unknown" : "never" };
4432
+ if (!(state.inAllOf && schema.additionalProperties === false && (!schema.properties || isSchemaPropertiesEmpty))) irSchema.additionalProperties = { type: schema.additionalProperties ? "unknown" : "never" };
4425
4433
  } else irSchema.additionalProperties = schemaToIrSchema$2({
4426
4434
  context,
4427
4435
  schema: schema.additionalProperties,
@@ -4452,7 +4460,7 @@ function initIrSchema$2({ schema }) {
4452
4460
  function parseAllOf$2({ context, schema, state }) {
4453
4461
  let irSchema = initIrSchema$2({ schema });
4454
4462
  const schemaItems = [];
4455
- const schemaType = getSchemaType$1({ schema });
4463
+ const schemaType = getSchemaType$1(schema);
4456
4464
  const compositionSchemas = schema.allOf;
4457
4465
  for (const compositionSchema of compositionSchemas) {
4458
4466
  const originalInAllOf = state.inAllOf;
@@ -4463,8 +4471,7 @@ function parseAllOf$2({ context, schema, state }) {
4463
4471
  state
4464
4472
  });
4465
4473
  state.inAllOf = originalInAllOf;
4466
- if (state.inAllOf === void 0) delete state.inAllOf;
4467
- if (schema.required) if (irCompositionSchema.required) irCompositionSchema.required = [...irCompositionSchema.required, ...schema.required];
4474
+ if (schema.required) if (irCompositionSchema.required) irCompositionSchema.required.push(...schema.required);
4468
4475
  else irCompositionSchema.required = schema.required;
4469
4476
  schemaItems.push(irCompositionSchema);
4470
4477
  if (compositionSchema.$ref) {
@@ -4498,7 +4505,7 @@ function parseAllOf$2({ context, schema, state }) {
4498
4505
  if (irObjectSchema.properties) {
4499
4506
  for (const requiredProperty of irObjectSchema.required ?? []) if (!irObjectSchema.properties[requiredProperty]) for (const compositionSchema of compositionSchemas) {
4500
4507
  const finalCompositionSchema = compositionSchema.$ref ? context.resolveRef(compositionSchema.$ref) : compositionSchema;
4501
- if (getSchemaType$1({ schema: finalCompositionSchema }) === "object") {
4508
+ if (getSchemaType$1(finalCompositionSchema) === "object") {
4502
4509
  const irCompositionSchema = parseOneType$2({
4503
4510
  context,
4504
4511
  schema: {
@@ -4542,7 +4549,11 @@ function parseEnum$2({ context, schema, state }) {
4542
4549
  });
4543
4550
  irSchema.type = "enum";
4544
4551
  const schemaItems = [];
4545
- for (const [index, enumValue] of schema.enum.entries()) {
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];
4546
4557
  const typeOfEnumValue = typeof enumValue;
4547
4558
  let enumType;
4548
4559
  if (typeOfEnumValue === "string" || typeOfEnumValue === "number" || typeOfEnumValue === "boolean") enumType = typeOfEnumValue;
@@ -4554,8 +4565,8 @@ function parseEnum$2({ context, schema, state }) {
4554
4565
  const irTypeSchema = parseOneType$2({
4555
4566
  context,
4556
4567
  schema: {
4557
- description: schema["x-enum-descriptions"]?.[index],
4558
- title: schema["x-enum-varnames"]?.[index] ?? schema["x-enumNames"]?.[index],
4568
+ description: xEnumDescriptions?.[index],
4569
+ title: xEnumVarnames?.[index] ?? xEnumNames?.[index],
4559
4570
  type: enumType === "null" ? "string" : enumType
4560
4571
  },
4561
4572
  state
@@ -4627,7 +4638,7 @@ function parseType$2({ context, schema, state }) {
4627
4638
  irSchema,
4628
4639
  schema
4629
4640
  });
4630
- const type = getSchemaType$1({ schema });
4641
+ const type = getSchemaType$1(schema);
4631
4642
  if (!type) return irSchema;
4632
4643
  if (schema["x-nullable"]) return parseNullableType$1({
4633
4644
  context,
@@ -4779,7 +4790,7 @@ const paginationField$2 = ({ context, name, schema }) => {
4779
4790
  for (const name in schema.properties) if (getPaginationKeywordsRegExp(context.config.parser.pagination).test(name)) {
4780
4791
  const property = schema.properties[name];
4781
4792
  if (typeof property !== "boolean" && !("$ref" in property)) {
4782
- if (isPaginationType$2(getSchemaType$1({ schema: property }))) return name;
4793
+ if (isPaginationType$2(getSchemaType$1(property))) return name;
4783
4794
  }
4784
4795
  }
4785
4796
  for (const allOf of schema.allOf ?? []) {
@@ -5196,7 +5207,7 @@ const parseV2_0_X = (context) => {
5196
5207
  securitySchemesMap.set(name, securitySchemeObject);
5197
5208
  }
5198
5209
  if (context.spec.definitions) for (const name in context.spec.definitions) {
5199
- const $ref = `#/definitions/${name}`;
5210
+ const $ref = pathToJsonPointer(["definitions", name]);
5200
5211
  const schema = context.spec.definitions[name];
5201
5212
  parseSchema$2({
5202
5213
  $ref,
@@ -5464,7 +5475,7 @@ const mediaTypeObjects$1 = ({ content }) => {
5464
5475
  };
5465
5476
  //#endregion
5466
5477
  //#region src/openApi/3.0.x/parser/schema.ts
5467
- function getSchemaType({ schema }) {
5478
+ function getSchemaType(schema) {
5468
5479
  if (schema.type) return schema.type;
5469
5480
  if (schema.properties) return "object";
5470
5481
  }
@@ -5519,7 +5530,7 @@ function findDiscriminatorsInSchema$1({ context, discriminators = [], schema })
5519
5530
  */
5520
5531
  function getAllDiscriminatorValues$1({ discriminator, schemaRef }) {
5521
5532
  const values = [];
5522
- for (const [value, mappedSchemaRef] of Object.entries(discriminator.mapping || {})) if (mappedSchemaRef === schemaRef) values.push(value);
5533
+ for (const value in discriminator.mapping) if (discriminator.mapping[value] === schemaRef) values.push(value);
5523
5534
  return values;
5524
5535
  }
5525
5536
  function parseSchemaJsDoc$1({ irSchema, schema }) {
@@ -5559,10 +5570,7 @@ function parseArray$1({ context, irSchema = {}, schema, state }) {
5559
5570
  else if ("$ref" in schema.items) schemaItems.push(irItemsSchema);
5560
5571
  else {
5561
5572
  const ofArray = schema.items.allOf || schema.items.anyOf || schema.items.oneOf;
5562
- if (ofArray && ofArray.length > 1 && !schema.items.nullable) irSchema = {
5563
- ...irSchema,
5564
- ...irItemsSchema
5565
- };
5573
+ if (ofArray && ofArray.length > 1 && !schema.items.nullable) Object.assign(irSchema, irItemsSchema);
5566
5574
  else schemaItems.push(irItemsSchema);
5567
5575
  }
5568
5576
  }
@@ -5582,20 +5590,24 @@ function parseNumber$1({ irSchema = {}, schema }) {
5582
5590
  }
5583
5591
  function parseObject$1({ context, irSchema = {}, schema, state }) {
5584
5592
  irSchema.type = "object";
5585
- const schemaProperties = {};
5586
- for (const name in schema.properties) {
5587
- const property = schema.properties[name];
5588
- if (typeof property === "boolean") {} else schemaProperties[name] = schemaToIrSchema$1({
5589
- context,
5590
- schema: property,
5591
- state
5592
- });
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;
5593
5606
  }
5594
- if (Object.keys(schemaProperties).length) irSchema.properties = schemaProperties;
5595
5607
  if (schema.additionalProperties === void 0) {
5596
5608
  if (!irSchema.properties) irSchema.additionalProperties = { type: "unknown" };
5597
5609
  } else if (typeof schema.additionalProperties === "boolean") {
5598
- if (!(state.inAllOf && schema.additionalProperties === false && (!schema.properties || !Object.keys(schema.properties).length))) irSchema.additionalProperties = { type: schema.additionalProperties ? "unknown" : "never" };
5610
+ if (!(state.inAllOf && schema.additionalProperties === false && (!schema.properties || isSchemaPropertiesEmpty))) irSchema.additionalProperties = { type: schema.additionalProperties ? "unknown" : "never" };
5599
5611
  } else irSchema.additionalProperties = schemaToIrSchema$1({
5600
5612
  context,
5601
5613
  schema: schema.additionalProperties,
@@ -5645,7 +5657,7 @@ function initIrSchema$1({ schema }) {
5645
5657
  function parseAllOf$1({ context, schema, state }) {
5646
5658
  let irSchema = initIrSchema$1({ schema });
5647
5659
  const schemaItems = [];
5648
- const schemaType = getSchemaType({ schema });
5660
+ const schemaType = getSchemaType(schema);
5649
5661
  const compositionSchemas = schema.allOf;
5650
5662
  const discriminatorsToAdd = [];
5651
5663
  for (const compositionSchema of compositionSchemas) {
@@ -5657,8 +5669,7 @@ function parseAllOf$1({ context, schema, state }) {
5657
5669
  state
5658
5670
  });
5659
5671
  state.inAllOf = originalInAllOf;
5660
- if (state.inAllOf === void 0) delete state.inAllOf;
5661
- if (schema.required) if (irCompositionSchema.required) irCompositionSchema.required = [...irCompositionSchema.required, ...schema.required];
5672
+ if (schema.required) if (irCompositionSchema.required) irCompositionSchema.required.push(...schema.required);
5662
5673
  else irCompositionSchema.required = schema.required;
5663
5674
  schemaItems.push(irCompositionSchema);
5664
5675
  if ("$ref" in compositionSchema) {
@@ -5733,7 +5744,7 @@ function parseAllOf$1({ context, schema, state }) {
5733
5744
  inlineSchema.properties[discriminator.propertyName] = discriminatorProperty;
5734
5745
  if (isRequired) {
5735
5746
  if (!inlineSchema.required) inlineSchema.required = [];
5736
- if (!inlineSchema.required.includes(discriminator.propertyName)) inlineSchema.required = [...inlineSchema.required, discriminator.propertyName];
5747
+ if (!inlineSchema.required.includes(discriminator.propertyName)) inlineSchema.required.push(discriminator.propertyName);
5737
5748
  }
5738
5749
  } else {
5739
5750
  const irDiscriminatorSchema = {
@@ -5756,7 +5767,7 @@ function parseAllOf$1({ context, schema, state }) {
5756
5767
  if (irObjectSchema.properties) {
5757
5768
  for (const requiredProperty of irObjectSchema.required ?? []) if (!irObjectSchema.properties[requiredProperty]) for (const compositionSchema of compositionSchemas) {
5758
5769
  const finalCompositionSchema = "$ref" in compositionSchema ? context.resolveRef(compositionSchema.$ref) : compositionSchema;
5759
- if (getSchemaType({ schema: finalCompositionSchema }) === "object") {
5770
+ if (getSchemaType(finalCompositionSchema) === "object") {
5760
5771
  const irCompositionSchema = parseOneType$1({
5761
5772
  context,
5762
5773
  schema: {
@@ -5795,7 +5806,7 @@ function parseAllOf$1({ context, schema, state }) {
5795
5806
  function parseAnyOf$1({ context, schema, state }) {
5796
5807
  let irSchema = initIrSchema$1({ schema });
5797
5808
  const schemaItems = [];
5798
- const schemaType = getSchemaType({ schema });
5809
+ const schemaType = getSchemaType(schema);
5799
5810
  const compositionSchemas = schema.anyOf;
5800
5811
  const discriminatorPropertyType = schema.discriminator ? findDiscriminatorPropertyType$1({
5801
5812
  context,
@@ -5854,7 +5865,11 @@ function parseEnum$1({ context, schema, state }) {
5854
5865
  });
5855
5866
  irSchema.type = "enum";
5856
5867
  const schemaItems = [];
5857
- for (const [index, enumValue] of schema.enum.entries()) {
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];
5858
5873
  const typeOfEnumValue = typeof enumValue;
5859
5874
  let enumType;
5860
5875
  if (typeOfEnumValue === "string" || typeOfEnumValue === "number" || typeOfEnumValue === "boolean") enumType = typeOfEnumValue;
@@ -5866,8 +5881,8 @@ function parseEnum$1({ context, schema, state }) {
5866
5881
  const irTypeSchema = parseOneType$1({
5867
5882
  context,
5868
5883
  schema: {
5869
- description: schema["x-enum-descriptions"]?.[index],
5870
- title: schema["x-enum-varnames"]?.[index] ?? schema["x-enumNames"]?.[index],
5884
+ description: xEnumDescriptions?.[index],
5885
+ title: xEnumVarnames?.[index] ?? xEnumNames?.[index],
5871
5886
  type: enumType === "null" ? "string" : enumType
5872
5887
  },
5873
5888
  state
@@ -5886,7 +5901,7 @@ function parseEnum$1({ context, schema, state }) {
5886
5901
  function parseOneOf$1({ context, schema, state }) {
5887
5902
  let irSchema = initIrSchema$1({ schema });
5888
5903
  let schemaItems = [];
5889
- const schemaType = getSchemaType({ schema });
5904
+ const schemaType = getSchemaType(schema);
5890
5905
  const compositionSchemas = schema.oneOf;
5891
5906
  const discriminatorPropertyType = schema.discriminator ? findDiscriminatorPropertyType$1({
5892
5907
  context,
@@ -5994,7 +6009,7 @@ function parseType$1({ context, schema, state }) {
5994
6009
  irSchema,
5995
6010
  schema
5996
6011
  });
5997
- const type = getSchemaType({ schema });
6012
+ const type = getSchemaType(schema);
5998
6013
  if (!type) return irSchema;
5999
6014
  if (!schema.nullable) return parseOneType$1({
6000
6015
  context,
@@ -6152,7 +6167,7 @@ const paginationField$1 = ({ context, name, schema }) => {
6152
6167
  for (const name in schema.properties) if (getPaginationKeywordsRegExp(context.config.parser.pagination).test(name)) {
6153
6168
  const property = schema.properties[name];
6154
6169
  if (typeof property !== "boolean" && !("$ref" in property)) {
6155
- if (isPaginationType$1(getSchemaType({ schema: property }))) return name;
6170
+ if (isPaginationType$1(getSchemaType(property))) return name;
6156
6171
  }
6157
6172
  }
6158
6173
  for (const allOf of schema.allOf ?? []) {
@@ -6536,7 +6551,11 @@ const parseV3_0_X = (context) => {
6536
6551
  securitySchemesMap.set(name, securitySchemeObject);
6537
6552
  }
6538
6553
  for (const name in context.spec.components.parameters) {
6539
- const $ref = `#/components/parameters/${name}`;
6554
+ const $ref = pathToJsonPointer([
6555
+ "components",
6556
+ "parameters",
6557
+ name
6558
+ ]);
6540
6559
  const parameterOrReference = context.spec.components.parameters[name];
6541
6560
  parseParameter$1({
6542
6561
  $ref,
@@ -6545,7 +6564,11 @@ const parseV3_0_X = (context) => {
6545
6564
  });
6546
6565
  }
6547
6566
  for (const name in context.spec.components.requestBodies) {
6548
- const $ref = `#/components/requestBodies/${name}`;
6567
+ const $ref = pathToJsonPointer([
6568
+ "components",
6569
+ "requestBodies",
6570
+ name
6571
+ ]);
6549
6572
  const requestBodyOrReference = context.spec.components.requestBodies[name];
6550
6573
  parseRequestBody$1({
6551
6574
  $ref,
@@ -6554,7 +6577,11 @@ const parseV3_0_X = (context) => {
6554
6577
  });
6555
6578
  }
6556
6579
  for (const name in context.spec.components.schemas) {
6557
- const $ref = `#/components/schemas/${name}`;
6580
+ const $ref = pathToJsonPointer([
6581
+ "components",
6582
+ "schemas",
6583
+ name
6584
+ ]);
6558
6585
  const schema = context.spec.components.schemas[name];
6559
6586
  parseSchema$1({
6560
6587
  $ref,
@@ -6805,7 +6832,7 @@ const mediaTypeObjects = ({ content }) => {
6805
6832
  };
6806
6833
  //#endregion
6807
6834
  //#region src/openApi/3.1.x/parser/schema.ts
6808
- function getSchemaTypes({ schema }) {
6835
+ function getSchemaTypes(schema) {
6809
6836
  if (typeof schema.type === "string") return [schema.type];
6810
6837
  if (schema.type) return schema.type;
6811
6838
  if (schema.properties) return ["object"];
@@ -6864,7 +6891,7 @@ function findDiscriminatorsInSchema({ context, discriminators = [], schema }) {
6864
6891
  */
6865
6892
  function getAllDiscriminatorValues({ discriminator, schemaRef }) {
6866
6893
  const values = [];
6867
- for (const [value, mappedSchemaRef] of Object.entries(discriminator.mapping || {})) if (mappedSchemaRef === schemaRef) values.push(value);
6894
+ for (const value in discriminator.mapping) if (discriminator.mapping[value] === schemaRef) values.push(value);
6868
6895
  return values;
6869
6896
  }
6870
6897
  function parseSchemaJsDoc({ irSchema, schema }) {
@@ -6926,10 +6953,7 @@ function parseArray({ context, irSchema = {}, schema, state }) {
6926
6953
  if (!schemaItems.length && schema.maxItems && schema.maxItems === schema.minItems) schemaItems = Array(schema.maxItems).fill(irItemsSchema);
6927
6954
  else {
6928
6955
  const ofArray = schema.items.allOf || schema.items.anyOf || schema.items.oneOf;
6929
- if (ofArray && ofArray.length > 1 && !getSchemaTypes({ schema: schema.items }).includes("null")) irSchema = {
6930
- ...irSchema,
6931
- ...irItemsSchema
6932
- };
6956
+ if (ofArray && ofArray.length > 1 && !getSchemaTypes(schema.items).includes("null")) Object.assign(irSchema, irItemsSchema);
6933
6957
  else schemaItems.push(irItemsSchema);
6934
6958
  }
6935
6959
  }
@@ -6953,25 +6977,21 @@ function parseNumber({ irSchema = {}, schema }) {
6953
6977
  }
6954
6978
  function parseObject({ context, irSchema = {}, schema, state }) {
6955
6979
  irSchema.type = "object";
6956
- const schemaProperties = {};
6957
- for (const name in schema.properties) {
6958
- const property = schema.properties[name];
6959
- if (typeof property === "boolean") {} else schemaProperties[name] = schemaToIrSchema({
6960
- context,
6961
- schema: property,
6962
- state
6963
- });
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;
6964
6993
  }
6965
- if (Object.keys(schemaProperties).length) irSchema.properties = schemaProperties;
6966
- if (schema.additionalProperties === void 0) {
6967
- if (!irSchema.properties) irSchema.additionalProperties = { type: "unknown" };
6968
- } else if (typeof schema.additionalProperties === "boolean") {
6969
- 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" };
6970
- } else irSchema.additionalProperties = schemaToIrSchema({
6971
- context,
6972
- schema: schema.additionalProperties,
6973
- state
6974
- });
6994
+ let isPatternPropertiesEmpty = true;
6975
6995
  if (schema.patternProperties) {
6976
6996
  const patternProperties = {};
6977
6997
  for (const pattern in schema.patternProperties) {
@@ -6981,9 +7001,19 @@ function parseObject({ context, irSchema = {}, schema, state }) {
6981
7001
  schema: patternSchema,
6982
7002
  state
6983
7003
  });
7004
+ isPatternPropertiesEmpty = false;
6984
7005
  }
6985
- if (Object.keys(patternProperties).length) irSchema.patternProperties = patternProperties;
7006
+ if (!isPatternPropertiesEmpty) irSchema.patternProperties = patternProperties;
6986
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
+ });
6987
7017
  if (schema.propertyNames) irSchema.propertyNames = schemaToIrSchema({
6988
7018
  context,
6989
7019
  schema: schema.propertyNames,
@@ -7037,7 +7067,7 @@ function parseAllOf({ context, schema, state }) {
7037
7067
  schema
7038
7068
  });
7039
7069
  const schemaItems = [];
7040
- const schemaTypes = getSchemaTypes({ schema });
7070
+ const schemaTypes = getSchemaTypes(schema);
7041
7071
  const compositionSchemas = schema.allOf;
7042
7072
  const discriminatorsToAdd = [];
7043
7073
  for (const compositionSchema of compositionSchemas) {
@@ -7049,8 +7079,7 @@ function parseAllOf({ context, schema, state }) {
7049
7079
  state
7050
7080
  });
7051
7081
  state.inAllOf = originalInAllOf;
7052
- if (state.inAllOf === void 0) delete state.inAllOf;
7053
- if (schema.required) if (irCompositionSchema.required) irCompositionSchema.required = [...irCompositionSchema.required, ...schema.required];
7082
+ if (schema.required) if (irCompositionSchema.required) irCompositionSchema.required.push(...schema.required);
7054
7083
  else irCompositionSchema.required = schema.required;
7055
7084
  schemaItems.push(irCompositionSchema);
7056
7085
  if (compositionSchema.$ref) {
@@ -7125,7 +7154,7 @@ function parseAllOf({ context, schema, state }) {
7125
7154
  inlineSchema.properties[discriminator.propertyName] = discriminatorProperty;
7126
7155
  if (isRequired) {
7127
7156
  if (!inlineSchema.required) inlineSchema.required = [];
7128
- if (!inlineSchema.required.includes(discriminator.propertyName)) inlineSchema.required = [...inlineSchema.required, discriminator.propertyName];
7157
+ if (!inlineSchema.required.includes(discriminator.propertyName)) inlineSchema.required.push(discriminator.propertyName);
7129
7158
  }
7130
7159
  } else {
7131
7160
  const irDiscriminatorSchema = {
@@ -7148,7 +7177,7 @@ function parseAllOf({ context, schema, state }) {
7148
7177
  if (irObjectSchema.properties) {
7149
7178
  for (const requiredProperty of irObjectSchema.required ?? []) if (!irObjectSchema.properties[requiredProperty]) for (const compositionSchema of compositionSchemas) {
7150
7179
  const finalCompositionSchema = compositionSchema.$ref ? context.resolveRef(compositionSchema.$ref) : compositionSchema;
7151
- if (getSchemaTypes({ schema: finalCompositionSchema }).includes("object")) {
7180
+ if (getSchemaTypes(finalCompositionSchema).includes("object")) {
7152
7181
  const irCompositionSchema = parseOneType({
7153
7182
  context,
7154
7183
  schema: {
@@ -7189,7 +7218,7 @@ function parseAnyOf({ context, schema, state }) {
7189
7218
  schema
7190
7219
  });
7191
7220
  const schemaItems = [];
7192
- const schemaTypes = getSchemaTypes({ schema });
7221
+ const schemaTypes = getSchemaTypes(schema);
7193
7222
  const compositionSchemas = schema.anyOf;
7194
7223
  const discriminatorPropertyType = schema.discriminator ? findDiscriminatorPropertyType({
7195
7224
  context,
@@ -7248,8 +7277,12 @@ function parseEnum({ context, schema, state }) {
7248
7277
  });
7249
7278
  irSchema.type = "enum";
7250
7279
  const schemaItems = [];
7251
- const schemaTypes = getSchemaTypes({ schema });
7252
- for (const [index, enumValue] of schema.enum.entries()) {
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];
7253
7286
  const typeOfEnumValue = typeof enumValue;
7254
7287
  let enumType;
7255
7288
  if (typeOfEnumValue === "string" || typeOfEnumValue === "number" || typeOfEnumValue === "boolean") enumType = typeOfEnumValue;
@@ -7262,8 +7295,8 @@ function parseEnum({ context, schema, state }) {
7262
7295
  context,
7263
7296
  schema: {
7264
7297
  const: enumValue,
7265
- description: schema["x-enum-descriptions"]?.[index],
7266
- title: schema["x-enum-varnames"]?.[index] ?? schema["x-enumNames"]?.[index],
7298
+ description: xEnumDescriptions?.[index],
7299
+ title: xEnumVarnames?.[index] ?? xEnumNames?.[index],
7267
7300
  type: enumType
7268
7301
  },
7269
7302
  state
@@ -7283,7 +7316,7 @@ function parseOneOf({ context, schema, state }) {
7283
7316
  schema
7284
7317
  });
7285
7318
  let schemaItems = [];
7286
- const schemaTypes = getSchemaTypes({ schema });
7319
+ const schemaTypes = getSchemaTypes(schema);
7287
7320
  const compositionSchemas = schema.oneOf;
7288
7321
  const discriminatorPropertyType = schema.discriminator ? findDiscriminatorPropertyType({
7289
7322
  context,
@@ -7464,7 +7497,7 @@ function parseType({ context, schema, state }) {
7464
7497
  irSchema,
7465
7498
  schema
7466
7499
  });
7467
- const schemaTypes = getSchemaTypes({ schema });
7500
+ const schemaTypes = getSchemaTypes(schema);
7468
7501
  if (schemaTypes.length === 1) return parseOneType({
7469
7502
  context,
7470
7503
  irSchema,
@@ -7582,11 +7615,11 @@ const paginationField = ({ context, name, schema }) => {
7582
7615
  for (const name in schema.properties) if (getPaginationKeywordsRegExp(context.config.parser.pagination).test(name)) {
7583
7616
  const property = schema.properties[name];
7584
7617
  if (typeof property !== "boolean") {
7585
- const schemaTypes = getSchemaTypes({ schema: property });
7618
+ const schemaTypes = getSchemaTypes(property);
7586
7619
  if (!schemaTypes.length) {
7587
7620
  const nonNullCompositionSchemas = (property.anyOf ?? property.oneOf ?? []).filter((schema) => schema.type !== "null");
7588
7621
  if (nonNullCompositionSchemas.length === 1) {
7589
- if (isPaginationType(getSchemaTypes({ schema: nonNullCompositionSchemas[0] }))) return name;
7622
+ if (isPaginationType(getSchemaTypes(nonNullCompositionSchemas[0]))) return name;
7590
7623
  }
7591
7624
  }
7592
7625
  if (isPaginationType(schemaTypes)) return name;
@@ -8128,7 +8161,11 @@ const parseV3_1_X = (context) => {
8128
8161
  securitySchemesMap.set(name, securitySchemeObject);
8129
8162
  }
8130
8163
  for (const name in context.spec.components.parameters) {
8131
- const $ref = `#/components/parameters/${name}`;
8164
+ const $ref = pathToJsonPointer([
8165
+ "components",
8166
+ "parameters",
8167
+ name
8168
+ ]);
8132
8169
  const parameterOrReference = context.spec.components.parameters[name];
8133
8170
  parseParameter({
8134
8171
  $ref,
@@ -8137,7 +8174,11 @@ const parseV3_1_X = (context) => {
8137
8174
  });
8138
8175
  }
8139
8176
  for (const name in context.spec.components.requestBodies) {
8140
- const $ref = `#/components/requestBodies/${name}`;
8177
+ const $ref = pathToJsonPointer([
8178
+ "components",
8179
+ "requestBodies",
8180
+ name
8181
+ ]);
8141
8182
  const requestBodyOrReference = context.spec.components.requestBodies[name];
8142
8183
  parseRequestBody({
8143
8184
  $ref,
@@ -8146,7 +8187,11 @@ const parseV3_1_X = (context) => {
8146
8187
  });
8147
8188
  }
8148
8189
  for (const name in context.spec.components.schemas) {
8149
- const $ref = `#/components/schemas/${name}`;
8190
+ const $ref = pathToJsonPointer([
8191
+ "components",
8192
+ "schemas",
8193
+ name
8194
+ ]);
8150
8195
  const schema = context.spec.components.schemas[name];
8151
8196
  parseSchema({
8152
8197
  $ref,
@@ -8526,8 +8571,18 @@ const definePluginConfig = (defaultConfig) => (userConfig) => ({
8526
8571
  */
8527
8572
  const mappers = {
8528
8573
  boolean: (enabled) => ({ enabled }),
8529
- function: (name) => ({ name }),
8530
- string: (name) => ({ name })
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
+ })
8531
8586
  };
8532
8587
  //#endregion
8533
8588
  //#region src/plugins/symbol.ts
@@ -8535,9 +8590,8 @@ const mappers = {
8535
8590
  * Helper function to build the input for symbol registration, applying naming hooks if provided.
8536
8591
  */
8537
8592
  function buildSymbolIn({ plugin, ...ctx }) {
8538
- const hooks = [plugin.config["~hooks"]?.symbols?.getName, plugin.context.config.parser.hooks.symbols?.getName];
8593
+ const hooks = plugin.getHooks((hooks) => hooks.symbols?.getName);
8539
8594
  for (const hook of hooks) {
8540
- if (!hook) continue;
8541
8595
  const result = hook(ctx);
8542
8596
  if (typeof result === "function") {
8543
8597
  const name = result(ctx);