oas 32.1.9 → 32.1.10

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.
@@ -1,12 +1,12 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkQ6ABRA4Ucjs = require('../chunk-Q6ABRA4U.cjs');
4
- require('../chunk-NG4A45EE.cjs');
3
+ var _chunkDKPOVGFIcjs = require('../chunk-DKPOVGFI.cjs');
4
+ require('../chunk-EYI3QYOG.cjs');
5
5
 
6
6
 
7
7
 
8
8
  var _chunkW6GBV2JTcjs = require('../chunk-W6GBV2JT.cjs');
9
- require('../chunk-KZCEPS4J.cjs');
9
+ require('../chunk-HTEFBV7K.cjs');
10
10
  require('../chunk-AYA3UT4L.cjs');
11
11
  require('../chunk-YPR7YTHM.cjs');
12
12
 
@@ -20,7 +20,7 @@ function callbacks(definition) {
20
20
  );
21
21
  }
22
22
  async function circularRefs(definition) {
23
- const oas = new (0, _chunkQ6ABRA4Ucjs.Oas)(structuredClone(definition));
23
+ const oas = new (0, _chunkDKPOVGFIcjs.Oas)(structuredClone(definition));
24
24
  await oas.dereference();
25
25
  const results = oas.getCircularReferences();
26
26
  results.sort();
@@ -33,7 +33,7 @@ function discriminators(definition) {
33
33
  return _chunkW6GBV2JTcjs.query.call(void 0, ["$..discriminator"], definition).map((res) => _chunkW6GBV2JTcjs.refizePointer.call(void 0, res.pointer));
34
34
  }
35
35
  async function fileSize(definition) {
36
- const oas = new (0, _chunkQ6ABRA4Ucjs.Oas)(structuredClone(definition));
36
+ const oas = new (0, _chunkDKPOVGFIcjs.Oas)(structuredClone(definition));
37
37
  const originalSizeInBytes = Buffer.from(JSON.stringify(oas.api)).length;
38
38
  const raw = Number((originalSizeInBytes / (1024 * 1024)).toFixed(2));
39
39
  await oas.dereference();
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  Oas
3
- } from "../chunk-WRZUJO3I.js";
4
- import "../chunk-55H65L6J.js";
3
+ } from "../chunk-WXXVCSCN.js";
4
+ import "../chunk-2TQO63CW.js";
5
5
  import {
6
6
  query,
7
7
  refizePointer
8
8
  } from "../chunk-CKC36IL7.js";
9
- import "../chunk-7BR3G6FM.js";
9
+ import "../chunk-7BC6KXMO.js";
10
10
  import "../chunk-S27IGTVG.js";
11
11
  import "../chunk-MNOEMVCF.js";
12
12
 
@@ -13,7 +13,7 @@ import {
13
13
  mergeReferencedSchemasIntoRoot,
14
14
  supportedMethods,
15
15
  toJSONSchema
16
- } from "./chunk-7BR3G6FM.js";
16
+ } from "./chunk-7BC6KXMO.js";
17
17
  import {
18
18
  getExtension
19
19
  } from "./chunk-S27IGTVG.js";
@@ -1869,4 +1869,4 @@ export {
1869
1869
  * @license Apache-2.0
1870
1870
  * @see {@link https://github.com/swagger-api/swagger-ui/blob/master/src/core/plugins/samples/fn.js}
1871
1871
  */
1872
- //# sourceMappingURL=chunk-55H65L6J.js.map
1872
+ //# sourceMappingURL=chunk-2TQO63CW.js.map
@@ -209,6 +209,15 @@ function getRefPathSegments(ref) {
209
209
  }
210
210
  return path;
211
211
  }
212
+ function isArrayIndexSegment(seg) {
213
+ return /^\d+$/.test(seg);
214
+ }
215
+ function childShouldBeSchemaArray(parentKey, childSeg) {
216
+ if (!childSeg || !isArrayIndexSegment(childSeg)) {
217
+ return false;
218
+ }
219
+ return parentKey === "allOf" || parentKey === "anyOf" || parentKey === "oneOf";
220
+ }
212
221
  function mergeReferencedSchemasIntoRoot(root, refToSchema) {
213
222
  for (const [ref, schema] of refToSchema) {
214
223
  const segments = getRefPathSegments(ref);
@@ -216,16 +225,57 @@ function mergeReferencedSchemasIntoRoot(root, refToSchema) {
216
225
  continue;
217
226
  }
218
227
  let current = root;
228
+ let pathInvalid = false;
219
229
  for (let i = 0; i < segments.length - 1; i++) {
220
230
  const seg = segments[i];
221
- let next = current[seg];
222
- if (!next || typeof next !== "object" || Array.isArray(next)) {
231
+ const nextSeg = segments[i + 1];
232
+ if (Array.isArray(current)) {
233
+ const idx = Number(seg);
234
+ if (!Number.isInteger(idx) || idx < 0) {
235
+ pathInvalid = true;
236
+ break;
237
+ }
238
+ const slot = current[idx];
239
+ if (slot === void 0 || slot === null || typeof slot !== "object" || Array.isArray(slot)) {
240
+ const nextObj = {};
241
+ current[idx] = nextObj;
242
+ current = nextObj;
243
+ } else {
244
+ current = slot;
245
+ }
246
+ continue;
247
+ }
248
+ const cur = current;
249
+ const existing = cur[seg];
250
+ if (childShouldBeSchemaArray(seg, nextSeg)) {
251
+ if (!Array.isArray(existing)) {
252
+ cur[seg] = [];
253
+ }
254
+ current = cur[seg];
255
+ continue;
256
+ }
257
+ let next;
258
+ if (existing !== void 0 && existing !== null && typeof existing === "object" && !Array.isArray(existing)) {
259
+ next = existing;
260
+ } else {
223
261
  next = {};
224
- current[seg] = next;
262
+ cur[seg] = next;
225
263
  }
226
264
  current = next;
227
265
  }
228
- current[segments[segments.length - 1]] = schema;
266
+ if (pathInvalid) {
267
+ continue;
268
+ }
269
+ const lastSeg = segments[segments.length - 1];
270
+ if (Array.isArray(current)) {
271
+ const idx = Number(lastSeg);
272
+ if (!Number.isInteger(idx) || idx < 0) {
273
+ continue;
274
+ }
275
+ current[idx] = schema;
276
+ } else {
277
+ current[lastSeg] = schema;
278
+ }
229
279
  }
230
280
  }
231
281
 
@@ -590,7 +640,7 @@ function toJSONSchema(data, opts) {
590
640
  returnMode: "ref",
591
641
  refLogger
592
642
  });
593
- const { $ref: _$ref, ...siblings } = schema;
643
+ const { $ref: _$ref, properties: _propertiesWithRef, ...siblings } = schema;
594
644
  if (Object.keys(siblings).length > 0) {
595
645
  return { ...resolved, ...siblings };
596
646
  }
@@ -1282,4 +1332,4 @@ export {
1282
1332
  supportedMethods,
1283
1333
  SERVER_VARIABLE_REGEX
1284
1334
  };
1285
- //# sourceMappingURL=chunk-7BR3G6FM.js.map
1335
+ //# sourceMappingURL=chunk-7BC6KXMO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/matches-mimetype.ts","../src/lib/get-parameter-content-type.ts","../src/lib/refs.ts","../src/lib/helpers.ts","../src/lib/clone-object.ts","../src/lib/build-discriminator-one-of.ts","../src/lib/openapi-to-json-schema.ts","../src/operation/transformers/get-parameters-as-json-schema.ts","../src/utils.ts"],"sourcesContent":["function matchesMediaType(types: string[], mediaType: string): boolean {\n return types.some(type => {\n return mediaType.indexOf(type) > -1;\n });\n}\n\n// biome-ignore lint/style/noDefaultExport: This file has no other exports so this is fine.\nexport default {\n formUrlEncoded: (mimeType: string): boolean => {\n return matchesMediaType(['application/x-www-form-urlencoded'], mimeType);\n },\n\n json: (contentType: string): boolean => {\n return matchesMediaType(\n ['application/json', 'application/x-json', 'text/json', 'text/x-json', '+json'],\n contentType,\n );\n },\n\n multipart: (contentType: string): boolean => {\n return matchesMediaType(\n ['multipart/mixed', 'multipart/related', 'multipart/form-data', 'multipart/alternative'],\n contentType,\n );\n },\n\n wildcard: (contentType: string): boolean => {\n return contentType === '*/*';\n },\n\n xml: (contentType: string): boolean => {\n return matchesMediaType(\n [\n 'application/xml',\n 'application/xml-external-parsed-entity',\n 'application/xml-dtd',\n 'text/xml',\n 'text/xml-external-parsed-entity',\n '+xml',\n ],\n contentType,\n );\n },\n};\n","import matchesMimetype from './matches-mimetype.js';\n\n/**\n * Selects a content type from an array of content type keys, prioritizing `application/json`\n * and other JSON-like content types over other content types.\n *\n * When multiple content types are present:\n * - If there's exactly one content type, it's returned\n * - If there are multiple content types, JSON-like content types (e.g., `application/json`,\n * `application/vnd.api+json`) are prioritized\n * - If no JSON-like content types are present, the first content type is returned\n *\n * @param contentKeys - Array of content type keys (e.g., ['application/json', 'application/xml'])\n * @returns The selected content type, or undefined if the array is empty\n */\nexport function getParameterContentType(contentKeys: string[]): string | undefined {\n if (contentKeys.length === 0) {\n return undefined;\n }\n\n if (contentKeys.length === 1) {\n return contentKeys[0];\n }\n\n // We should always try to prioritize `application/json` over any other possible\n // content that might be present on this schema.\n const jsonLikeContentTypes = contentKeys.filter(k => matchesMimetype.json(k));\n if (jsonLikeContentTypes.length) {\n return jsonLikeContentTypes[0];\n }\n\n return contentKeys[0];\n}\n","import type { ParserOptions } from '@readme/openapi-parser';\nimport type { OASDocument, SchemaObject } from '../types.js';\n\nimport jsonpointer from 'jsonpointer';\n\nimport { isRef } from '../types.js';\nimport { isPrimitive } from './helpers.js';\n\n/**\n * Decorate component schemas within the API definition with a `x-readme-ref-name` property so we\n * can retin their original schema names during dereferencing or `$ref` resolution operations.\n *\n */\nexport function decorateComponentSchemasWithRefName(api: OASDocument): void {\n if (!api?.components?.schemas || typeof api.components.schemas !== 'object') {\n return;\n }\n\n Object.keys(api.components.schemas).forEach(schemaName => {\n // As of OpenAPI 3.1 component schemas can be primitives or arrays. If this happens then we\n // shouldn't try to add `x-readme-ref-name` properties because we can't. We'll have some data\n // loss on these schemas but as they aren't objects they likely won't be used in ways that\n // would require needing a `title` or `x-readme-ref-name` anyways.\n if (\n isPrimitive(api.components?.schemas?.[schemaName]) ||\n Array.isArray(api.components?.schemas?.[schemaName]) ||\n api.components?.schemas?.[schemaName] === null\n ) {\n return;\n }\n\n (api.components?.schemas?.[schemaName] as SchemaObject)['x-readme-ref-name'] = schemaName;\n });\n}\n\n/**\n * Encode a string to be used as a JSON pointer.\n *\n * @see {@link https://tools.ietf.org/html/rfc6901}\n * @param str String to encode into string that can be used as a JSON pointer.\n */\nexport function encodePointer(str: string): string {\n return str.replaceAll('~', '~0').replaceAll('/', '~1');\n}\n\n/**\n * Decode a JSON pointer string.\n *\n * Per RFC 6901, `~0` is unescaped to `~` and `~1` to `/`. A single-pass replacement is required:\n * the sequence `~01` must decode to `~1` (tilde then one), not `~/`. Replacing `~1` before `~0`\n * would incorrectly turn `~01` into `~/`.\n *\n * @see {@link https://tools.ietf.org/html/rfc6901}\n * @param str String to decode a JSON pointer from\n */\nexport function decodePointer(str: string): string {\n return str.replace(/~([01])/g, (_, digit) => (digit === '0' ? '~' : '/'));\n}\n\n/**\n * Lookup a reference pointer within an a JSON object and return the schema that it resolves to.\n *\n * @param $ref Reference to look up a schema for.\n * @param definition OpenAPI definition to look for the `$ref` pointer in.\n */\nfunction findRef($ref: string, definition: OASDocument | SchemaObject): any {\n let currRef = $ref.trim();\n if (currRef === '') {\n // If this ref is empty, don't bother trying to look for it.\n return false;\n }\n\n if (currRef.startsWith('#')) {\n // Decode URI fragment representation.\n currRef = decodeURIComponent(currRef.substring(1));\n } else {\n throw new Error(`Could not find a definition for ${$ref}.`);\n }\n\n const current = jsonpointer.get(definition, currRef);\n if (current === undefined) {\n throw new Error(`Could not find a definition for ${$ref}.`);\n }\n\n return current;\n}\n\n/**\n * Dereference a `$ref` pointer if present, otherwise return the value as-is.\n *\n * This function handles `$ref` pointers on-the-fly without requiring full dereferencing and\n * prevents infinite loops by tracking seen `$ref` pointers and not re-processing circular\n * references.\n *\n * @param value The value that may contain a `$ref` pointer.\n * @param definition OpenAPI definition to look for the `$ref` pointer in.\n * @param seenRefs Optional Set to track `$ref` pointers that have already been processed to prevent circular references.\n * @returns The dereferenced value if it was a `$ref`, otherwise the original value. Returns the original `$ref` if it's circular.\n */\nexport function dereferenceRef<T>(\n value: T,\n definition?: OASDocument | SchemaObject,\n seenRefs: Set<string> = new Set<string>(),\n): T {\n if (value === undefined) {\n return undefined as T;\n }\n\n if (isRef(value)) {\n if (!definition) {\n return value as T;\n }\n\n const ref = value.$ref;\n\n // If we've seen this `$ref` before then it's circular and we should return the original `$ref`\n // to prevent infinite loops\n if (seenRefs.has(ref)) {\n return value as T;\n }\n\n // Track this `$ref` as having been seen so we can avoid infinitely processing circular\n // references.\n seenRefs.add(ref);\n\n try {\n const dereferenced = findRef(ref, definition);\n\n // If the dereferenced value is itself a `$ref` then recursively dereference it (but with\n // `seenRefs` tracking).\n if (isRef(dereferenced)) {\n return dereferenceRef(dereferenced, definition, seenRefs) as T;\n }\n\n return {\n ...dereferenced,\n } as T;\n } catch {\n // If dereferencing fails return the original `$ref`.\n return value as T;\n }\n }\n\n return value;\n}\n\n/**\n * Retrive our dereferencing configuration for `@readme/openapi-parser`.\n *\n */\nexport function getDereferencingOptions(circularRefs: Set<string>): Pick<ParserOptions, 'resolve' | 'dereference'> {\n return {\n resolve: {\n // We shouldn't be resolving external pointers at this point so just ignore them.\n external: false,\n },\n dereference: {\n // If circular `$refs` are ignored they'll remain in the schema as `$ref: String`, otherwise\n // `$ref` just won't exist. This, in tandem with `onCircular`, allows us to do easy and\n // accumulate a list of circular references.\n circular: 'ignore',\n\n onCircular: (path: string) => {\n // The circular references that are coming out of `json-schema-ref-parser` are prefixed\n // with the schema path (file path, URL, whatever) that the schema exists in. Because we\n // don't care about this information for this reporting mechanism, and only the `$ref`\n // pointer, we're removing it.\n circularRefs.add(`#${path.split('#')[1]}`);\n },\n },\n };\n}\n\n/**\n * Recursively collect all `$ref` pointers in a schema.\n *\n */\nexport function collectRefsInSchema(schema: unknown): Set<string> {\n const refs = new Set<string>();\n if (!schema || typeof schema !== 'object') return refs;\n const obj = schema as Record<string, unknown>;\n if (isRef(obj)) {\n refs.add(obj.$ref);\n }\n\n for (const value of Object.values(obj)) {\n if (Array.isArray(value)) {\n for (const item of value) {\n for (const r of collectRefsInSchema(item)) refs.add(r);\n }\n } else if (value && typeof value === 'object') {\n for (const r of collectRefsInSchema(value)) refs.add(r);\n }\n }\n\n return refs;\n}\n\n/**\n * Given a set of `$ref` pointers and a full set of schema objects, mapped to their reference\n * locations, return only the schemas that are transitively referenced from those schemas.\n *\n */\nexport function filterRequiredRefsToReferenced(\n requiredRefs: Set<string>,\n usedSchemas: Map<string, SchemaObject>,\n): Map<string, SchemaObject> {\n const referenced = new Set(requiredRefs);\n\n let prevSize = 0;\n while (referenced.size > prevSize) {\n prevSize = referenced.size;\n for (const ref of referenced) {\n const schema = usedSchemas.get(ref);\n if (schema) {\n for (const r of collectRefsInSchema(schema)) {\n referenced.add(r);\n }\n }\n }\n }\n\n const filtered = new Map<string, SchemaObject>();\n for (const ref of referenced) {\n const s = usedSchemas.get(ref);\n if (s !== undefined) {\n filtered.set(ref, s);\n }\n }\n\n return filtered;\n}\n\n/**\n * Parse a `$ref` pointers (e.g. `#/x-definitions/MySchema` or `#/components/schemas/Foo`) into\n * path segments. Returns `null` if the first segment is reserved (we should not embed at root\n * under that key).\n *\n */\nfunction getRefPathSegments(ref: string): string[] | null {\n if (!ref.startsWith('#/')) return null;\n const path = ref\n .slice(2)\n .split('/')\n .map(seg => {\n // We need to decode these segments twice because the first decode is to decode encoded JSON\n // pointer segments, and the second is to decode any URI-encoded segments.\n return decodeURIComponent(decodePointer(seg));\n });\n\n if (path.length < 2) {\n // We need at least two pieces of a `$ref` for it to be valid. e.g. `#/x-definitions/MySchema`\n // or `#/components/schemas/Foo`.\n return null;\n }\n\n return path;\n}\n\nfunction isArrayIndexSegment(seg: string): boolean {\n return /^\\d+$/.test(seg);\n}\n\nfunction childShouldBeSchemaArray(parentKey: string, childSeg: string | undefined): boolean {\n if (!childSeg || !isArrayIndexSegment(childSeg)) {\n return false;\n }\n\n return parentKey === 'allOf' || parentKey === 'anyOf' || parentKey === 'oneOf';\n}\n\n/**\n * Merge referenced schemas into the root schema at the paths defined by their reference location.\n *\n * @example `#/components/schemas/MySchema` -> `root.components.schemas.MySchema`\n */\nexport function mergeReferencedSchemasIntoRoot(root: SchemaObject, refToSchema: Map<string, unknown>): void {\n for (const [ref, schema] of refToSchema) {\n const segments = getRefPathSegments(ref);\n if (!segments || segments.length === 0) {\n continue;\n }\n\n let current: SchemaObject = root;\n let pathInvalid = false;\n\n for (let i = 0; i < segments.length - 1; i++) {\n const seg = segments[i] as keyof SchemaObject;\n const nextSeg = segments[i + 1];\n\n if (Array.isArray(current)) {\n const idx = Number(seg);\n if (!Number.isInteger(idx) || idx < 0) {\n pathInvalid = true;\n break;\n }\n\n const slot: SchemaObject = current[idx];\n if (slot === undefined || slot === null || typeof slot !== 'object' || Array.isArray(slot)) {\n const nextObj: SchemaObject = {};\n current[idx] = nextObj;\n current = nextObj;\n } else {\n current = slot;\n }\n\n continue;\n }\n\n const cur = current;\n const existing = cur[seg] as SchemaObject;\n\n if (childShouldBeSchemaArray(seg, nextSeg)) {\n if (!Array.isArray(existing)) {\n cur[seg] = [];\n }\n\n current = cur[seg] as unknown[];\n continue;\n }\n\n let next: Record<string, unknown>;\n if (existing !== undefined && existing !== null && typeof existing === 'object' && !Array.isArray(existing)) {\n next = existing as Record<string, unknown>;\n } else {\n next = {};\n cur[seg] = next;\n }\n\n current = next;\n }\n\n if (pathInvalid) {\n continue;\n }\n\n const lastSeg = segments[segments.length - 1] as keyof SchemaObject;\n if (Array.isArray(current)) {\n const idx = Number(lastSeg);\n if (!Number.isInteger(idx) || idx < 0) {\n continue;\n }\n\n current[idx] = schema;\n } else {\n current[lastSeg] = schema;\n }\n }\n}\n","import type { SchemaObject } from '../types.js';\n\nexport function hasSchemaType(schema: SchemaObject, discriminator: 'array' | 'object'): boolean {\n if (Array.isArray(schema.type)) {\n return schema.type.includes(discriminator);\n }\n\n return schema.type === discriminator;\n}\n\nexport function isObject(val: unknown): val is Record<string, unknown> {\n return typeof val === 'object' && val !== null && !Array.isArray(val);\n}\n\nexport function isPrimitive(val: unknown): val is boolean | number | string {\n return typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean';\n}\n","/**\n * @deprecated Use `structuredClone` instead\n */\nexport function cloneObject<T>(obj: T): T {\n if (typeof obj === 'undefined') {\n return undefined as T;\n }\n\n return JSON.parse(JSON.stringify(obj));\n}\n","import type { DiscriminatorChildrenMap, DiscriminatorObject, OASDocument, SchemaObject } from '../types.js';\n\nimport { isRef } from '../types.js';\nimport { cloneObject } from './clone-object.js';\n\n/**\n * Determines if a schema has a discriminator but is missing oneOf/anyOf polymorphism.\n *\n * @param schema Schema to check.\n * @returns If the schema has a discriminator but no oneOf/anyOf.\n */\nfunction hasDiscriminatorWithoutPolymorphism(schema: SchemaObject): boolean {\n if (!schema || typeof schema !== 'object') return false;\n if (!('discriminator' in schema)) return false;\n if ('oneOf' in schema || 'anyOf' in schema) return false;\n return true;\n}\n\n/**\n * Checks if a schema's allOf contains a $ref to a specific schema name.\n *\n * @param schema Schema to check.\n * @param targetSchemaName The schema name to look for (e.g., 'Pet').\n * @returns If the schema's allOf contains a $ref to the target schema.\n */\nfunction allOfReferencesSchema(schema: SchemaObject, targetSchemaName: string): boolean {\n if (!schema || typeof schema !== 'object') return false;\n if (!('allOf' in schema) || !Array.isArray(schema.allOf)) return false;\n\n return schema.allOf.some(item => {\n if (isRef(item)) {\n // Check if the $ref points to the target schema\n // Format: #/components/schemas/SchemaName\n const refParts = item.$ref.split('/');\n const refSchemaName = refParts[refParts.length - 1];\n return refSchemaName === targetSchemaName;\n }\n\n return false;\n });\n}\n\n/**\n * Phase 1: Before dereferencing, identify discriminator schemas and their children via allOf\n * inheritance. Returns a mapping that can be used after dereferencing.\n *\n * We don't add oneOf here because that would create circular references\n * (Pet → Cat → Pet via allOf) which would break dereferencing.\n *\n * Note: Schemas defined in mapping but NOT declared using anyOf, allOf or oneOf will not be considered\n * a valid child. The discriminator object is legal only when using one of the composite keywords oneOf, anyOf, allOf.\n * @link https://spec.openapis.org/oas/v3.1.0.html#fixed-fields-20\n *\n * @param api The OpenAPI definition to process (before dereferencing).\n * @returns Maps of discriminator schema names to their child schema names and `$ref` pointers.\n */\nexport function findDiscriminatorChildren(definition: Pick<OASDocument, 'components'>): {\n children: DiscriminatorChildrenMap;\n refs: Map<string, string>;\n} {\n const childrenMap: DiscriminatorChildrenMap = new Map();\n const childrenRefMap = new Map<string, string>();\n\n if (!definition?.components?.schemas || typeof definition.components.schemas !== 'object') {\n return { children: childrenMap, refs: childrenRefMap };\n }\n\n const schemas = definition.components.schemas as Record<string, SchemaObject>;\n const schemaNames = Object.keys(schemas);\n\n // Find all schemas with discriminator but no oneOf/anyOf\n const discriminatorSchemas: string[] = schemaNames.filter(name => {\n return hasDiscriminatorWithoutPolymorphism(schemas[name]);\n });\n\n // For each discriminator schema, record child schema names\n for (const baseName of discriminatorSchemas) {\n const baseSchema = schemas[baseName] as SchemaObject & { discriminator: DiscriminatorObject };\n const discriminator = baseSchema.discriminator;\n\n let childSchemaNames: string[] = [];\n\n // If there's already a mapping defined, use it but only include schemas that\n // actually inherit from this parent via allOf. A mapping entry for a schema\n // that doesn't use allOf is just a value resolution hint, not a declaration\n // of inheritance.\n if (discriminator.mapping && typeof discriminator.mapping === 'object') {\n const mappingRefs = Object.values(discriminator.mapping);\n if (mappingRefs.length > 0) {\n childSchemaNames = mappingRefs\n .map(ref => ref.split('/').pop())\n .filter((name): name is string => {\n if (!name) return false;\n const childSchema = schemas[name];\n return !!childSchema && allOfReferencesSchema(childSchema, baseName);\n });\n }\n }\n\n // Otherwise, scan for schemas that extend this base via allOf\n if (!childSchemaNames.length) {\n childSchemaNames = schemaNames.filter(name => {\n if (name === baseName) return false;\n return allOfReferencesSchema(schemas[name], baseName);\n });\n }\n\n // Store child schema names in the map\n if (childSchemaNames.length) {\n for (const childName of childSchemaNames) {\n childrenRefMap.set(childName, `#/components/schemas/${childName}`);\n }\n\n childrenMap.set(baseName, childSchemaNames);\n childrenRefMap.set(baseName, `#/components/schemas/${baseName}`);\n }\n }\n\n return { children: childrenMap, refs: childrenRefMap };\n}\n\n/**\n * Apply discriminator oneOf to a map of used schemas (e.g. from `getParametersAsJSONSchema` and\n * `getResponseAsJSONSchema`). For each discriminator base in `usedSchemas`, it ensures children\n * are in the map via `getOrAddSchema`, then sets `oneOf` on the base.\n *\n * Optionally this also strips `oneOf` from the base when it appears inside a child's `allOf`\n * schema.\n *\n * @param api The OpenAPI definition (for findDiscriminatorChildren).\n * @param usedSchemas Map of schema name -> JSON Schema to update.\n * @param getOrAddSchema Callback that resolves, converts, and adds a schema by name; returns the converted schema or undefined.\n */\nexport function applyDiscriminatorOneOfToUsedSchemas(\n definition: Pick<OASDocument, 'components'>,\n usedSchemas: Map<string, SchemaObject>,\n getOrAddSchema: (ref: string) => SchemaObject | undefined,\n): void {\n const { children: childrenMap, refs: childrenRefMap } = findDiscriminatorChildren(definition);\n if (!childrenMap.size) return;\n\n // Build oneOf for each discriminator schema\n for (const [baseName, childNames] of childrenMap) {\n const baseRef = childrenRefMap.get(baseName);\n if (!baseRef) continue;\n\n const baseSchema = usedSchemas.get(baseRef);\n if (!baseSchema || typeof baseSchema !== 'object') continue;\n\n // Build `oneOf` from raw child schema `$ref` pointers.\n const oneOf: SchemaObject[] = [];\n for (const childName of childNames) {\n const childRef = childrenRefMap.get(childName);\n if (!childRef) continue;\n\n const childSchema = getOrAddSchema(childRef);\n if (childSchema) {\n oneOf.push({\n $ref: childRef,\n });\n }\n }\n\n if (oneOf.length > 0) {\n (baseSchema as Record<string, unknown>).oneOf = oneOf;\n }\n }\n\n // Strip `oneOf` from discriminator schemas embedded in child `allOf` structures.\n //\n // When `Cat` extends `Pet` via an `allOf` and `Pet` has a `discriminator` with a `oneOf` the\n // embedded `Pet` inside `Cat`'s `allOf` should NOT have `oneOf` because this would create a\n // circular `Cat.allOf[0].oneOf[0] = Cat` reference.\n //\n // We only strip from `allOf` entries to preserve `oneOf` in direct references.\n for (const [parentSchemaName, childNames] of childrenMap) {\n for (const childName of childNames) {\n const childRef = childrenRefMap.get(childName);\n if (!childRef) continue;\n\n const childSchema = usedSchemas.get(childRef);\n if (!childSchema || !('allOf' in childSchema) || !Array.isArray(childSchema.allOf)) {\n continue;\n }\n\n for (let i = 0; i < childSchema.allOf.length; i++) {\n const item = childSchema.allOf[i];\n if (\n item &&\n typeof item === 'object' &&\n 'x-readme-ref-name' in item &&\n item['x-readme-ref-name'] === parentSchemaName &&\n 'oneOf' in item\n ) {\n // Clone the allOf entry and strip oneOf from the clone to avoid mutating the shared reference.\n // This ensures Pet in components.schemas keeps its oneOf while embedded Pet in Cat's allOf doesn't.\n const clonedItem = cloneObject(item);\n delete clonedItem.oneOf;\n childSchema.allOf[i] = clonedItem;\n }\n }\n }\n }\n}\n","import type { JSONSchema7TypeName } from 'json-schema';\nimport type {\n ExampleObject,\n JSONSchema,\n OASDocument,\n ReferenceObject,\n RequestBodyObject,\n SchemaObject,\n} from '../types.js';\n\nimport mergeJSONSchemaAllOf from 'json-schema-merge-allof';\nimport jsonpointer from 'jsonpointer';\nimport removeUndefinedObjects from 'remove-undefined-objects';\n\nimport { isOpenAPI30, isRef, isSchema } from '../types.js';\nimport { hasSchemaType, isObject, isPrimitive } from './helpers.js';\nimport { collectRefsInSchema, dereferenceRef, encodePointer } from './refs.js';\n\n/**\n * This list has been pulled from `openapi-schema-to-json-schema` but been slightly modified to fit\n * within the constraints in which ReadMe uses the output from this library in schema form\n * rendering as while properties like `readOnly` aren't represented within JSON Schema, we support\n * it within that library's handling of OpenAPI-friendly JSON Schema.\n *\n * @see {@link https://github.com/openapi-contrib/openapi-schema-to-json-schema/blob/main/src/consts.ts}\n */\nconst UNSUPPORTED_SCHEMA_PROPS = [\n 'example', // OpenAPI supports `example` but we're mapping it to `examples` in this library.\n 'externalDocs',\n 'xml',\n] as const;\n\nexport interface toJSONSchemaOptions {\n /**\n * Whether or not to extend descriptions with a list of any present enums.\n */\n addEnumsToDescriptions?: boolean;\n\n /**\n * Current location within the schema -- this is a JSON pointer.\n */\n currentLocation?: string;\n\n /**\n * An OpenAPI definition to use for schema `$ref` pointer resolutions.\n */\n definition?: OASDocument;\n\n /**\n * Object containing a global set of defaults that we should apply to schemas that match it.\n */\n globalDefaults?: Record<string, unknown>;\n\n /**\n * If you wish to hide properties that are marked as being `readOnly`.\n */\n hideReadOnlyProperties?: boolean;\n\n /**\n * If you wish to hide properties that are marked as being `writeOnly`.\n */\n hideWriteOnlyProperties?: boolean;\n\n /**\n * Is this schema the child of a polymorphic `allOf` schema?\n */\n isPolymorphicAllOfChild?: boolean;\n\n /**\n * Array of parent `default` schemas to utilize when attempting to path together schema defaults.\n */\n prevDefaultSchemas?: SchemaObject[];\n\n /**\n * Array of parent `example` schemas to utilize when attempting to path together schema examples.\n */\n prevExampleSchemas?: SchemaObject[];\n\n /**\n * A function that's called anytime a (circular) `$ref` is found.\n */\n refLogger?: (ref: string, type: 'discriminator' | 'ref') => void;\n\n /**\n * A set of `$ref` pointers that have been seen during JSON Schema generation.\n */\n seenRefs?: Set<string>;\n\n /**\n * A dictionary of referenced schema names to their compiled JSON Schema objects.\n */\n usedSchemas?: Map<string, SchemaObject>;\n\n /**\n * Tracks component `$ref` pointers that were already emitted as bare `{ $ref }` stubs in this\n * conversion. Used so a later duplicate bare `$ref` to the same component keeps the stub,\n * while a bare `$ref` that follows an `allOf` merge of the same ref still inlines the expanded\n * schema.\n */\n refsEmittedAsStub?: Set<string>;\n}\n\n/**\n * Placeholder value in `usedSchemas` while a schema is being converted (used for circular\n * references).\n */\nconst PENDING_SCHEMA = { __pending: true } as unknown as SchemaObject;\n\nfunction isPendingSchema(s: SchemaObject): boolean {\n return isObject(s) && '__pending' in s && (s as Record<string, unknown>).__pending === true;\n}\n\nexport function getSchemaVersionString(schema: SchemaObject, api: OASDocument): string {\n // If we're not on OpenAPI 3.1+ then we should fall back to the default schema version.\n if (isOpenAPI30(api)) {\n // This should remain as an HTTP url, not HTTPS.\n return 'http://json-schema.org/draft-04/schema#';\n }\n\n // If the schema indicates the version, prefer that.\n if (schema.$schema) {\n return schema.$schema;\n }\n\n // If the user defined a global schema version on their OAS document, prefer that.\n if (api.jsonSchemaDialect) {\n return api.jsonSchemaDialect;\n }\n\n return 'https://json-schema.org/draft/2020-12/schema#';\n}\n\nfunction isPolymorphicSchema(schema: SchemaObject): boolean {\n return 'allOf' in schema || 'anyOf' in schema || 'oneOf' in schema;\n}\n\n/**\n * Determine if a polymorphic schema is comprised of empty schemas.\n *\n */\nfunction isEmptyPolymorphicSchema(list: unknown): boolean {\n if (!Array.isArray(list)) return false;\n if (!list.length) return true;\n\n return list.every(branch => {\n if (branch === null || branch === undefined) return true;\n if (typeof branch !== 'object' || Array.isArray(branch)) return false;\n return Array.isArray(branch) ? !branch.length : !Object.keys(branch as object).length;\n });\n}\n\n/**\n * Inline any `$ref` pointer into an objects schema so that `json-schema-merge-allof` can merge\n * them together. We need to do this because `json-schema-merge-allof` does not support `$ref`\n * pointer resolution.\n */\nfunction inlinePropertyRefsForMerge(schema: SchemaObject, usedSchemas: Map<string, SchemaObject>): SchemaObject {\n const out = structuredClone(schema);\n if (!('properties' in out) || typeof out.properties !== 'object' || out.properties === null) {\n return out;\n }\n\n for (const key of Object.keys(out.properties)) {\n const val = out.properties[key];\n if (isRef(val)) {\n const resolved = usedSchemas.get(val.$ref);\n if (resolved !== undefined && !isPendingSchema(resolved)) {\n out.properties[key] = {\n ...structuredClone(resolved),\n };\n }\n }\n }\n\n return out;\n}\n\n/**\n * Resolve and convert a `$ref` schema, caching the converted result in `usedSchemas`.\n *\n * This helper always attempts to dereference and convert the target schema while guarding against\n * circular/invalid refs with `PENDING_SCHEMA`. The `returnMode` controls whether the caller gets\n * back the original `$ref` pointer or the converted JSON Schema representation.\n */\nfunction resolveAndCacheRefSchema({\n schema,\n definition,\n usedSchemas,\n seenRefs,\n conversionOptions,\n returnMode,\n refLogger,\n}: {\n schema: ReferenceObject;\n definition: OASDocument;\n usedSchemas: Map<string, SchemaObject>;\n seenRefs: Set<string>;\n conversionOptions: toJSONSchemaOptions;\n returnMode: 'ref' | 'converted';\n refLogger: NonNullable<toJSONSchemaOptions['refLogger']>;\n}): SchemaObject {\n const ref = schema.$ref;\n const refsEmittedAsStub = conversionOptions.refsEmittedAsStub;\n const existing = usedSchemas.get(ref);\n if (existing !== undefined && !isPendingSchema(existing)) {\n if (returnMode === 'converted') {\n return existing;\n }\n\n // If we have already seen this bare `$ref` pointer before, and emitted it as a stub, then we\n // should do the same again here.\n if (refsEmittedAsStub?.has(ref)) {\n return { $ref: ref };\n }\n\n // If this existing schema isn't a `$ref` pointer then we should return it as-is.\n if (!isRef(existing)) {\n return structuredClone(existing);\n }\n\n return { $ref: ref };\n }\n\n // If our `$ref` was never resolved away from an in-progress schema then it's either invalid\n // or a circular reference and we should return it as-is.\n if (existing !== undefined && isPendingSchema(existing)) {\n refsEmittedAsStub?.add(ref);\n return { $ref: ref };\n }\n\n usedSchemas.set(ref, PENDING_SCHEMA);\n\n if (returnMode === 'ref') {\n // If we want to return the original `$ref` pointer then we should make an attempt to resolve\n // and lazily dereference it into our `usedSchemas` store.\n let resolved: SchemaObject;\n try {\n const dereferenced = dereferenceRef(schema, definition, seenRefs);\n if (isRef(dereferenced)) {\n refLogger(dereferenced.$ref, 'ref');\n\n let converted: SchemaObject;\n try {\n // `jsonpointer` doesn't understand the `#` prefix that `$ref` pointers have so we need\n // to shave it off.\n const pointer = ref.startsWith('#') ? decodeURIComponent(ref.substring(1)) : ref;\n const rawSchema = jsonpointer.get(definition, pointer);\n if (rawSchema && typeof rawSchema === 'object') {\n converted = toJSONSchema(structuredClone(rawSchema), { ...conversionOptions, seenRefs });\n } else {\n converted = { $ref: ref };\n }\n } catch {\n converted = { $ref: ref };\n }\n\n usedSchemas.set(ref, converted);\n refLogger(ref, 'ref');\n refsEmittedAsStub?.add(ref);\n return { $ref: ref };\n }\n\n resolved = dereferenced;\n } catch {\n refLogger(ref, 'ref');\n usedSchemas.set(ref, { $ref: ref });\n refsEmittedAsStub?.add(ref);\n return { $ref: ref };\n }\n\n const converted = toJSONSchema(structuredClone(resolved), { ...conversionOptions, seenRefs });\n usedSchemas.set(ref, converted);\n refLogger(ref, 'ref');\n refsEmittedAsStub?.add(ref);\n return { $ref: ref };\n }\n\n try {\n // If we want to return the generated and converted JSON Schema object then, if we have a `$ref`\n // pointer we should make an attempt to resolve and lazily dereference that into our converted\n // schema. If that fails then we'll return the original schema.\n const dereferenced = dereferenceRef(schema, definition, seenRefs);\n if (isRef(dereferenced)) {\n let converted: SchemaObject;\n try {\n // `jsonpointer` doesn't understand the `#` prefix that `$ref` pointers have so\n // we need to shave it off.\n const pointer = ref.startsWith('#') ? decodeURIComponent(ref.substring(1)) : ref;\n const rawSchema = jsonpointer.get(definition, pointer);\n if (rawSchema && typeof rawSchema === 'object') {\n converted = toJSONSchema(structuredClone(rawSchema), { ...conversionOptions, seenRefs });\n } else {\n converted = { $ref: ref };\n }\n } catch {\n converted = { $ref: ref };\n }\n\n usedSchemas.set(ref, converted);\n return converted;\n }\n\n const converted = toJSONSchema(structuredClone(dereferenced), { ...conversionOptions, seenRefs });\n usedSchemas.set(ref, converted);\n return converted;\n } catch {\n usedSchemas.set(ref, { $ref: ref });\n return { $ref: ref };\n }\n}\n\nfunction isRequestBodySchema(schema: unknown): schema is RequestBodyObject {\n return 'content' in (schema as RequestBodyObject);\n}\n\n/**\n * Given a JSON pointer, a type of property to look for, and an array of schemas do a reverse\n * search through them until we find the JSON pointer, or part of it, within the array.\n *\n * This function will allow you to take a pointer like `/tags/name` and return back `buster` from\n * the following array:\n *\n * ```\n * [\n * {\n * example: {id: 20}\n * },\n * {\n * examples: {\n * distinctName: {\n * tags: {name: 'buster'}\n * }\n * }\n * }\n * ]\n * ```\n *\n * As with most things however, this is not without its quirks! If a deeply nested property shares\n * the same name as an example that's further up the stack (like `tags.id` and an example for `id`),\n * there's a chance that it'll be misidentified as having an example and receive the wrong value.\n *\n * That said, any example is usually better than no example though, so while it's quirky behavior\n * it shouldn't raise immediate cause for alarm.\n *\n * @see {@link https://tools.ietf.org/html/rfc6901}\n * @param property Specific type of schema property to look for a value for.\n * @param pointer JSON pointer to search for an example for.\n * @param schemas Array of previous schemas we've found relating to this pointer.\n */\nfunction searchForValueByPropAndPointer(\n property: 'default' | 'example',\n pointer: string,\n schemas: toJSONSchemaOptions['prevDefaultSchemas'] | toJSONSchemaOptions['prevExampleSchemas'] = [],\n) {\n if (!schemas.length || !pointer.length) {\n return undefined;\n }\n\n const locSplit = pointer.split('/').filter(Boolean).reverse();\n const pointers = [];\n\n let point = '';\n for (let i = 0; i < locSplit.length; i += 1) {\n point = `/${locSplit[i]}${point}`;\n pointers.push(point);\n }\n\n let foundValue: any;\n const rev = [...schemas].reverse();\n\n for (let i = 0; i < pointers.length; i += 1) {\n for (let ii = 0; ii < rev.length; ii += 1) {\n let schema = rev[ii];\n\n if (property === 'example') {\n if ('example' in schema) {\n schema = schema.example;\n } else {\n if (!Array.isArray(schema.examples) || !schema.examples.length) {\n continue;\n }\n\n // Prevent us from crashing if `examples` is a completely empty object.\n schema = [...schema.examples].shift();\n }\n } else {\n schema = schema.default;\n }\n\n try {\n foundValue = jsonpointer.get(schema, pointers[i]);\n } catch {\n // If the schema we're looking at is `{obj: null}` and our pointer is `/obj/propertyName`\n // `jsonpointer` will throw an error. If that happens, we should silently catch and toss it\n // and return no example.\n }\n\n if (foundValue !== undefined) {\n break;\n }\n }\n\n if (foundValue !== undefined) {\n break;\n }\n }\n\n return foundValue;\n}\n\n/**\n * Given an OpenAPI-flavored JSON Schema, make an effort to modify it so it's shaped more towards\n * stock JSON Schema.\n *\n * Why do this?\n *\n * 1. OpenAPI 3.0.x supports its own flavor of JSON Schema that isn't fully compatible with most\n * JSON Schema tooling (like `@readme/oas-form` or `@rjsf/core`).\n * 2. While validating an OpenAPI definition will prevent corrupted or improper schemas from\n * occuring, we have a lot of legacy schemas in ReadMe that were ingested before we had proper\n * validation in place, and as a result have some API definitions that will not pass validation\n * right now. In addition to reshaping OAS-JSON Schema into JSON Schema this library will also\n * fix these improper schemas: things like `type: object` having `items` instead of `properties`,\n * or `type: array` missing `items`.\n * 3. To ease the burden of polymorphic handling on our form rendering engine we make an attempt\n * to merge `allOf` schemas here.\n * 4. Additionally due to OpenAPI 3.0.x not supporting JSON Schema, in order to support the\n * `example` keyword that OAS supports, we need to do some work in here to remap it into\n * `examples`. However, since all we care about in respect to examples for usage within\n * `@readme/oas-form`, we're only retaining primitives. This *slightly* deviates from JSON\n * Schema in that JSON Schema allows for any schema to be an example, but since\n * `@readme/oas-form` can only actually **render** primitives, that's what we're retaining.\n * 5. Though OpenAPI 3.1 does support full JSON Schema, this library should be able to handle it\n * without any problems.\n *\n * And why use this over `@openapi-contrib/openapi-schema-to-json-schema`? Fortunately and\n * unfortunately we've got a lot of API definitions in our database that aren't currently valid so\n * we need to have a lot of bespoke handling for odd quirks, typos, and missing declarations that\n * might be present.\n *\n * @todo add support for `schema: false` and `not` cases.\n * @todo tighten up `data` to allow for `SchemaObject | ReferenceObject`\n * @see {@link https://json-schema.org/draft/2019-09/json-schema-validation.html}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n * @param data OpenAPI Schema Object to convert to pure JSON Schema.\n */\nexport function toJSONSchema(data: SchemaObject | boolean, opts?: toJSONSchemaOptions): SchemaObject {\n let schema = data === true ? {} : { ...data };\n const schemaAdditionalProperties = isSchema(schema) ? schema.additionalProperties : null;\n\n const {\n addEnumsToDescriptions,\n currentLocation,\n definition,\n globalDefaults,\n hideReadOnlyProperties,\n hideWriteOnlyProperties,\n isPolymorphicAllOfChild,\n prevDefaultSchemas = [],\n prevExampleSchemas = [],\n refLogger,\n seenRefs,\n usedSchemas,\n refsEmittedAsStub = new Set<string>(),\n } = {\n addEnumsToDescriptions: false,\n currentLocation: '',\n globalDefaults: {},\n hideReadOnlyProperties: false,\n hideWriteOnlyProperties: false,\n isPolymorphicAllOfChild: false,\n prevDefaultSchemas: [] as toJSONSchemaOptions['prevDefaultSchemas'],\n prevExampleSchemas: [] as toJSONSchemaOptions['prevExampleSchemas'],\n refLogger: () => true,\n seenRefs: new Set<string>(),\n usedSchemas: new Map<string, SchemaObject>(),\n refsEmittedAsStub: new Set<string>(),\n ...opts,\n };\n\n const polyOptions: toJSONSchemaOptions = {\n addEnumsToDescriptions,\n currentLocation,\n definition,\n globalDefaults,\n hideReadOnlyProperties,\n hideWriteOnlyProperties,\n isPolymorphicAllOfChild: false,\n prevDefaultSchemas,\n prevExampleSchemas,\n refLogger,\n seenRefs,\n usedSchemas,\n refsEmittedAsStub,\n };\n\n // If this schema contains a `$ref` make an attempt to resolve and convert it into our\n // `usedSchemas` store, but still return the `$ref` in output so we preserve reference identity\n // instead of inlining a duplicate converted schema at this location.\n if (isRef(schema)) {\n if (definition && usedSchemas) {\n const resolved = resolveAndCacheRefSchema({\n schema,\n definition,\n usedSchemas,\n seenRefs,\n conversionOptions: polyOptions,\n returnMode: 'ref',\n refLogger,\n });\n\n // Preserve metadata siblings (e.g. description, summary) alongside `$ref` pointers because\n // OpenAPI 3.1 allows those to exist as local overrides. The `properties` keyword at the same\n // level as `$ref` however is invalid in JSON Schema and should be ignored.\n const { $ref: _$ref, properties: _propertiesWithRef, ...siblings } = schema as Record<string, unknown>;\n if (Object.keys(siblings).length > 0) {\n return { ...resolved, ...siblings };\n }\n\n return resolved;\n }\n\n refLogger(schema.$ref, 'ref');\n return schema;\n }\n\n // If we don't have a set type, but are dealing with an `anyOf`, `oneOf`, or `allOf`\n // representation let's run through them and make sure they're good.\n if (isSchema(schema, isPolymorphicAllOfChild)) {\n // If this is an `allOf` schema we should make an attempt to merge so as to ease the burden on\n // the tooling that ingests these schemas.\n if ('allOf' in schema && Array.isArray(schema.allOf)) {\n // If we have an API definition present then we should attempt to resolve each `$ref` in an\n // `allOf` before merging them together with `json-schema-merge-allof` so that that has access\n // to the full and actual schemas.\n let allOfSchemas = schema.allOf as SchemaObject[];\n if (definition && usedSchemas) {\n // When merging multiple `allOf` schemas together `$ref` pointers that are present are\n // merged away so we shouldn't log them. When an `allOf` has a single item we're just\n // unwrapping them schema, so `$ref` pointers _do_ appear in the output then we **should**\n // log those.\n const allOfOptions: toJSONSchemaOptions =\n schema.allOf.length > 1 ? { ...polyOptions, refLogger: () => {} } : polyOptions;\n\n allOfSchemas = schema.allOf.map(item => {\n if (isRef(item)) {\n return resolveAndCacheRefSchema({\n schema: item,\n definition,\n usedSchemas,\n seenRefs,\n conversionOptions: allOfOptions,\n returnMode: 'converted',\n refLogger,\n });\n }\n\n return toJSONSchema(item as SchemaObject, allOfOptions);\n });\n\n schema = {\n ...schema,\n allOf: allOfSchemas.map(s => inlinePropertyRefsForMerge(s, usedSchemas)),\n } as SchemaObject;\n }\n\n try {\n schema = mergeJSONSchemaAllOf(schema as JSONSchema, {\n ignoreAdditionalProperties: true,\n resolvers: {\n // `merge-json-schema-allof` by default takes the first `description` when you're\n // merging an `allOf` but because generally when you're merging two schemas together\n // with an `allOf` you want data in the subsequent schemas to be applied to the first\n // and `description` should be a part of that.\n description: (obj: string[]) => {\n return obj.slice(-1)[0];\n },\n\n // `merge-json-schema-allof` doesn't support merging enum arrays but since that's a\n // safe and simple operation as enums always contain primitives we can handle it\n // ourselves with a custom resolver. We intersect the arrays so that child schemas\n // can narrow a parent's broad enum (e.g. [1,2,20,50] ∩ [1] = [1]).\n //\n // We unfortunately need to cast our return value as `any[]` because the internal types\n // of `merge-json-schema-allof`'s `enum` resolver are not portable.\n enum: (obj: unknown[]) => {\n const arrays = obj as any[][];\n const intersection = arrays.reduce((acc, e) => acc.filter(v => e.includes(v)));\n return intersection.length > 0 ? intersection : arrays.reduce((acc, e) => acc.concat(e), []);\n },\n\n // for any unknown keywords (e.g., `example`, `format`, `x-readme-ref-name`),\n // we fallback to using the title resolver (which uses the first value found).\n // https://github.com/mokkabonna/json-schema-merge-allof/blob/ea2e48ee34415022de5a50c236eb4793a943ad11/src/index.js#L292\n // https://github.com/mokkabonna/json-schema-merge-allof/blob/ea2e48ee34415022de5a50c236eb4793a943ad11/README.md?plain=1#L147\n defaultResolver: mergeJSONSchemaAllOf.options.resolvers.title,\n },\n }) as SchemaObject;\n } catch {\n // If we can't merge the `allOf` for whatever reason (like if one item is a `string` and\n // the other is a `object`) then we should completely remove it from the schema and continue\n // with whatever we've got. Why? If we don't, any tooling that's ingesting this will need\n // to account for the incompatible `allOf` and it may be subject to more breakages than\n // just not having it present would be.\n const { ...schemaWithoutAllOf } = schema;\n schema = schemaWithoutAllOf as SchemaObject;\n delete schema.allOf;\n }\n\n // This is a little messy but because `json-schema-merge-allof` doesn't support attaching a\n // resolver to a deeply nested `$ref` pointer, which we would need to do in order to emit\n // that a `$ref` is present in this schema, we need to instead scan the resulting schema\n // for them.\n collectRefsInSchema(schema).forEach(ref => {\n refLogger(ref, 'ref');\n });\n\n // If after merging the `allOf` this schema still contains a `$ref` then it's circular and\n // we shouldn't do anything else. Preserve sibling properties alongside the `$ref`.\n if (isRef(schema)) {\n refLogger(schema.$ref, 'ref');\n\n return schema;\n }\n }\n\n (['anyOf', 'oneOf'] as const).forEach((polyType: 'anyOf' | 'oneOf') => {\n if (polyType in schema && Array.isArray(schema[polyType])) {\n const discriminatorPropertyName =\n 'discriminator' in schema && schema.discriminator && isObject(schema.discriminator)\n ? schema.discriminator.propertyName\n : undefined;\n\n schema[polyType].forEach((item, idx) => {\n if (!schema[polyType]?.[idx]) {\n // We should never hit this because `anyOf` and `oneOf` ara guaranteed by this point to\n // be arrays but TS isn't smart enough to carry this inferrence down to this block.\n return;\n }\n\n const itemOptions: toJSONSchemaOptions = {\n ...polyOptions,\n currentLocation: `${currentLocation}/${idx}`,\n };\n\n // When `properties` or `items` are present alongside a polymorphic schema instead of\n // letting whatever JSON Schema interpreter is handling these constructed schemas we can\n // guide its hand a bit by manually transforming it into an inferred `allOf` of the\n // `properties` + the polymorph schema.\n //\n // This `allOf` schema will be merged together when fed through `toJSONSchema`.\n if ('properties' in schema) {\n schema[polyType][idx] = toJSONSchema(\n {\n required: schema.required,\n allOf: [item, { properties: schema.properties }],\n } as SchemaObject,\n itemOptions,\n );\n } else if ('items' in schema) {\n schema[polyType][idx] = toJSONSchema(\n {\n allOf: [item, { items: schema.items }],\n } as SchemaObject,\n itemOptions,\n );\n } else {\n schema[polyType][idx] = toJSONSchema(item as SchemaObject, itemOptions);\n }\n\n // Ensure that we don't have any invalid `required` booleans or empty arrays lying around.\n if ('required' in (schema[polyType][idx] as SchemaObject)) {\n if (Array.isArray(schema[polyType][idx].required) && schema[polyType][idx].required.length === 0) {\n delete (schema[polyType][idx] as SchemaObject).required;\n } else if (\n isObject(schema[polyType][idx]) &&\n typeof (schema[polyType][idx] as SchemaObject).required === 'boolean'\n ) {\n delete (schema[polyType][idx] as SchemaObject).required;\n }\n }\n\n // When a parent schema has a discriminator and child schemas inherit via allOf, the child\n // schemas can inherit the parent's discriminator, oneOf, and anyOf. We remove these\n // from child schemas to avoid nested discriminator UIs where each child incorrectly shows\n // all other children as options. This keeps the discriminator only at the parent level.\n if (discriminatorPropertyName) {\n const childSchema = schema[polyType][idx] as SchemaObject;\n if (isObject(childSchema)) {\n if ('discriminator' in childSchema) {\n delete (childSchema as Record<string, unknown>).discriminator;\n }\n if ('oneOf' in childSchema) {\n delete (childSchema as Record<string, unknown>).oneOf;\n }\n if ('anyOf' in childSchema) {\n delete (childSchema as Record<string, unknown>).anyOf;\n }\n }\n\n // When the child is a `$ref` the actual schema lives in `usedSchemas` so we should\n // strip these polymorphic keywords there too.\n if (definition && usedSchemas && isRef(childSchema)) {\n const resolved = usedSchemas.get(childSchema.$ref);\n if (resolved && typeof resolved === 'object' && !isPendingSchema(resolved)) {\n if ('discriminator' in resolved) {\n delete (resolved as Record<string, unknown>).discriminator;\n }\n if ('oneOf' in resolved) {\n delete (resolved as Record<string, unknown>).oneOf;\n }\n if ('anyOf' in resolved) {\n delete (resolved as Record<string, unknown>).anyOf;\n }\n\n // Instead of relying on the `resovled` reference populating back into `usedSchemas`\n // we should make sure that that schema is refreshed with our new schema.\n usedSchemas.set(childSchema.$ref, resolved);\n }\n }\n }\n });\n }\n });\n\n if (schema?.discriminator?.mapping && typeof schema.discriminator.mapping === 'object') {\n // Discriminator mappings aren't written as traditional `$ref` pointers so in order to log\n // them to the supplied `refLogger`.\n const mapping = schema.discriminator.mapping;\n Object.keys(mapping).forEach(k => {\n refLogger(mapping[k], 'discriminator');\n });\n }\n }\n\n // If this schema is malformed for some reason, let's do our best to repair it.\n if (!('type' in schema) && !isPolymorphicSchema(schema) && !isRequestBodySchema(schema)) {\n if ('properties' in schema) {\n schema.type = 'object';\n } else if ('items' in schema) {\n schema.type = 'array';\n } else {\n // If there's still no `type` on the schema we should leave it alone because we don't have a\n // great way to know if it's part of a nested schema that should, and couldn't be merged,\n // into another, or it's just purely malformed.\n //\n // Whatever tooling that ingests the generated schema should handle it however it needs to.\n }\n }\n\n if ('type' in schema && schema.type !== undefined) {\n // `nullable` isn't a thing in JSON Schema but it was in OpenAPI 3.0 so we should retain and\n // translate it into something that's compatible with JSON Schema.\n if ('nullable' in schema) {\n if (schema.nullable) {\n if (Array.isArray(schema.type)) {\n schema.type.push('null');\n } else if (schema.type !== null && schema.type !== 'null') {\n schema.type = [schema.type, 'null'];\n }\n }\n\n delete schema.nullable;\n }\n\n if (schema.type === null) {\n // `type: null` is possible in JSON Schema but we're translating it to a string version\n // so we don't need to worry about asserting nullish types in our implementations of this\n // generated schema.\n (schema as SchemaObject).type = 'null';\n } else if (Array.isArray(schema.type)) {\n // @ts-expect-error -- `null` is not valid in JSON Schema but it can be done in OpenAPI 3.0.\n if (schema.type.includes(null)) {\n // @ts-expect-error -- `null` is not valid in JSON Schema but it can be done in OpenAPI 3.0.\n schema.type[schema.type.indexOf(null)] = 'null';\n }\n\n schema.type = Array.from(new Set(schema.type));\n\n // We don't need `type: [<type>]` when we can just as easily make it `type: <type>`.\n if (schema.type.length === 1) {\n schema.type = schema.type.shift();\n } else if (schema.type.includes('array') || schema.type.includes('boolean') || schema.type.includes('object')) {\n // If we have a `null` type but there's only two types present then we can remove `null`\n // as an option and flag the whole schema as `nullable`.\n const isNullable = schema.type.includes('null');\n\n if (schema.type.length === 2 && isNullable) {\n // If this is `array | null` or `object | null` then we don't need to do anything.\n } else {\n // If this mixed type has non-primitives then we for convenience of our implementation\n // we're moving them into a `oneOf`.\n const nonPrimitives: any[] = [];\n\n // Because arrays, booleans, and objects are not compatible with any other schem type\n // other than null we're moving them into an isolated `oneOf`, and as such want to take\n // with it its specific properties that may be present on our current schema.\n Object.entries({\n // https://json-schema.org/understanding-json-schema/reference/array.html\n array: [\n 'additionalItems',\n 'contains',\n 'items',\n 'maxContains',\n 'maxItems',\n 'minContains',\n 'minItems',\n 'prefixItems',\n 'uniqueItems',\n ],\n\n // https://json-schema.org/understanding-json-schema/reference/boolean.html\n boolean: [\n // Booleans don't have any boolean-specific properties.\n ],\n\n // https://json-schema.org/understanding-json-schema/reference/object.html\n object: [\n 'additionalProperties',\n 'maxProperties',\n 'minProperties',\n 'nullable',\n 'patternProperties',\n 'properties',\n 'propertyNames',\n 'required',\n ],\n } as Record<string, (keyof SchemaObject)[]>).forEach(([typeKey, keywords]) => {\n if (!schema.type?.includes(typeKey as JSONSchema7TypeName)) {\n return;\n }\n\n const reducedSchema: any = removeUndefinedObjects({\n type: isNullable ? [typeKey, 'null'] : typeKey,\n\n allowEmptyValue: (schema as any).allowEmptyValue ?? undefined,\n deprecated: schema.deprecated ?? undefined,\n description: schema.description ?? undefined,\n readOnly: schema.readOnly ?? undefined,\n title: schema.title ?? undefined,\n writeOnly: schema.writeOnly ?? undefined,\n });\n\n keywords.forEach(keyword => {\n if (keyword in schema) {\n reducedSchema[keyword] = schema[keyword];\n delete schema[keyword];\n }\n });\n\n nonPrimitives.push(reducedSchema);\n });\n\n schema.type = schema.type.filter(t => t !== 'array' && t !== 'boolean' && t !== 'object');\n if (schema.type.length === 1) {\n schema.type = schema.type.shift();\n }\n\n // Because we may have encountered a fully mixed non-primitive type like `array | object`\n // we only want to retain the existing schema object if we still have types remaining\n // in it.\n if (schema.type && schema.type.length > 1) {\n schema = { oneOf: [schema, ...nonPrimitives] };\n } else {\n schema = { oneOf: nonPrimitives };\n }\n }\n }\n }\n }\n\n if (isSchema(schema, isPolymorphicAllOfChild)) {\n if ('default' in schema && isObject(schema.default)) {\n prevDefaultSchemas.push({ default: schema.default });\n }\n\n // JSON Schema doesn't support OpenAPI-style examples so we need to reshape them a bit.\n if ('example' in schema) {\n // Only bother adding primitive examples.\n if (isPrimitive(schema.example)) {\n schema.examples = [schema.example];\n } else if (Array.isArray(schema.example)) {\n schema.examples = schema.example.filter(example => isPrimitive(example));\n if (!schema.examples.length) {\n delete schema.examples;\n }\n } else {\n prevExampleSchemas.push({ example: schema.example });\n }\n\n delete schema.example;\n } else if ('examples' in schema) {\n let reshapedExamples = false;\n if (typeof schema.examples === 'object' && schema.examples !== null && !Array.isArray(schema.examples)) {\n const examples: unknown[] = [];\n\n Object.entries(schema.examples).forEach(([name, example]) => {\n let currentExample = example as ExampleObject | ReferenceObject;\n if (name === '$ref') {\n currentExample = dereferenceRef({ $ref: currentExample } as ReferenceObject, definition, seenRefs);\n if (!currentExample || isRef(currentExample)) {\n // If this example is invalid or still a `$ref` after lazy dereferencing then we\n // should log and ignore it.\n refLogger(currentExample.$ref, 'ref');\n return;\n }\n }\n\n if ('value' in currentExample) {\n if (isPrimitive(currentExample.value)) {\n examples.push(currentExample.value);\n reshapedExamples = true;\n } else if (Array.isArray(currentExample.value) && isPrimitive(currentExample.value[0])) {\n examples.push(currentExample.value[0]);\n reshapedExamples = true;\n } else {\n // If this example is neither a primitive or an array we should dump it into the\n // `prevExampleSchemas` array because we might be able to extract an example from it\n // further downstream.\n prevExampleSchemas.push({\n example: currentExample.value,\n });\n }\n }\n });\n\n if (examples.length) {\n reshapedExamples = true;\n schema.examples = examples;\n }\n } else if (Array.isArray(schema.examples) && isPrimitive(schema.examples[0])) {\n // We haven't reshaped `examples` here, but since it's in a state that's preferrable to us\n // let's keep it around.\n reshapedExamples = true;\n }\n\n if (!reshapedExamples) {\n delete schema.examples;\n }\n }\n\n // If we didn't have any immediately defined examples, let's search backwards and see if we can\n // find one. But as we're only looking for primitive example, only try to search for one if\n // we're dealing with a primitive schema.\n if (!hasSchemaType(schema, 'array') && !hasSchemaType(schema, 'object') && !schema.examples) {\n const foundExample = searchForValueByPropAndPointer('example', currentLocation, prevExampleSchemas);\n if (foundExample) {\n // We can only really deal with primitives, so only promote those as the found example if\n // it is.\n if (isPrimitive(foundExample) || (Array.isArray(foundExample) && isPrimitive(foundExample[0]))) {\n schema.examples = [foundExample];\n }\n }\n }\n\n if (hasSchemaType(schema, 'array')) {\n if ('items' in schema && schema.items !== undefined) {\n if (\n !(definition && usedSchemas) &&\n !Array.isArray(schema.items) &&\n Object.keys(schema.items).length === 1 &&\n isRef(schema.items)\n ) {\n // When not resolving refs, `items` that is a lone `$ref` is treated as circular; log and leave as-is.\n refLogger(schema.items.$ref, 'ref');\n } else if (schema.items !== true) {\n // Run through the arrays contents and clean them up (including resolving $ref in items when in ref-resolution mode).\n // Do not pass prevDefaultSchemas: the array's default (e.g. [12, 34, 56]) belongs on the array,\n // not on items (we must not set default: 12 on items when the default is already on tags).\n schema.items = toJSONSchema(schema.items as SchemaObject, {\n ...polyOptions,\n currentLocation: `${currentLocation}/0`,\n prevDefaultSchemas: [],\n prevExampleSchemas,\n });\n\n // If we have a non-array, or empty array, `required` entry in our `items` schema then\n // it's invalid and we should remove it. We only support non-array boolean `required`\n // properties inside object properties.\n if ('required' in schema.items) {\n if (Array.isArray(schema.items.required) && schema.items.required.length === 0) {\n delete schema.items.required;\n } else if (isObject(schema.items) && !Array.isArray(schema.items.required)) {\n delete schema.items.required;\n }\n }\n }\n } else if ('properties' in schema || 'additionalProperties' in schema) {\n // This is a fix to handle cases where someone may have typod `items` as `properties` on an\n // array. Since throwing a complete failure isn't ideal, we can see that they meant for the\n // type to be `object`, so we can do our best to shape the data into what they were\n // intending it to be.\n schema.type = 'object';\n } else {\n // This is a fix to handle cases where we have a malformed array with no `items` property\n // present.\n (schema as any).items = {};\n }\n } else if (hasSchemaType(schema, 'object')) {\n if ('properties' in schema && schema.properties !== undefined) {\n Object.keys(schema.properties).forEach(prop => {\n if (\n Array.isArray(schema.properties?.[prop]) ||\n (typeof schema.properties?.[prop] === 'object' && schema.properties?.[prop] !== null)\n ) {\n const newPropSchema = toJSONSchema(schema.properties[prop] as SchemaObject, {\n ...polyOptions,\n currentLocation: `${currentLocation}/${encodePointer(prop)}`,\n prevDefaultSchemas,\n prevExampleSchemas,\n });\n\n // If this property is read or write only then we should fully hide it from its parent schema.\n let propShouldBeUpdated = true;\n if ((hideReadOnlyProperties || hideWriteOnlyProperties) && !Object.keys(newPropSchema).length) {\n // We should only delete this schema if it wasn't already empty though. We do this\n // because we (un)fortunately have handling in our API Explorer form system for\n // schemas that are devoid of any `type` declaration.\n if (Object.keys(schema.properties[prop]).length > 0) {\n delete schema.properties[prop];\n propShouldBeUpdated = false;\n }\n }\n\n if (propShouldBeUpdated) {\n schema.properties[prop] = newPropSchema;\n\n /**\n * JSON Schema does not have any support for `required: <boolean>` but because some\n * of our users do this, and it does not throw OpenAPI validation errors thanks to\n * some extremely loose typings around `schema` in the official JSON Schema\n * definitions that the OAI offers, we're opting to support these users and upgrade\n * their invalid `required` definitions into ones that our tooling can interpret.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/schemas/v3.1/schema.json#L1114-L1121}\n */\n if (\n isObject(newPropSchema) &&\n 'required' in newPropSchema &&\n typeof newPropSchema.required === 'boolean' &&\n newPropSchema.required === true\n ) {\n if ('required' in schema && Array.isArray(schema.required)) {\n schema.required.push(prop);\n } else {\n schema.required = [prop];\n }\n\n delete (schema.properties[prop] as SchemaObject).required;\n }\n }\n }\n });\n\n // If we want to hide all readOnly or writeOnly properites and it happens to be that this\n // object was comprised of only those then we shouldn't render this object.\n if (hideReadOnlyProperties || hideWriteOnlyProperties) {\n if (!Object.keys(schema.properties).length) {\n return {};\n }\n }\n }\n\n if (typeof schemaAdditionalProperties === 'object' && schemaAdditionalProperties !== null) {\n // If this `additionalProperties` is completely empty and devoid of any sort of schema,\n // treat it as such. Otherwise let's recurse into it and see if we can sort it out.\n if (\n !('type' in schemaAdditionalProperties) &&\n !('$ref' in schemaAdditionalProperties) &&\n // We know it will be a schema object because it's dereferenced\n !isPolymorphicSchema(schemaAdditionalProperties as SchemaObject)\n ) {\n schema.additionalProperties = true;\n } else {\n // We know it will be a schema object because it's dereferenced\n schema.additionalProperties = toJSONSchema(schemaAdditionalProperties as SchemaObject, {\n ...polyOptions,\n currentLocation,\n prevDefaultSchemas,\n prevExampleSchemas,\n });\n }\n }\n\n // Since neither `properties` and `additionalProperties` are actually required to be present\n // on an object, since we construct this schema work to build up a form we still need\n // *something* for the user to enter in for this object so we'll add back in\n // `additionalProperties` for that.\n if (!isPolymorphicSchema(schema) && !('properties' in schema) && !('additionalProperties' in schema)) {\n schema.additionalProperties = true;\n }\n }\n }\n\n /**\n * Users can pass in parameter defaults via JWT User Data. We're checking to see if the defaults\n * being passed in exist on endpoints via jsonpointer\n *\n * @see {@link https://docs.readme.com/docs/passing-data-to-jwt}\n */\n if (\n isSchema(schema, isPolymorphicAllOfChild) &&\n globalDefaults &&\n Object.keys(globalDefaults).length > 0 &&\n currentLocation\n ) {\n try {\n const userJwtDefault = jsonpointer.get(globalDefaults, currentLocation);\n if (userJwtDefault) {\n schema.default = userJwtDefault;\n }\n } catch {\n // If jsonpointer returns an error, we won't show any defaults for that path.\n }\n }\n\n // Only add a default value if we actually have one.\n if ('default' in schema && typeof schema.default !== 'undefined') {\n if (hasSchemaType(schema, 'object')) {\n // Defaults for `object` and types have been dereferenced into their children schemas already\n // above so we don't need to preserve this default anymore.\n delete schema.default;\n } else if (\n ('allowEmptyValue' in schema && schema.allowEmptyValue && schema.default === '') ||\n schema.default !== ''\n ) {\n // If we have `allowEmptyValue` present, and the default is actually an empty string, let it\n // through as it's allowed.\n } else {\n // If the default is empty and we don't want to allowEmptyValue, we need to remove the\n // default.\n delete schema.default;\n }\n } else if (prevDefaultSchemas.length) {\n const foundDefault = searchForValueByPropAndPointer('default', currentLocation, prevDefaultSchemas);\n\n // We shouldn't ever set an object default out of the parent lineage tree defaults because\n // the contents of that object will be set on the schema that they're a part of. Setting\n // that object as well would result us in duplicating the defaults for that schema in two\n // places.\n if (\n isPrimitive(foundDefault) ||\n foundDefault === null ||\n (Array.isArray(foundDefault) && hasSchemaType(schema, 'array'))\n ) {\n (schema as SchemaObject).default = foundDefault;\n }\n }\n\n if (isSchema(schema, isPolymorphicAllOfChild) && 'enum' in schema && Array.isArray(schema.enum)) {\n // Enums should not have duplicated items as those will break AJV validation.\n // If we ever target ES6 for typescript we can drop this array.from.\n // https://stackoverflow.com/questions/33464504/using-spread-syntax-and-new-set-with-typescript/56870548\n schema.enum = Array.from(new Set(schema.enum));\n\n // If we want to add enums to descriptions (like in the case of response JSON Schema)\n // generation we need to convert them into a list of Markdown tilda'd strings. We're also\n // filtering away empty and falsy strings here because adding empty `` blocks to the description\n // will serve nobody any good.\n if (addEnumsToDescriptions) {\n const enums = schema.enum\n .filter(v => v !== undefined && (typeof v !== 'string' || v.trim() !== ''))\n .map(str => `\\`${str}\\``)\n .join(' ');\n\n if (enums.length) {\n const currentDescription =\n 'description' in schema && typeof schema.description === 'string' ? schema.description : '';\n\n if (!currentDescription) {\n schema.description = enums;\n } else {\n const paragraphs = currentDescription.split(/\\n\\n+/).map(p => p.trim());\n const enumParagraphCount = paragraphs.filter(p => p === enums).length;\n\n // After `allOf` merging nested properties are run through `toJSONSchema` again however\n // enum description additions may already be present from the first pass, we should avoid\n // duplicating thoes addendums.\n if (enumParagraphCount > 1) {\n const withoutEnum = paragraphs.filter(p => p !== enums);\n schema.description = withoutEnum.length > 0 ? `${withoutEnum.join('\\n\\n')}\\n\\n${enums}` : enums;\n } else if (paragraphs.some(p => p === enums)) {\n // noop\n } else {\n schema.description = `${currentDescription}\\n\\n${enums}`;\n }\n }\n }\n }\n }\n\n // Clean up any remaining `items` or `properties` schema fragments lying around if there's also\n // polymorphism present.\n if ('anyOf' in schema || 'oneOf' in schema) {\n // If this polymorphic schema is comprised of schemas that were unable to be merged and are now\n // empty objects then we should wipe them out because they're fully invalid.\n for (const key of ['anyOf', 'oneOf'] as const) {\n if (key in schema && isEmptyPolymorphicSchema(schema[key])) {\n delete schema[key];\n }\n }\n\n if ('anyOf' in schema || 'oneOf' in schema) {\n if ('properties' in schema) {\n delete schema.properties;\n }\n\n if ('items' in schema) {\n delete schema.items;\n }\n }\n }\n\n // Remove unsupported JSON Schema props.\n for (let i = 0; i < UNSUPPORTED_SCHEMA_PROPS.length; i += 1) {\n // Using the as here because the purpose is to delete keys we don't expect, so of course the\n // typing won't work\n delete (schema as Record<string, unknown>)[UNSUPPORTED_SCHEMA_PROPS[i]];\n }\n\n // If we want to hide any `readOnly` or `writeOnly` schemas, and this one is that, then we\n // shouldn't return anything.\n if (hideReadOnlyProperties && 'readOnly' in schema && schema.readOnly === true) {\n return {};\n } else if (hideWriteOnlyProperties && 'writeOnly' in schema && schema.writeOnly === true) {\n return {};\n }\n\n return schema;\n}\n","import type { OpenAPIV3_1 } from 'openapi-types';\nimport type { toJSONSchemaOptions } from '../../lib/openapi-to-json-schema.js';\nimport type { ExampleObject, OASDocument, ParameterObject, SchemaObject, SchemaWrapper } from '../../types.js';\nimport type { Operation } from '../index.js';\n\nimport { getExtension, PARAMETER_ORDERING } from '../../extensions.js';\nimport { applyDiscriminatorOneOfToUsedSchemas } from '../../lib/build-discriminator-one-of.js';\nimport { cloneObject } from '../../lib/clone-object.js';\nimport { getParameterContentType } from '../../lib/get-parameter-content-type.js';\nimport { isPrimitive } from '../../lib/helpers.js';\nimport { getSchemaVersionString, toJSONSchema } from '../../lib/openapi-to-json-schema.js';\nimport { dereferenceRef, filterRequiredRefsToReferenced, mergeReferencedSchemasIntoRoot } from '../../lib/refs.js';\nimport { isRef } from '../../types.js';\n\n/**\n * The order of this object determines how they will be sorted in the compiled JSON Schema\n * representation.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameter-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object}\n */\nexport const types: Record<keyof OASDocument, string> = {\n path: 'Path Params',\n query: 'Query Params',\n body: 'Body Params',\n cookie: 'Cookie Params',\n formData: 'Form Data',\n header: 'Headers',\n metadata: 'Metadata', // This a special type reserved for https://npm.im/api\n};\n\nexport interface getParametersAsJSONSchemaOptions {\n /**\n * Contains an object of user defined schema defaults.\n */\n globalDefaults?: Record<string, unknown>;\n\n /**\n * If you wish to hide properties that are marked as being `readOnly`.\n */\n hideReadOnlyProperties?: boolean;\n\n /**\n * If you wish to hide properties that are marked as being `writeOnly`.\n */\n hideWriteOnlyProperties?: boolean;\n\n /**\n * If you wish to include discriminator mapping `$ref` components alongside your\n * `discriminator` in schemas. Defaults to `true`.\n */\n includeDiscriminatorMappingRefs?: boolean;\n\n /**\n * If you want the output to be two objects: body (contains `body` and `formData` JSON\n * Schema) and metadata (contains `path`, `query`, `cookie`, and `header`).\n */\n mergeIntoBodyAndMetadata?: boolean;\n}\n\nexport function getParametersAsJSONSchema(\n operation: Operation,\n api: OASDocument,\n opts?: getParametersAsJSONSchemaOptions,\n): SchemaWrapper[] | null {\n const seenRefs = new Set<string>();\n const refsByGroup = new Map<string, Set<string>>();\n const usedSchemasByGroup = new Map<string, Map<string, SchemaObject>>();\n\n function refLoggerForSchemaGroup(group: string) {\n let set = refsByGroup.get(group);\n if (!set) {\n set = new Set();\n refsByGroup.set(group, set);\n }\n\n return set;\n }\n\n function usedSchemasForSchemaGroup(group: string) {\n let map = usedSchemasByGroup.get(group);\n if (!map) {\n map = new Map<string, SchemaObject>();\n usedSchemasByGroup.set(group, map);\n }\n\n return map;\n }\n\n const baseSchemaOptions: toJSONSchemaOptions = {\n definition: api,\n globalDefaults: opts?.globalDefaults,\n hideReadOnlyProperties: opts?.hideReadOnlyProperties,\n hideWriteOnlyProperties: opts?.hideWriteOnlyProperties,\n seenRefs,\n };\n\n function transformRequestBody(): SchemaWrapper | null {\n const requestBody = operation.getRequestBody();\n if (!requestBody || !Array.isArray(requestBody)) return null;\n\n const [mediaType, mediaTypeObject, description] = requestBody;\n const type = mediaType === 'application/x-www-form-urlencoded' ? 'formData' : 'body';\n\n // If this schema is completely empty, don't bother processing it.\n if (!mediaTypeObject.schema || !Object.keys(mediaTypeObject.schema).length) {\n return null;\n }\n\n const prevExampleSchemas: toJSONSchemaOptions['prevExampleSchemas'] = [];\n if ('example' in mediaTypeObject) {\n prevExampleSchemas.push({ example: mediaTypeObject.example });\n } else if ('examples' in mediaTypeObject) {\n prevExampleSchemas.push({\n examples: Object.values(mediaTypeObject.examples || {})\n .map(ex => {\n let example = ex;\n if (!example) return undefined;\n if (isRef(example)) {\n example = dereferenceRef(example, operation.api);\n if (!example || isRef(example)) return undefined;\n }\n\n return example.value;\n })\n .filter((item): item is ExampleObject => item !== undefined),\n });\n }\n\n // We're cloning the request schema because we've had issues with request schemas that were\n // dereferenced being processed multiple times because their component is also processed.\n const requestSchema = cloneObject(mediaTypeObject.schema);\n\n const cleanedSchema = toJSONSchema(requestSchema, {\n ...baseSchemaOptions,\n usedSchemas: usedSchemasForSchemaGroup(type),\n prevExampleSchemas,\n refLogger: ref => refLoggerForSchemaGroup(type).add(ref),\n });\n\n // If this schema is **still** empty, don't bother returning it.\n if (!Object.keys(cleanedSchema).length) {\n return null;\n }\n\n return {\n type,\n label: types[type],\n schema: isPrimitive(cleanedSchema)\n ? cleanedSchema\n : {\n ...cleanedSchema,\n $schema: getSchemaVersionString(cleanedSchema, api),\n },\n ...(description ? { description } : {}),\n };\n }\n\n function transformParameters(): SchemaWrapper[] {\n const operationParams = operation.getParameters();\n\n const transformed = Object.keys(types)\n .map(type => {\n const required: string[] = [];\n\n // This `as` actually *could* be a ref, but we don't want refs to pass through here, so\n // `.in` will never match `type`\n const parameters = operationParams.filter(param => (param as ParameterObject).in === type);\n if (parameters.length === 0) {\n return null;\n }\n\n const properties = parameters.reduce((prev: Record<string, SchemaObject>, current: ParameterObject) => {\n let schema: SchemaObject = {};\n if ('schema' in current) {\n const currentSchema: SchemaObject = current.schema ? cloneObject(current.schema) : {};\n\n if (current.example) {\n // `example` can be present outside of the `schema` block so if it's there we should\n // pull it in so it can be handled and returned if it's valid.\n currentSchema.example = current.example;\n } else if (current.examples) {\n // `examples` isn't actually supported here in OAS 3.0, but we might as well support\n // it because `examples` is JSON Schema and that's fully supported in OAS 3.1.\n currentSchema.examples = current.examples as unknown as unknown[];\n }\n\n if (current.deprecated) currentSchema.deprecated = current.deprecated;\n\n const interimSchema = toJSONSchema(currentSchema, {\n ...baseSchemaOptions,\n usedSchemas: usedSchemasForSchemaGroup(type),\n currentLocation: `/${current.name}`,\n refLogger: ref => refLoggerForSchemaGroup(type).add(ref),\n });\n\n schema = isPrimitive(interimSchema) ? interimSchema : { ...interimSchema };\n } else if ('content' in current && typeof current.content === 'object') {\n const contentKeys = Object.keys(current.content);\n if (contentKeys.length) {\n const contentType = getParameterContentType(contentKeys);\n if (\n contentType &&\n typeof current.content[contentType] === 'object' &&\n 'schema' in current.content[contentType]\n ) {\n const currentSchema: SchemaObject = current.content[contentType].schema\n ? cloneObject(current.content[contentType].schema)\n : {};\n\n if (current.example) {\n // `example` can be present outside of the `schema` block so if it's there we\n // should pull it in so it can be handled and returned if it's valid.\n currentSchema.example = current.example;\n } else if (current.examples) {\n // `examples` isn't actually supported here in OAS 3.0, but we might as well\n // support it because `examples` is JSON Schema and that's fully supported in OAS\n // 3.1.\n currentSchema.examples = current.examples as unknown as unknown[];\n }\n\n if (current.deprecated) currentSchema.deprecated = current.deprecated;\n\n const interimSchema = toJSONSchema(currentSchema, {\n ...baseSchemaOptions,\n usedSchemas: usedSchemasForSchemaGroup(type),\n currentLocation: `/${current.name}`,\n refLogger: ref => refLoggerForSchemaGroup(type).add(ref),\n });\n\n schema = isPrimitive(interimSchema) ? interimSchema : { ...interimSchema };\n }\n }\n }\n\n // Parameter descriptions don't exist in `current.schema` so `constructSchema` will never\n // have access to it.\n if (current.description) {\n if (!isPrimitive(schema)) {\n schema.description = current.description;\n }\n }\n\n prev[current.name] = schema;\n\n if (current.required) {\n required.push(current.name);\n }\n\n return prev;\n }, {});\n\n const schema: OpenAPIV3_1.SchemaObject = {\n $schema: getSchemaVersionString({}, api),\n type: 'object',\n properties: properties as Record<string, OpenAPIV3_1.SchemaObject>,\n ...(required.length > 0 ? { required } : {}),\n };\n\n return {\n type,\n label: types[type],\n schema,\n };\n })\n .filter(item => item !== null);\n\n if (!opts?.mergeIntoBodyAndMetadata) {\n return transformed;\n } else if (!transformed.length) {\n return [];\n }\n\n // If we want to merge parameters into a single metadata entry then we need to pull all\n // available schemas under one roof.\n return [\n {\n type: 'metadata',\n label: types.metadata,\n schema: {\n allOf: transformed.map(r => r.schema),\n },\n },\n ];\n }\n\n // If this operation neither has any parameters or a request body then we should return `null`\n // because there won't be any JSON Schema.\n if (!operation.hasParameters() && !operation.hasRequestBody()) {\n return null;\n }\n\n // `metadata` is `api` SDK specific, is not a part of the `PARAMETER_ORDERING` extension, and\n // should always be sorted last. We also define `formData` as `form` in the extension because\n // we don't want folks to have to deal with casing issues so we need to rewrite it to `formData`.\n const typeKeys = (getExtension(PARAMETER_ORDERING, api, operation) as string[]).map(k => k.toLowerCase());\n typeKeys[typeKeys.indexOf('form')] = 'formData';\n typeKeys.push('metadata');\n\n const jsonSchema = [transformRequestBody()]\n .concat(...transformParameters())\n .filter((item): item is SchemaWrapper => item !== null);\n\n // For each group include only schemas that are referenced or otherwise used within that groups'\n // schema. This allows us to avoid having to include schemas or components that are not used,\n // which would otherwise add to the overall bloat and memory footprint of the generated JSON\n // Schema object.\n return jsonSchema\n .map(group => {\n if (group.schema && typeof group.schema === 'object') {\n const usedSchemas = usedSchemasByGroup.get(group.type) ?? new Map<string, SchemaObject>();\n\n // Apply discriminator `oneOf` arrays to used schemas.\n applyDiscriminatorOneOfToUsedSchemas(api, usedSchemas, (ref: string) => {\n if (usedSchemas.has(ref)) {\n return usedSchemas.get(ref);\n }\n\n try {\n const resolved = dereferenceRef({ $ref: ref }, api, seenRefs);\n if (isRef(resolved)) return undefined;\n const converted = toJSONSchema(structuredClone(resolved) as SchemaObject, {\n ...baseSchemaOptions,\n usedSchemas,\n seenRefs,\n });\n\n usedSchemas.set(ref, converted);\n return converted;\n } catch {\n return undefined;\n }\n });\n\n const refsInGroup = refsByGroup.get(group.type) ?? new Set();\n const referencedSchemas = filterRequiredRefsToReferenced(refsInGroup, usedSchemas);\n\n if (referencedSchemas.size > 0) {\n mergeReferencedSchemasIntoRoot(group.schema, referencedSchemas);\n }\n }\n\n return group;\n })\n .sort((a, b) => {\n return typeKeys.indexOf(a.type) - typeKeys.indexOf(b.type);\n });\n}\n","import { getParameterContentType } from './lib/get-parameter-content-type.js';\nimport matchesMimeType from './lib/matches-mimetype.js';\nimport { dereferenceRef } from './lib/refs.js';\nimport { types as jsonSchemaTypes } from './operation/transformers/get-parameters-as-json-schema.js';\n\nexport const supportedMethods = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'] as const;\n\nexport const SERVER_VARIABLE_REGEX: RegExp = /{([-_a-zA-Z0-9:.[\\]]+)}/g;\n\nexport { getParameterContentType, jsonSchemaTypes, matchesMimeType, dereferenceRef };\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,iBAAiBA,QAAiB,WAA4B;AACrE,SAAOA,OAAM,KAAK,UAAQ;AACxB,WAAO,UAAU,QAAQ,IAAI,IAAI;AAAA,EACnC,CAAC;AACH;AAGA,IAAO,2BAAQ;AAAA,EACb,gBAAgB,CAAC,aAA8B;AAC7C,WAAO,iBAAiB,CAAC,mCAAmC,GAAG,QAAQ;AAAA,EACzE;AAAA,EAEA,MAAM,CAAC,gBAAiC;AACtC,WAAO;AAAA,MACL,CAAC,oBAAoB,sBAAsB,aAAa,eAAe,OAAO;AAAA,MAC9E;AAAA,IACF;AAAA,EACF;AAAA,EAEA,WAAW,CAAC,gBAAiC;AAC3C,WAAO;AAAA,MACL,CAAC,mBAAmB,qBAAqB,uBAAuB,uBAAuB;AAAA,MACvF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,UAAU,CAAC,gBAAiC;AAC1C,WAAO,gBAAgB;AAAA,EACzB;AAAA,EAEA,KAAK,CAAC,gBAAiC;AACrC,WAAO;AAAA,MACL;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;;;AC5BO,SAAS,wBAAwB,aA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AAQ;AAC5D,cAAI,MAAM,QAAQ,EAAG,QAAO;AAC5B,gBAAM,YAAY,aAAa,gBAAgB,QAAQ,GAAmB;AAAA,YACxE,GAAG;AAAA,YACH;AAAA,YACA;AAAA,UACF,CAAC;AAED,sBAAY,IAAI,KAAK,SAAS;AAC9B,iBAAO;AAAA,QACT,QAAQ;AACN,iBAAO;AAAA,QACT;AAAA,MACF,CAAC;AAED,YAAM,cAAc,YAAY,IAAI,MAAM,IAAI,KAAK,oBAAI,IAAI;AAC3D,YAAM,oBAAoB,+BAA+B,aAAa,WAAW;AAEjF,UAAI,kBAAkB,OAAO,GAAG;AAC9B,uCAA+B,MAAM,QAAQ,iBAAiB;AAAA,MAChE;AAAA,IACF;AAEA,WAAO;AAAA,EACT,CAAC,EACA,KAAK,CAAC,GAAG,MAAM;AACd,WAAO,SAAS,QAAQ,EAAE,IAAI,IAAI,SAAS,QAAQ,EAAE,IAAI;AAAA,EAC3D,CAAC;AACL;;;ACtVO,IAAM,mBAAmB,CAAC,OAAO,OAAO,QAAQ,UAAU,WAAW,QAAQ,SAAS,OAAO;AAE7F,IAAM,wBAAgC;","names":["types","jsonpointer","converted","jsonpointer","schema"]}
@@ -1,14 +1,14 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
2
2
 
3
3
 
4
- var _chunkNG4A45EEcjs = require('./chunk-NG4A45EE.cjs');
4
+ var _chunkEYI3QYOGcjs = require('./chunk-EYI3QYOG.cjs');
5
5
 
6
6
 
7
7
 
8
8
 
9
9
 
10
10
 
11
- var _chunkKZCEPS4Jcjs = require('./chunk-KZCEPS4J.cjs');
11
+ var _chunkHTEFBV7Kcjs = require('./chunk-HTEFBV7K.cjs');
12
12
 
13
13
 
14
14
 
@@ -61,7 +61,7 @@ function getByScheme(user, scheme = {}, selectedApp) {
61
61
  }
62
62
  function getAuth(api, user, selectedApp) {
63
63
  return Object.keys(_optionalChain([api, 'optionalAccess', _3 => _3.components, 'optionalAccess', _4 => _4.securitySchemes]) || {}).map((scheme) => {
64
- const securityScheme = _chunkKZCEPS4Jcjs.dereferenceRef.call(void 0, _optionalChain([api, 'access', _5 => _5.components, 'optionalAccess', _6 => _6.securitySchemes, 'optionalAccess', _7 => _7[scheme]]), api);
64
+ const securityScheme = _chunkHTEFBV7Kcjs.dereferenceRef.call(void 0, _optionalChain([api, 'access', _5 => _5.components, 'optionalAccess', _6 => _6.securitySchemes, 'optionalAccess', _7 => _7[scheme]]), api);
65
65
  if (!securityScheme || _chunkYPR7YTHMcjs.isRef.call(void 0, securityScheme)) {
66
66
  return false;
67
67
  }
@@ -126,7 +126,7 @@ function normalizedURL(api, selected) {
126
126
  return ensureProtocol(url);
127
127
  }
128
128
  function transformURLIntoRegex(url) {
129
- return stripTrailingSlash(url.replace(_chunkKZCEPS4Jcjs.SERVER_VARIABLE_REGEX, "([-_a-zA-Z0-9:.[\\]]+)"));
129
+ return stripTrailingSlash(url.replace(_chunkHTEFBV7Kcjs.SERVER_VARIABLE_REGEX, "([-_a-zA-Z0-9:.[\\]]+)"));
130
130
  }
131
131
  function normalizePath(path) {
132
132
  return path.replace(/({?){(.*?)}(}?)/g, (str, ...args) => {
@@ -331,7 +331,7 @@ var Oas = (_class = class _Oas {
331
331
  return false;
332
332
  }
333
333
  const variables = {};
334
- Array.from(server.url.matchAll(_chunkKZCEPS4Jcjs.SERVER_VARIABLE_REGEX)).forEach((variable, y) => {
334
+ Array.from(server.url.matchAll(_chunkHTEFBV7Kcjs.SERVER_VARIABLE_REGEX)).forEach((variable, y) => {
335
335
  variables[variable[1]] = found[y + 1];
336
336
  });
337
337
  return {
@@ -362,7 +362,7 @@ var Oas = (_class = class _Oas {
362
362
  */
363
363
  replaceUrl(url, variables = {}) {
364
364
  return stripTrailingSlash(
365
- url.replace(_chunkKZCEPS4Jcjs.SERVER_VARIABLE_REGEX, (original, key) => {
365
+ url.replace(_chunkHTEFBV7Kcjs.SERVER_VARIABLE_REGEX, (original, key) => {
366
366
  if (key in variables) {
367
367
  const data = variables[key];
368
368
  if (typeof data === "object") {
@@ -393,22 +393,22 @@ var Oas = (_class = class _Oas {
393
393
  };
394
394
  if (opts.isWebhook) {
395
395
  if (_chunkYPR7YTHMcjs.isOpenAPI31.call(void 0, this.api)) {
396
- const webhookPath = _chunkKZCEPS4Jcjs.dereferenceRef.call(void 0, _optionalChain([this, 'access', _19 => _19.api, 'optionalAccess', _20 => _20.webhooks, 'optionalAccess', _21 => _21[path]]), this.api);
396
+ const webhookPath = _chunkHTEFBV7Kcjs.dereferenceRef.call(void 0, _optionalChain([this, 'access', _19 => _19.api, 'optionalAccess', _20 => _20.webhooks, 'optionalAccess', _21 => _21[path]]), this.api);
397
397
  if (webhookPath && !_chunkYPR7YTHMcjs.isRef.call(void 0, webhookPath)) {
398
398
  if (_optionalChain([webhookPath, 'optionalAccess', _22 => _22[method]])) {
399
399
  operation = webhookPath[method];
400
- return new (0, _chunkNG4A45EEcjs.Webhook)(this, path, method, operation);
400
+ return new (0, _chunkEYI3QYOGcjs.Webhook)(this, path, method, operation);
401
401
  }
402
402
  }
403
403
  }
404
404
  }
405
405
  if (_optionalChain([this, 'optionalAccess', _23 => _23.api, 'optionalAccess', _24 => _24.paths, 'optionalAccess', _25 => _25[path]])) {
406
- const pathItem = _chunkKZCEPS4Jcjs.dereferenceRef.call(void 0, this.api.paths[path], this.api);
406
+ const pathItem = _chunkHTEFBV7Kcjs.dereferenceRef.call(void 0, this.api.paths[path], this.api);
407
407
  if (_optionalChain([pathItem, 'optionalAccess', _26 => _26[method]])) {
408
- operation = _chunkKZCEPS4Jcjs.dereferenceRef.call(void 0, pathItem[method], this.api);
408
+ operation = _chunkHTEFBV7Kcjs.dereferenceRef.call(void 0, pathItem[method], this.api);
409
409
  }
410
410
  }
411
- return new (0, _chunkNG4A45EEcjs.Operation)(this, path, method, operation);
411
+ return new (0, _chunkEYI3QYOGcjs.Operation)(this, path, method, operation);
412
412
  }
413
413
  findOperationMatches(url) {
414
414
  const { origin, hostname } = new URL(url);
@@ -576,7 +576,7 @@ var Oas = (_class = class _Oas {
576
576
  let scheme = _optionalChain([this, 'access', _34 => _34.api, 'optionalAccess', _35 => _35.components, 'optionalAccess', _36 => _36.securitySchemes, 'optionalAccess', _37 => _37[name]]);
577
577
  if (!scheme) return void 0;
578
578
  if (_chunkYPR7YTHMcjs.isRef.call(void 0, scheme)) {
579
- scheme = _chunkKZCEPS4Jcjs.dereferenceRef.call(void 0, scheme, this.api);
579
+ scheme = _chunkHTEFBV7Kcjs.dereferenceRef.call(void 0, scheme, this.api);
580
580
  if (!scheme || _chunkYPR7YTHMcjs.isRef.call(void 0, scheme)) return void 0;
581
581
  }
582
582
  return scheme;
@@ -602,14 +602,14 @@ var Oas = (_class = class _Oas {
602
602
  if (!pathItem) {
603
603
  return;
604
604
  } else if (_chunkYPR7YTHMcjs.isRef.call(void 0, pathItem)) {
605
- this.api.paths[path] = _chunkKZCEPS4Jcjs.dereferenceRef.call(void 0, pathItem, this.api);
605
+ this.api.paths[path] = _chunkHTEFBV7Kcjs.dereferenceRef.call(void 0, pathItem, this.api);
606
606
  pathItem = this.api.paths[path];
607
607
  if (!pathItem || _chunkYPR7YTHMcjs.isRef.call(void 0, pathItem)) {
608
608
  return;
609
609
  }
610
610
  }
611
611
  Object.keys(pathItem).forEach((method) => {
612
- if (!_chunkKZCEPS4Jcjs.supportedMethods.includes(method)) {
612
+ if (!_chunkHTEFBV7Kcjs.supportedMethods.includes(method)) {
613
613
  return;
614
614
  }
615
615
  paths[path][method] = this.operation(path, method);
@@ -631,10 +631,10 @@ var Oas = (_class = class _Oas {
631
631
  }
632
632
  Object.keys(this.api.webhooks).forEach((id) => {
633
633
  webhooks[id] = {};
634
- const webhookPath = _chunkKZCEPS4Jcjs.dereferenceRef.call(void 0, _optionalChain([this, 'access', _38 => _38.api, 'access', _39 => _39.webhooks, 'optionalAccess', _40 => _40[id]]), this.api);
634
+ const webhookPath = _chunkHTEFBV7Kcjs.dereferenceRef.call(void 0, _optionalChain([this, 'access', _38 => _38.api, 'access', _39 => _39.webhooks, 'optionalAccess', _40 => _40[id]]), this.api);
635
635
  if (webhookPath) {
636
636
  Object.keys(webhookPath).forEach((method) => {
637
- if (!_chunkKZCEPS4Jcjs.supportedMethods.includes(method)) {
637
+ if (!_chunkHTEFBV7Kcjs.supportedMethods.includes(method)) {
638
638
  return;
639
639
  }
640
640
  webhooks[id][method] = this.operation(id, method, {
@@ -804,12 +804,12 @@ var Oas = (_class = class _Oas {
804
804
  }
805
805
  this.dereferencing.processing = true;
806
806
  if (!this.schemasDecorated) {
807
- _chunkKZCEPS4Jcjs.decorateComponentSchemasWithRefName.call(void 0, this.api);
807
+ _chunkHTEFBV7Kcjs.decorateComponentSchemasWithRefName.call(void 0, this.api);
808
808
  this.schemasDecorated = true;
809
809
  }
810
810
  const { api, promises } = this;
811
811
  const circularRefs = /* @__PURE__ */ new Set();
812
- const dereferencingOptions = _chunkKZCEPS4Jcjs.getDereferencingOptions.call(void 0, circularRefs);
812
+ const dereferencingOptions = _chunkHTEFBV7Kcjs.getDereferencingOptions.call(void 0, circularRefs);
813
813
  return _openapiparser.dereference.call(void 0, api, dereferencingOptions).then((dereferenced) => {
814
814
  this.api = dereferenced;
815
815
  this.promises = promises;
@@ -856,4 +856,4 @@ var Oas = (_class = class _Oas {
856
856
 
857
857
 
858
858
  exports.Oas = Oas;
859
- //# sourceMappingURL=chunk-Q6ABRA4U.cjs.map
859
+ //# sourceMappingURL=chunk-DKPOVGFI.cjs.map