oas 32.1.10 → 32.1.13

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.
Files changed (39) hide show
  1. package/dist/analyzer/index.cjs +6 -6
  2. package/dist/analyzer/index.js +4 -4
  3. package/dist/{chunk-WXXVCSCN.js → chunk-2EISA7HB.js} +5 -5
  4. package/dist/chunk-2EISA7HB.js.map +1 -0
  5. package/dist/{chunk-YPR7YTHM.cjs → chunk-3MTU2ESP.cjs} +1 -1
  6. package/dist/{chunk-YPR7YTHM.cjs.map → chunk-3MTU2ESP.cjs.map} +1 -1
  7. package/dist/{chunk-EYI3QYOG.cjs → chunk-7BWVOLZR.cjs} +211 -198
  8. package/dist/chunk-7BWVOLZR.cjs.map +1 -0
  9. package/dist/{chunk-DKPOVGFI.cjs → chunk-BJEFIYTO.cjs} +29 -29
  10. package/dist/chunk-BJEFIYTO.cjs.map +1 -0
  11. package/dist/{chunk-2TQO63CW.js → chunk-GIFUTDD5.js} +53 -40
  12. package/dist/chunk-GIFUTDD5.js.map +1 -0
  13. package/dist/{chunk-7BC6KXMO.js → chunk-K5WNB3M7.js} +133 -49
  14. package/dist/chunk-K5WNB3M7.js.map +1 -0
  15. package/dist/{chunk-MNOEMVCF.js → chunk-PSNTODZL.js} +1 -1
  16. package/dist/{chunk-MNOEMVCF.js.map → chunk-PSNTODZL.js.map} +1 -1
  17. package/dist/{chunk-HTEFBV7K.cjs → chunk-SAB2PGCD.cjs} +158 -74
  18. package/dist/chunk-SAB2PGCD.cjs.map +1 -0
  19. package/dist/index.cjs +5 -5
  20. package/dist/index.js +4 -4
  21. package/dist/operation/index.cjs +4 -4
  22. package/dist/operation/index.js +3 -3
  23. package/dist/reducer/index.cjs +49 -28
  24. package/dist/reducer/index.cjs.map +1 -1
  25. package/dist/reducer/index.js +23 -2
  26. package/dist/reducer/index.js.map +1 -1
  27. package/dist/types.cjs +2 -2
  28. package/dist/types.d.cts +3 -0
  29. package/dist/types.d.ts +3 -0
  30. package/dist/types.js +1 -1
  31. package/dist/utils.cjs +3 -3
  32. package/dist/utils.js +2 -2
  33. package/package.json +6 -8
  34. package/dist/chunk-2TQO63CW.js.map +0 -1
  35. package/dist/chunk-7BC6KXMO.js.map +0 -1
  36. package/dist/chunk-DKPOVGFI.cjs.map +0 -1
  37. package/dist/chunk-EYI3QYOG.cjs.map +0 -1
  38. package/dist/chunk-HTEFBV7K.cjs.map +0 -1
  39. package/dist/chunk-WXXVCSCN.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas/dist/chunk-EYI3QYOG.cjs","../src/operation/index.ts","../src/operation/lib/dedupe-common-parameters.ts","../src/samples/index.ts","../src/samples/utils.ts","../src/operation/lib/get-mediatype-examples.ts","../src/operation/lib/get-response-examples.ts","../src/operation/lib/get-callback-examples.ts","../src/operation/lib/get-example-groups.ts","../src/operation/lib/get-requestbody-examples.ts","../src/operation/lib/operationId.ts","../src/operation/transformers/get-response-as-json-schema.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACMA,0EAA2B;ADJ3B;AACA;AEfO,SAAS,sBAAA,CACd,UAAA,EACA,gBAAA,EACmB;AACnB,EAAA,OAAO,gBAAA,CAAiB,MAAA,CAAO,CAAC,KAAA,EAAA,GAA2B;AACzD,IAAA,OAAO,CAAC,UAAA,CAAW,IAAA,CAAK,CAAC,MAAA,EAAA,GAA4B;AACnD,MAAA,GAAA,CAAI,KAAA,CAAM,KAAA,GAAQ,MAAA,CAAO,IAAA,EAAM;AAC7B,QAAA,OAAO,KAAA,CAAM,KAAA,IAAS,MAAA,CAAO,KAAA,GAAQ,KAAA,CAAM,GAAA,IAAO,MAAA,CAAO,EAAA;AAAA,MAC3D,EAAA,KAAA,GA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,IAAA;AACZ,MAAA;AACT,IAAA;AAEkB,IAAA;AACG,IAAA;AACD,MAAA;AACC,MAAA;AACrB,IAAA;AAEoB,IAAA;AACtB,EAAA;AACF;ADoZyB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/erunion/code/readme/oas/packages/oas/dist/chunk-EYI3QYOG.cjs","sourcesContent":[null,"import type { Extensions } from '../extensions.js';\nimport type Oas from '../index.js';\nimport type {\n HttpMethods,\n JSONSchema,\n KeyedSecuritySchemeObject,\n MediaTypeObject,\n OAS31Document,\n OASDocument,\n OperationObject,\n ParameterObject,\n PathItemObject,\n ReferenceObject,\n RequestBodyObject,\n ResponseObject,\n SchemaWrapper,\n SecurityRequirementObject,\n SecuritySchemeObject,\n SecurityType,\n TagObject,\n} from '../types.js';\nimport type { CallbackExample } from './lib/get-callback-examples.js';\nimport type { ExampleGroups } from './lib/get-example-groups.js';\nimport type { RequestBodyExample } from './lib/get-requestbody-examples.js';\nimport type { ResponseExample } from './lib/get-response-examples.js';\nimport type { OperationIDGeneratorOptions } from './lib/operationId.js';\nimport type { getParametersAsJSONSchemaOptions } from './transformers/get-parameters-as-json-schema.js';\nimport type { ResponseSchemaObject } from './transformers/get-response-as-json-schema.js';\n\nimport { $RefParser } from '@apidevtools/json-schema-ref-parser';\n\nimport matchesMimeType from '../lib/matches-mimetype.js';\nimport { decorateComponentSchemasWithRefName, dereferenceRef, getDereferencingOptions } from '../lib/refs.js';\nimport { isRef } from '../types.js';\nimport { supportedMethods } from '../utils.js';\nimport { dedupeCommonParameters } from './lib/dedupe-common-parameters.js';\nimport { getCallbackExamples } from './lib/get-callback-examples.js';\nimport { getExampleGroups } from './lib/get-example-groups.js';\nimport { getRequestBodyExamples } from './lib/get-requestbody-examples.js';\nimport { getResponseExamples } from './lib/get-response-examples.js';\nimport { getOperationId, hasOperationId } from './lib/operationId.js';\nimport { getParametersAsJSONSchema } from './transformers/get-parameters-as-json-schema.js';\nimport { getResponseAsJSONSchema } from './transformers/get-response-as-json-schema.js';\n\nexport class Operation {\n /**\n * The `Oas` instance that this operation belongs to.\n */\n oas: Oas;\n\n /**\n * Schema of the operation from the API Definition.\n */\n schema: OperationObject;\n\n /**\n * OpenAPI API Definition that this operation originated from.\n */\n api: OASDocument;\n\n /**\n * Path that this operation is targeted towards.\n */\n path: string;\n\n /**\n * HTTP Method that this operation is targeted towards.\n */\n method: HttpMethods;\n\n /**\n * The primary Content Type that this operation accepts.\n */\n contentType: string | undefined;\n\n /**\n * An object with groups of all example definitions (body/header/query/path/response/etc.)\n */\n exampleGroups: ExampleGroups | undefined;\n\n /**\n * Request body examples for this operation.\n */\n requestBodyExamples: RequestBodyExample[] | undefined;\n\n /**\n * Response examples for this operation.\n */\n responseExamples: ResponseExample[] | undefined;\n\n /**\n * Callback examples for this operation (if it has callbacks).\n */\n callbackExamples: CallbackExample[] | undefined;\n\n /**\n * Flattened out arrays of both request and response headers that are utilized on this operation.\n */\n headers: {\n request: string[];\n response: string[];\n };\n\n /**\n * Internal storage array that the library utilizes to keep track of the times the\n * {@see Operation.dereference} has been called so that if you initiate multiple promises they'll\n * all end up returning the same data set once the initial dereference call completed.\n */\n protected promises: {\n reject: any;\n resolve: any;\n }[];\n\n /**\n * Internal storage array that the library utilizes to keep track of its `dereferencing` state so\n * it doesn't initiate multiple dereferencing processes.\n */\n protected dereferencing: {\n circularRefs: string[];\n complete: boolean;\n processing: boolean;\n };\n\n /**\n * Have the component schemas within this API definition been decorated with our\n * `x-readme-ref-name` extension?\n *\n * @see {@link decorateComponentSchemas}\n */\n protected schemasDecorated: boolean = false;\n\n constructor(oas: Oas, path: string, method: HttpMethods, operation: OperationObject) {\n this.oas = oas;\n this.schema = operation;\n this.api = oas.api;\n this.path = path;\n this.method = method;\n\n this.contentType = undefined;\n this.requestBodyExamples = undefined;\n this.responseExamples = undefined;\n this.callbackExamples = undefined;\n this.exampleGroups = undefined;\n this.headers = {\n request: [],\n response: [],\n };\n\n this.promises = [];\n this.dereferencing = {\n processing: false,\n complete: false,\n circularRefs: [],\n };\n }\n\n /**\n * Retrieve the `summary` for this operation.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-operationsummary}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-operation-summary}\n */\n getSummary(): string | undefined {\n if (this.schema?.summary && typeof this.schema.summary === 'string') {\n return this.schema.summary;\n }\n\n const pathItem = this.api.paths?.[this.path];\n if (pathItem?.summary && typeof pathItem.summary === 'string') {\n return pathItem.summary;\n }\n\n return undefined;\n }\n\n /**\n * Retrieve the `description` for this operation.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-operationdescription}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-operation-description}\n */\n getDescription(): string | undefined {\n if (this.schema?.description && typeof this.schema.description === 'string') {\n return this.schema.description;\n }\n\n const pathItem = this.api.paths?.[this.path];\n if (pathItem?.description && typeof pathItem.description === 'string') {\n return pathItem.description;\n }\n\n return undefined;\n }\n\n /**\n * Retrieve the primary content type for this operation. If multiple exist, the first JSON-like\n * type will be returned.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-requestbodycontent}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-request-body-content}\n */\n getContentType(): string {\n if (this.contentType) {\n return this.contentType;\n }\n\n let types: string[] = [];\n if (this.schema.requestBody) {\n if (isRef(this.schema.requestBody)) {\n this.schema.requestBody = dereferenceRef(this.schema.requestBody, this.api);\n }\n\n if (this.schema.requestBody && 'content' in this.schema.requestBody) {\n types = Object.keys(this.schema.requestBody.content);\n }\n }\n\n this.contentType = 'application/json';\n if (types?.length) {\n this.contentType = types[0];\n }\n\n // Favor JSON if it exists\n types.forEach(t => {\n if (matchesMimeType.json(t)) {\n this.contentType = t;\n }\n });\n\n return this.contentType;\n }\n\n /**\n * Checks if the current operation has a `x-www-form-urlencoded` content type payload.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-requestbodycontent}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-request-body-content}\n */\n isFormUrlEncoded(): boolean {\n return matchesMimeType.formUrlEncoded(this.getContentType());\n }\n\n /**\n * Checks if the current operation has a mutipart content type payload.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-requestbodycontent}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-request-body-content}\n */\n isMultipart(): boolean {\n return matchesMimeType.multipart(this.getContentType());\n }\n\n /**\n * Checks if the current operation has a JSON-like content type payload.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-requestbodycontent}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-request-body-content}\n */\n isJson(): boolean {\n return matchesMimeType.json(this.getContentType());\n }\n\n /**\n * Checks if the current operation has an XML content type payload.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-requestbodycontent}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-request-body-content}\n */\n isXml(): boolean {\n return matchesMimeType.xml(this.getContentType());\n }\n\n /**\n * Checks if the current operation is a webhook or not.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#oas-webhooks}\n */\n isWebhook(): boolean {\n return this instanceof Webhook;\n }\n\n /**\n * Returns an array of all security requirements associated wtih this operation. If none are\n * defined at the operation level, the securities for the entire API definition are returned\n * (with an empty array as a final fallback).\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#security-requirement-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#security-requirement-object}\n */\n getSecurity(): SecurityRequirementObject[] {\n // If this definition doesn't have any security schemes defined then regardless if there are\n // `security` requirements defined anywhere we should return an empty array because they're all\n // invalid an unusable without the accompanying schemes.\n if (!this.api?.components?.securitySchemes || !Object.keys(this.api.components.securitySchemes).length) {\n return [];\n }\n\n return this.schema.security || this.api.security || [];\n }\n\n /**\n * Retrieve a collection of grouped security schemes. The inner array determines AND-grouped\n * security schemes, the outer array determines OR-groups.\n *\n * @see {@link https://swagger.io/docs/specification/authentication/#multiple}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#security-requirement-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#security-requirement-object}\n * @param filterInvalid Optional flag that, when set to `true`, filters out invalid/nonexistent\n * security schemes, rather than returning `false`.\n */\n getSecurityWithTypes(\n filterInvalid = false,\n ): ((false | { security: KeyedSecuritySchemeObject; type: SecurityType })[] | false)[] {\n return this.getSecurity().map(requirement => {\n let keys: string[];\n try {\n keys = Object.keys(requirement);\n } catch {\n return false;\n }\n\n const keysWithTypes = keys.map(key => {\n let security: SecuritySchemeObject | ReferenceObject | undefined;\n try {\n security = this.api?.components?.securitySchemes?.[key];\n if (!security) return false;\n if (isRef(security)) {\n security = dereferenceRef(security, this.api);\n if (!security || isRef(security)) return false;\n }\n } catch {\n return false;\n }\n\n if (!security || isRef(security)) return false;\n\n let type: SecurityType | null = null;\n\n if (security.type === 'http') {\n if (security.scheme === 'basic') type = 'Basic';\n else if (security.scheme === 'bearer') type = 'Bearer';\n else type = security.type;\n } else if (security.type === 'oauth2') {\n type = 'OAuth2';\n } else if (security.type === 'apiKey') {\n if (security.in === 'query') type = 'Query';\n else if (security.in === 'header') type = 'Header';\n else if (security.in === 'cookie') type = 'Cookie';\n else type = security.type;\n } else {\n return false;\n }\n\n return {\n type,\n security: {\n ...security,\n _key: key,\n _requirements: requirement[key],\n },\n };\n });\n\n if (filterInvalid) return keysWithTypes.filter(key => key !== false);\n\n return keysWithTypes;\n });\n }\n\n /**\n * Retrieve an object where the keys are unique scheme types, and the values are arrays\n * containing each security scheme of that type.\n *\n */\n prepareSecurity(): Record<SecurityType, KeyedSecuritySchemeObject[]> {\n return this.getSecurityWithTypes().reduce(\n (prev, securities) => {\n if (!securities) return prev;\n\n securities.forEach(security => {\n // Remove non-existent schemes\n if (!security) return;\n if (!prev[security.type]) prev[security.type] = [];\n\n // Only add schemes we haven't seen yet.\n const exists = prev[security.type].some(sec => sec._key === security.security._key);\n if (!exists) {\n // Since an operation can require the same security scheme several times (each with\n // different scope requirements), including the `_requirements` in this object would be\n // misleading since we dedupe the security schemes.\n if (security.security?._requirements) delete security.security._requirements;\n prev[security.type].push(security.security);\n }\n });\n\n return prev;\n },\n {} as Record<SecurityType, KeyedSecuritySchemeObject[]>,\n );\n }\n\n /**\n * Retrieve all of the headers, request and response, that are associated with this operation.\n *\n */\n getHeaders(): Operation['headers'] {\n const security = this.prepareSecurity();\n if (security.Header) {\n this.headers.request = security.Header.map((h: KeyedSecuritySchemeObject) => {\n // Only `apiKey` security schemes contain headers.\n if (!('name' in h)) return false;\n return h.name;\n }).filter((item): item is string => item !== false);\n }\n\n if (security.Bearer || security.Basic || security.OAuth2) {\n this.headers.request.push('Authorization');\n }\n\n if (security.Cookie) {\n this.headers.request.push('Cookie');\n }\n\n if (this.schema.parameters) {\n this.headers.request = this.headers.request.concat(\n this.schema.parameters\n .map(p => {\n let param = p;\n if (isRef(param)) {\n param = dereferenceRef(param, this.api);\n if (!param || isRef(param)) return undefined;\n }\n\n if (param.in && param.in === 'header') return param.name;\n return undefined;\n })\n .filter((item): item is string => item !== undefined),\n );\n }\n\n if (this.schema.responses) {\n this.headers.response = Object.keys(this.schema.responses)\n .map(r => {\n // biome-ignore-start lint/style/noNonNullAssertion: `schema.responses` is guaranteed here.\n let response = this.schema.responses![r];\n if (!response) return [];\n if (isRef(response)) {\n this.schema.responses![r] = dereferenceRef(response, this.api);\n response = this.schema.responses![r];\n if (!response || isRef(response)) {\n return [];\n }\n }\n // biome-ignore-end lint/style/noNonNullAssertion: --end--\n\n return response?.headers ? Object.keys(response.headers) : [];\n })\n .reduce((a, b) => a.concat(b), []);\n }\n\n // If the operation doesn't already specify a `content-type` request header, we check if the\n // path operation request body contains content, which implies that we should also include the\n // `content-type` header.\n if (!this.headers.request.includes('Content-Type') && this.schema.requestBody) {\n let requestBody = this.schema.requestBody;\n if (requestBody) {\n if (isRef(requestBody)) {\n this.schema.requestBody = dereferenceRef(requestBody, this.api);\n requestBody = this.schema.requestBody;\n }\n\n if (requestBody && !isRef(requestBody) && 'content' in requestBody && Object.keys(requestBody.content)) {\n this.headers.request.push('Content-Type');\n }\n }\n }\n\n // This is a similar approach, but in this case if we check the response content and prioritize\n // the `accept` request header and `content-type` request header.\n if (this.schema.responses) {\n const hasResponseContent = Object.keys(this.schema.responses).some(r => {\n let response = this.schema.responses?.[r];\n if (!response) return false;\n if (isRef(response)) {\n // biome-ignore-start lint/style/noNonNullAssertion: `schema.responses` is guaranteed here.\n this.schema.responses![r] = dereferenceRef(response, this.api);\n response = this.schema.responses![r];\n if (!response || isRef(response)) {\n return false;\n }\n // biome-ignore-end lint/style/noNonNullAssertion: --end--\n }\n\n return response.content && Object.keys(response.content).length > 0;\n });\n\n if (hasResponseContent) {\n if (!this.headers.request.includes('Accept')) this.headers.request.push('Accept');\n if (!this.headers.response.includes('Content-Type')) this.headers.response.push('Content-Type');\n }\n }\n\n return this.headers;\n }\n\n /**\n * Determine if this operation has an `operationId` present in its schema. Note that if one is\n * present in the schema but is an empty string then this will return `false`.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-operationid}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-operation-id}\n */\n hasOperationId(): boolean {\n return hasOperationId(this.schema);\n }\n\n /**\n * Determine if an operation has an `operationId` present in its schema. Note that if one is\n * present in the schema but is an empty string then this will return `false`.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-operationid}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-operation-id}\n */\n static hasOperationId(schema: OperationObject): boolean {\n return hasOperationId(schema);\n }\n\n /**\n * Get an `operationId` for this operation. If one is not present (it's not required by the spec!)\n * a hash of the path and method will be returned instead.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-operationid}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-operation-id}\n */\n getOperationId(opts: OperationIDGeneratorOptions = {}): string {\n return getOperationId(this.path, this.method, this.schema, opts);\n }\n\n /**\n * Get an `operationId` for an operation. If one is not present (it's not required by the spec!)\n * a hash of the path and method will be returned instead.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-operationid}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-operation-id}\n */\n static getOperationId(\n path: string,\n method: string,\n schema: OperationObject,\n opts: OperationIDGeneratorOptions = {},\n ): string {\n return getOperationId(path, method, schema, opts);\n }\n\n /**\n * Return an array of all tags, and their metadata, that exist on this operation.\n *\n */\n getTags(): TagObject[] {\n if (!('tags' in this.schema)) {\n return [];\n }\n\n const oasTagMap: Map<string, TagObject> = new Map();\n if (Array.isArray(this.api?.tags)) {\n this.api.tags.forEach(tag => {\n oasTagMap.set(tag.name, tag);\n });\n }\n\n const oasTags = Object.fromEntries(oasTagMap);\n\n const tags: TagObject[] = [];\n if (Array.isArray(this.schema.tags)) {\n this.schema.tags.forEach(tag => {\n if (tag in oasTags) {\n tags.push(oasTags[tag]);\n } else {\n tags.push({\n name: tag,\n });\n }\n });\n }\n\n return tags;\n }\n\n /**\n * Return is the operation is flagged as `deprecated` or not.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-operationdeprecated}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-operation-deprecated}\n */\n isDeprecated(): boolean {\n return Boolean('deprecated' in this.schema ? this.schema.deprecated : false);\n }\n\n /**\n * Determine if the operation has any (non-request body) parameters.\n *\n */\n hasParameters(): boolean {\n return !!this.getParameters().length;\n }\n\n /**\n * Return the parameters (non-request body) on the operation.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-operationparameters}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-operation-parameters}\n */\n getParameters(): ParameterObject[] {\n let parameters = (this.schema?.parameters || [])\n .map(p => {\n let param = p;\n if (isRef(param)) {\n param = dereferenceRef(param, this.api);\n if (!param || isRef(param)) return undefined;\n }\n\n return param;\n })\n .filter((param): param is ParameterObject => param !== undefined);\n\n const commonParams = (this.api?.paths?.[this.path]?.parameters || [])\n .map(p => {\n let param = p;\n if (isRef(param)) {\n param = dereferenceRef(param, this.api);\n if (!param || isRef(param)) return undefined;\n }\n\n return param;\n })\n .filter((param): param is ParameterObject => param !== undefined);\n\n if (commonParams.length) {\n parameters = parameters.concat(dedupeCommonParameters(parameters, commonParams) || []);\n }\n\n return parameters;\n }\n\n /**\n * Determine if this operation has any required parameters.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-operationparameters}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-operation-parameters}\n */\n hasRequiredParameters(): boolean {\n return this.getParameters().some(param => 'required' in param && param.required);\n }\n\n /**\n * Convert the operation into an array of JSON Schema schemas for each available type of\n * parameter available on the operation.\n *\n * Note that this method is not compatible with an operation or OpenAPI definition that has been\n * processed with `.dereference()`. This method can only be called with the _original_ API\n * definition that was used to initialize the `Operation` and `Oas` instance. If a dereferenced\n * schema is present when this is called a `TypeError` will be thrown.\n *\n * @throws {TypeError} If the operation or OpenAPI definition has been run through `.dereference().`\n *\n */\n getParametersAsJSONSchema(opts: getParametersAsJSONSchemaOptions = {}): SchemaWrapper[] | null {\n if (this.isDereferenced()) {\n throw new Error(\n '`.getParametersAsJSONSchema()` is not compatible with an operation or OpenAPI definition that has been run through `.dereference().`',\n );\n }\n\n // Because some downstream tooling that use these JSON Schema objects may need to know original\n // schema names, like in some cases of discriminator mappings in our ReadMe API Explorer, we\n // need to decorate our component schemas with a `x-readme-ref-name` property with that original\n // schema name.\n //\n // This work happens automatically during our `.dereference()` process but because we do not\n // allow dereferencing to be used with this method we need to do this ourselves.\n if (!this.schemasDecorated) {\n decorateComponentSchemasWithRefName(this.api);\n this.schemasDecorated = true;\n }\n\n return getParametersAsJSONSchema(this, this.api, {\n includeDiscriminatorMappingRefs: true,\n ...opts,\n });\n }\n\n /**\n * Get a single response for this status code, formatted as JSON schema.\n *\n * Note that this method is not compatible with an operation or OpenAPI definition that has been\n * processed with `.dereference()`. This method can only be called with the _original_ API\n * definition that was used to initialize the `Operation` and `Oas` instance. If a dereferenced\n * schema is present when this is called a `TypeError` will be thrown.\n *\n * @param statusCode Status code to pull a JSON Schema response for.\n * @param opts Options for schema generation.\n * @param opts.contentType Optional content-type to use. If specified and the response doesn't have\n * this content-type, the function will return null.\n */\n getResponseAsJSONSchema(\n statusCode: number | string,\n opts: {\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 * Optional content-type to use. If specified and the response doesn't have this content-type,\n * the function will return null.\n */\n contentType?: string;\n } = {},\n ): ResponseSchemaObject[] | null {\n if (this.isDereferenced()) {\n throw new Error(\n '`.getResponseAsJSONSchema()` is not compatible with an operation or OpenAPI definition that has been run through `.dereference().`',\n );\n }\n\n // Because some downstream tooling that use these JSON Schema objects may need to know original\n // schema names, like in some cases of discriminator mappings in our ReadMe API Explorer, we\n // need to decorate our component schemas with a `x-readme-ref-name` property with that original\n // schema name.\n //\n // This work happens automatically during our `.dereference()` process but because we do not\n // allow dereferencing to be used with this method we need to do this ourselves.\n if (!this.schemasDecorated) {\n decorateComponentSchemasWithRefName(this.api);\n this.schemasDecorated = true;\n }\n\n return getResponseAsJSONSchema(this, this.api, statusCode, {\n includeDiscriminatorMappingRefs: true,\n ...opts,\n });\n }\n\n /**\n * Get an array of all valid response status codes for this operation.\n *\n */\n getResponseStatusCodes(): string[] {\n if (!this.schema.responses) return [];\n\n if (isRef(this.schema.responses)) {\n this.schema.responses = dereferenceRef(this.schema.responses, this.api);\n if (!this.schema.responses || isRef(this.schema.responses)) {\n return [];\n }\n }\n\n return Object.keys(this.schema.responses).filter(key => {\n // `x-` extensions aren't valid HTTP status codes so we shouldn't return them as one.\n if (key.startsWith('x-')) {\n return false;\n }\n\n const response = this.schema.responses?.[key];\n return response && typeof response === 'object';\n });\n }\n\n /**\n * Retrieve an array of all content types that this operation can return.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#response-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#response-object}\n */\n getResponseContentTypes(): string[] {\n if (!this.schema.responses) return [];\n\n const contentTypes = new Set<string>();\n Object.values(this.schema.responses).forEach((response: ReferenceObject | ResponseObject) => {\n let resp = response;\n if (!resp) return;\n if (isRef(resp)) {\n resp = dereferenceRef(resp, this.api);\n\n // If this response still can't be resolved then we shouldn't return anything because it's\n // either an invalid schema or a circular reference.\n if (!resp || isRef(resp)) {\n return;\n }\n }\n\n Object.keys(resp.content || {}).forEach(mimeType => {\n contentTypes.add(mimeType);\n });\n });\n\n return Array.from(contentTypes);\n }\n\n /**\n * Determine if the operation has any request bodies.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-operationrequestbody}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-operation-request-body}\n */\n hasRequestBody(): boolean {\n return !!this.schema.requestBody;\n }\n\n /**\n * Return the current `requestBody` object, dereferencing it in the process if it's a `$ref`\n * pointer.\n *\n */\n private getResolvedRequestBody(): RequestBodyObject | false {\n let requestBody = this.schema.requestBody;\n if (!requestBody) return false;\n if (isRef(requestBody)) {\n this.schema.requestBody = dereferenceRef(requestBody, this.api);\n requestBody = this.schema.requestBody;\n if (!requestBody || isRef(requestBody)) {\n return false;\n }\n }\n\n return requestBody;\n }\n\n /**\n * Retrieve the list of all available media types that the operations request body can accept.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#media-type-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n */\n getRequestBodyMediaTypes(): string[] {\n if (!this.hasRequestBody()) {\n return [];\n }\n\n const requestBody = this.getResolvedRequestBody();\n if (!requestBody) return [];\n\n return Object.keys(requestBody.content);\n }\n\n /**\n * Determine if this operation has a required request body.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#media-type-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n */\n hasRequiredRequestBody(): boolean {\n if (!this.hasRequestBody()) {\n return false;\n }\n\n const requestBody = this.getResolvedRequestBody();\n if (!requestBody) return false;\n\n if (requestBody.required) {\n return true;\n }\n\n // The OpenAPI spec isn't clear on the differentiation between schema `required` and\n // `requestBody.required` because you can have required top-level schema properties but a\n // non-required requestBody that negates each other.\n //\n // To kind of work ourselves around this and present a better QOL for this accessor, if at this\n // final point where we don't have a required request body, but the underlying Media Type Object\n // schema says that it has required properties then we should ultimately recognize that this\n // request body is required -- even as the request body description says otherwise.\n const parameters = this.getParametersAsJSONSchema();\n if (parameters === null) {\n return false;\n }\n\n return !!parameters\n .filter(js => ['body', 'formData'].includes(js.type))\n .find(js => js.schema && Array.isArray(js.schema.required) && js.schema.required.length);\n }\n\n /**\n * Retrieve a specific request body content schema off this operation.\n *\n * If no media type is supplied this will return either the first available JSON-like request\n * body, or the first available if there are no JSON-like media types present. When this return\n * comes back it's in the form of an array with the first key being the selected media type,\n * followed by the media type object in question.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#media-type-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n * @param mediaType Specific request body media type to retrieve if present.\n */\n getRequestBody(mediaType?: string): MediaTypeObject | false | [string, MediaTypeObject, ...string[]] {\n if (!this.hasRequestBody()) {\n return false;\n }\n\n const requestBody = this.getResolvedRequestBody();\n if (!requestBody) return false;\n\n if (mediaType) {\n if (!(mediaType in requestBody.content)) {\n return false;\n }\n\n return requestBody.content[mediaType];\n }\n\n // Since no media type was supplied we need to find either the first JSON-like media type that\n // we've got, or the first available of anything else if no JSON-like media types are present.\n let availableMediaType: string | undefined;\n const mediaTypes = this.getRequestBodyMediaTypes();\n mediaTypes.forEach((mt: string) => {\n if (!availableMediaType && matchesMimeType.json(mt)) {\n availableMediaType = mt;\n }\n });\n\n if (!availableMediaType) {\n mediaTypes.forEach((mt: string) => {\n if (!availableMediaType) {\n availableMediaType = mt;\n }\n });\n }\n\n if (availableMediaType) {\n return [\n availableMediaType,\n requestBody.content[availableMediaType],\n ...(requestBody.description ? [requestBody.description] : []),\n ];\n }\n\n return false;\n }\n\n /**\n * Retrieve an array of request body examples that this operation has.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#request-body-examples}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#request-body-examples}\n */\n getRequestBodyExamples(): RequestBodyExample[] {\n const isRequestExampleValueDefined = typeof this.requestBodyExamples?.[0]?.examples?.[0].value !== 'undefined';\n\n if (this.requestBodyExamples && isRequestExampleValueDefined) {\n return this.requestBodyExamples;\n }\n\n this.requestBodyExamples = getRequestBodyExamples(this.schema, this.api);\n return this.requestBodyExamples;\n }\n\n /**\n * Return a specific response out of the operation by a given HTTP status code.\n *\n * @param statusCode Status code to pull a response object for.\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#response-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#response-object}\n */\n getResponseByStatusCode(statusCode: number | string): ResponseObject | false {\n if (!this.schema.responses) {\n return false;\n }\n\n let response = this.schema.responses[statusCode];\n if (!response) return false;\n if (isRef(response)) {\n this.schema.responses[statusCode] = dereferenceRef(response, this.api);\n response = this.schema.responses[statusCode];\n if (!response || isRef(response)) {\n return false;\n }\n }\n\n return response;\n }\n\n /**\n * Retrieve an array of response examples that this operation has.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#response-object-examples}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#response-object-examples}\n */\n getResponseExamples(): ResponseExample[] {\n if (this.responseExamples) {\n return this.responseExamples;\n }\n\n this.responseExamples = getResponseExamples(this.schema, this.api);\n return this.responseExamples;\n }\n\n /**\n * Determine if the operation has callbacks.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callback-object}\n */\n hasCallbacks(): boolean {\n return Boolean(this.schema.callbacks);\n }\n\n /**\n * Retrieve a specific callback.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callback-object}\n * @param identifier Callback identifier to look for.\n * @param expression Callback expression to look for.\n * @param method HTTP Method on the callback to look for.\n */\n getCallback(identifier: string, expression: string, method: HttpMethods): Callback | false {\n if (!this.schema.callbacks) return false;\n\n let callbackObj = this.schema.callbacks[identifier];\n if (!callbackObj) return false;\n if (isRef(callbackObj)) {\n this.schema.callbacks[identifier] = dereferenceRef(callbackObj, this.api);\n callbackObj = this.schema.callbacks[identifier];\n if (!callbackObj || isRef(callbackObj)) {\n return false;\n }\n }\n\n let callback = callbackObj[expression];\n if (!callback) return false;\n if (isRef(callback)) {\n callbackObj[expression] = dereferenceRef(callback, this.api);\n callback = callbackObj[expression];\n if (!callback || isRef(callback)) {\n return false;\n }\n }\n\n if (!callback[method]) {\n return false;\n }\n\n return new Callback(this.oas, expression, method, callback[method], identifier, callback);\n }\n\n /**\n * Retrieve an array of operations created from each callback.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callback-object}\n */\n getCallbacks(): Callback[] {\n if (!this.hasCallbacks()) return [];\n\n const callbacks: Callback[] = [];\n // biome-ignore-start lint/style/noNonNullAssertion: `hasCallbacks()` has narrowed this for us.\n Object.keys(this.schema.callbacks!).forEach(callback => {\n let cb = this.schema.callbacks?.[callback];\n if (!cb) return;\n if (isRef(cb)) {\n this.schema.callbacks![callback] = dereferenceRef(cb, this.api);\n cb = this.schema.callbacks![callback];\n if (!cb || isRef(cb)) {\n return;\n }\n }\n\n Object.keys(cb).forEach(expression => {\n let callbackPath = cb[expression];\n if (!callbackPath) return;\n if (isRef(callbackPath)) {\n cb[expression] = dereferenceRef(callbackPath, this.api);\n callbackPath = cb[expression];\n if (!callbackPath || isRef(callbackPath)) {\n return;\n }\n }\n\n Object.keys(callbackPath).forEach(method => {\n if (!supportedMethods.includes(method as HttpMethods)) return;\n\n const found = this.getCallback(callback, expression, method as HttpMethods);\n if (found) {\n callbacks.push(found);\n }\n });\n });\n });\n // biome-ignore-end lint/style/noNonNullAssertion: --end--\n\n return callbacks;\n }\n\n /**\n * Retrieve an array of callback examples that this operation has.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callback-object}\n */\n getCallbackExamples(): CallbackExample[] {\n if (this.callbackExamples) {\n return this.callbackExamples;\n }\n\n this.callbackExamples = getCallbackExamples(this.schema, this.api);\n return this.callbackExamples;\n }\n\n /**\n * Determine if a given a custom specification extension exists within the operation.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specification-extensions}\n * @param extension Specification extension to lookup.\n */\n hasExtension(extension: string): boolean {\n return Boolean(this.schema && extension in this.schema);\n }\n\n /**\n * Retrieve a custom specification extension off of the operation.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specification-extensions}\n * @param extension Specification extension to lookup.\n *\n * @deprecated Use `oas.getExtension(extension, operation)` instead.\n */\n getExtension(extension: string | keyof Extensions): any {\n return this.schema?.[extension];\n }\n\n /**\n * Returns an object with groups of all example definitions (body/header/query/path/response/etc.).\n * The examples are grouped by their key when defined via the `examples` map.\n *\n * Any custom code samples defined via the `x-readme.code-samples` extension are returned,\n * regardless of if they have a matching response example.\n *\n * For standard OAS request parameter (e.g., body/header/query/path/etc.) examples,\n * they are only present in the return object if they have a corresponding response example\n * (i.e., a response example with the same key in the `examples` map).\n */\n getExampleGroups(): ExampleGroups {\n if (this.exampleGroups) return this.exampleGroups;\n\n const groups = getExampleGroups(this);\n\n this.exampleGroups = groups;\n\n return groups;\n }\n\n /**\n * Dereference the current operation schema so it can be parsed free of worries of `$ref` schemas\n * and circular structures.\n *\n */\n async dereference(opts?: {\n /**\n * A callback method can be supplied to be called when dereferencing is complete. Used for\n * debugging that the multi-promise handling within this method works.\n *\n * @private\n */\n cb?: () => void;\n }): Promise<(typeof this.promises)[] | boolean> {\n if (this.dereferencing.complete) {\n return Promise.resolve(true);\n }\n\n if (this.dereferencing.processing) {\n return new Promise((resolve, reject) => {\n this.promises.push({ resolve, reject });\n });\n }\n\n this.dereferencing.processing = true;\n\n // Because referencing will eliminate any lineage back to the original `$ref`, information that\n // we might need at some point, we should run through all available component schemas and denote\n // what their name is so that when dereferencing happens below those names will be preserved.\n //\n // Note: this mutates `this.api.components.schemas` in-place. Ideally we'd clone `components`\n // to avoid the side effect but `json-schema-ref-parser` relies on object identity for reference\n // resolution, so cloning breaks $ref handling. The mutation is idempotent (same key/value each\n // time) so it's safe in practice.\n if (!this.schemasDecorated) {\n decorateComponentSchemasWithRefName(this.api);\n this.schemasDecorated = true;\n }\n\n const { api, schema, promises } = this;\n\n const circularRefs: Set<string> = new Set();\n const dereferencingOptions = getDereferencingOptions(circularRefs);\n\n const parser = new $RefParser();\n return parser\n .dereference(\n '#/__INTERNAL__',\n {\n // Because `json-schema-ref-parser` will dereference this entire object as we only want\n // to dereference this operation schema we're attaching it to the `__INTERNAL__` key, and\n // later using that to extract our dereferenced schema. If we didn't do this then we run\n // the risk of any keyword in `schema` being overriden by `paths` and `components`.\n //\n // This solution isn't the best and still requires us to send `json-schema-ref-parser`\n // basically the entire API defintiion but because we don't know what `$ref` pointers in\n // `schema` reference, we can't know which parts of full API definition we could safely\n // exclude from this process.\n __INTERNAL__: structuredClone(schema),\n paths: api.paths ?? undefined,\n components: api.components ?? undefined,\n },\n {\n ...dereferencingOptions,\n dereference: {\n ...dereferencingOptions.dereference,\n\n /**\n * Because we only want to dereference our `__INTERNAL__` schema, not the **entire**\n * API definition if the parser attemps to dereference anything but that then we\n * should bail out of that crawler.\n *\n * @fixme this may cause issues where a path references a schema within itself to be ignored.\n */\n excludedPathMatcher: (path: string) => {\n if (path === '#/paths' || path.startsWith('#/paths/')) {\n return true;\n }\n return path === '#/components' || path.startsWith('#/components/');\n },\n },\n },\n )\n .then(res => {\n const dereferenced = res as JSONSchema & {\n __INTERNAL__: OperationObject;\n components?: OASDocument['components'];\n };\n\n // Refresh the current schema with the newly dereferenced one.\n this.schema = dereferenced.__INTERNAL__;\n\n this.promises = promises;\n this.dereferencing = {\n processing: false,\n complete: true,\n // We need to convert our `Set` to an array in order to match the typings.\n circularRefs: [...circularRefs],\n };\n\n // Used for debugging that dereferencing promise awaiting works.\n if (opts?.cb) {\n opts.cb();\n }\n })\n .then(() => {\n return this.promises.map(deferred => deferred.resolve());\n })\n .catch(err => {\n this.dereferencing.processing = false;\n this.promises.map(deferred => deferred.reject(err));\n throw err;\n });\n }\n\n /**\n * Determine if the current operation schema, or the OpenAPI definition it's part of, has been\n * dereferenced or not with `.dereference()`.\n *\n * @see Operation.dereference\n */\n isDereferenced(): boolean {\n return this.oas.isDereferenced() || this.dereferencing.processing || this.dereferencing.complete;\n }\n\n /**\n * Retrieve any circular `$ref` pointers that maybe present within operation schema.\n *\n * This method requires that you first dereference the definition.\n *\n * @see Operation.dereference\n */\n getCircularReferences(): string[] {\n if (!this.dereferencing.complete) {\n throw new Error('.dereference() must be called first in order for this method to obtain circular references.');\n }\n\n return this.dereferencing.circularRefs;\n }\n}\n\nexport class Callback extends Operation {\n /**\n * The identifier that this callback is set to.\n */\n identifier: string;\n\n /**\n * The parent path item object that this Callback exists within.\n */\n parentSchema: PathItemObject;\n\n constructor(\n oas: Oas,\n path: string,\n method: HttpMethods,\n operation: OperationObject,\n identifier: string,\n parentPathItem: PathItemObject,\n ) {\n super(oas, path, method, operation);\n\n this.identifier = identifier;\n this.parentSchema = parentPathItem;\n }\n\n /**\n * Return the primary identifier for this callback.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callback-object}\n */\n getIdentifier(): string {\n return this.identifier;\n }\n\n /**\n * Retrieve the `summary` for this callback.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-operationsummary}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-operation-summary}\n */\n getSummary(): string | undefined {\n if (this.schema?.summary && typeof this.schema.summary === 'string') {\n return this.schema.summary;\n } else if (this.parentSchema.summary && typeof this.parentSchema.summary === 'string') {\n return this.parentSchema.summary;\n }\n\n return undefined;\n }\n\n /**\n * Retrieve the `description` for this operation.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-operationdescription}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-operation-description}\n */\n getDescription(): string | undefined {\n if (this.schema?.description && typeof this.schema.description === 'string') {\n return this.schema.description;\n } else if (this.parentSchema.description && typeof this.parentSchema.description === 'string') {\n return this.parentSchema.description;\n }\n\n return undefined;\n }\n\n /**\n * Return the parameters (non-request body) on the operation.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-operationparameters}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-operation-parameters}\n */\n getParameters(): ParameterObject[] {\n let parameters = (this.schema?.parameters || [])\n .map(p => {\n let param = p;\n if (isRef(param)) {\n param = dereferenceRef(param, this.api);\n if (!param || isRef(param)) return undefined;\n }\n\n return param;\n })\n .filter((param): param is ParameterObject => param !== undefined);\n\n const commonParams = (this.parentSchema.parameters || [])\n .map(p => {\n let param = p;\n if (isRef(param)) {\n param = dereferenceRef(param, this.api);\n if (!param || isRef(param)) return undefined;\n }\n\n return param;\n })\n .filter((param): param is ParameterObject => param !== undefined);\n\n if (commonParams.length) {\n parameters = parameters.concat(dedupeCommonParameters(parameters, commonParams) || []);\n }\n\n return parameters;\n }\n}\n\nexport class Webhook extends Operation {\n /**\n * OpenAPI API Definition that this webhook originated from.\n */\n declare api: OAS31Document;\n\n /**\n * Retrieve the `summary` for this callback.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-operationsummary}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-operation-summary}\n */\n getSummary(): string | undefined {\n if (this.schema?.summary && typeof this.schema.summary === 'string') {\n return this.schema.summary;\n } else if (!this.api.webhooks) {\n return undefined;\n }\n\n let webhookPath = this.api.webhooks[this.path];\n if (isRef(webhookPath)) {\n this.api.webhooks[this.path] = dereferenceRef(webhookPath, this.api);\n webhookPath = this.api.webhooks[this.path];\n }\n\n return webhookPath?.summary;\n }\n\n /**\n * Retrieve the `description` for this operation.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#user-content-operationdescription}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.2.md#user-content-operation-description}\n */\n getDescription(): string | undefined {\n if (this.schema?.description && typeof this.schema.description === 'string') {\n return this.schema.description;\n } else if (!this.api.webhooks) {\n return undefined;\n }\n\n let webhookPath = this.api.webhooks[this.path];\n if (isRef(webhookPath)) {\n this.api.webhooks[this.path] = dereferenceRef(webhookPath, this.api);\n webhookPath = this.api.webhooks[this.path];\n }\n\n return webhookPath?.description;\n }\n}\n","import type { ParameterObject } from '../../types.js';\n\nimport { isRef } from '../../types.js';\n\n/**\n * With an array of common parameters filter down them to what isn't already present in a list of\n * non-common parameters.\n *\n * @param parameters Array of parameters defined at the operation level.\n * @param commonParameters Array of **common** parameters defined at the path item level.\n */\nexport function dedupeCommonParameters(\n parameters: ParameterObject[],\n commonParameters: ParameterObject[],\n): ParameterObject[] {\n return commonParameters.filter((param: ParameterObject) => {\n return !parameters.find((param2: ParameterObject) => {\n if (param.name && param2.name) {\n return param.name === param2.name && param.in === param2.in;\n } else if (isRef(param) && isRef(param2)) {\n return param.$ref === param2.$ref;\n }\n\n return false;\n });\n });\n}\n","/**\n * This file has been extracted and modified from Swagger UI.\n *\n * @license Apache-2.0\n * @see {@link https://github.com/swagger-api/swagger-ui/blob/master/src/core/plugins/samples/fn.js}\n */\nimport type { OASDocument, SchemaObject } from '../types.js';\n\nimport mergeJSONSchemaAllOf from 'json-schema-merge-allof';\nimport memoize from 'memoizee';\n\nimport { isRef } from '../types.js';\nimport { dereferenceRef } from '../utils.js';\nimport { deeplyStripKey, isFunc, normalizeArray, objectify, usesPolymorphism } from './utils.js';\n\nconst sampleDefaults = (genericSample: boolean | number | string) => {\n return (schema: SchemaObject): typeof genericSample =>\n typeof schema.default === typeof genericSample ? schema.default : genericSample;\n};\n\nconst primitives: Record<string, (arg: SchemaObject) => boolean | number | string> = {\n string: sampleDefaults('string'),\n string_email: sampleDefaults('user@example.com'),\n 'string_date-time': sampleDefaults(new Date().toISOString()),\n string_date: sampleDefaults(new Date().toISOString().substring(0, 10)),\n 'string_YYYY-MM-DD': sampleDefaults(new Date().toISOString().substring(0, 10)),\n string_uuid: sampleDefaults('3fa85f64-5717-4562-b3fc-2c963f66afa6'),\n string_hostname: sampleDefaults('example.com'),\n string_ipv4: sampleDefaults('198.51.100.42'),\n string_ipv6: sampleDefaults('2001:0db8:5b96:0000:0000:426f:8e17:642a'),\n number: sampleDefaults(0),\n number_float: sampleDefaults(0.0),\n integer: sampleDefaults(0),\n boolean: sampleDefaults(true),\n};\n\nconst primitive = (schema: SchemaObject) => {\n const objectifiedSchema = objectify(schema);\n const { format } = objectifiedSchema;\n let { type } = objectifiedSchema;\n\n if (type === 'null') {\n return null;\n } else if (Array.isArray(type)) {\n if (type.length === 1) {\n type = type[0];\n } else {\n // If one of our types is `null` then we should generate a sample for the non-null value.\n if (type.includes('null')) {\n type = type.filter(t => t !== 'null');\n }\n\n type = type.shift();\n }\n }\n\n // @todo add support for if `type` is an array\n const fn = primitives[`${type}_${format}`] || primitives[type as string];\n if (isFunc(fn)) {\n return fn(objectifiedSchema);\n }\n\n return `Unknown Type: ${objectifiedSchema.type}`;\n};\n\n/**\n * Generate a piece of sample data from a JSON Schema object. If `example` declarations are present\n * they will be utilized, but generally this will generate fake data for the information present in\n * the schema.\n *\n * @param schema JSON Schema to generate a sample for.\n */\nfunction sampleFromSchema(\n schema: SchemaObject,\n opts: {\n /**\n * An OpenAPI definition to use when resolving `$ref` pointers.\n */\n definition?: OASDocument;\n\n /**\n * If you wish to include data that's flagged as `readOnly`.\n */\n includeReadOnly?: boolean;\n\n /**\n * If you wish to include data that's flatted as `writeOnly`.\n */\n includeWriteOnly?: boolean;\n\n /**\n * Collection of `$ref` pointers to keep track of when dereferencing schemas here in order to\n * prevent infinite loops on circular references\n */\n seenRefs?: Set<string>;\n } = {},\n): Record<string, unknown> | unknown[] | boolean | number | string | null | undefined {\n const seenRefs = opts.seenRefs || new Set<string>();\n let objectifySchema = objectify(schema);\n\n // If this is a `$ref` pointer we should make an attempt to resolve it so we can generate a full\n // sample for this schema.\n let refToRelease: string | undefined;\n if (opts.definition && isRef(objectifySchema)) {\n refToRelease = objectifySchema.$ref;\n if (seenRefs.has(refToRelease)) {\n return undefined;\n }\n\n objectifySchema = dereferenceRef(objectifySchema, opts.definition, seenRefs);\n if (!objectifySchema || isRef(objectifySchema)) {\n return undefined;\n }\n }\n\n try {\n return sampleFromResolvedSchema(objectifySchema, opts, seenRefs);\n } finally {\n // In order to support generating samples from schemas that have circular references we're\n // releasing our `$ref` from the `seenRefs` store here so, it's re-used again in another\n // top-level property we're processing, we can generated another sample for it.\n if (refToRelease) {\n seenRefs.delete(refToRelease);\n }\n }\n}\n\nfunction sampleFromResolvedSchema(\n schema: Record<string, any>,\n opts: {\n definition?: OASDocument;\n includeReadOnly?: boolean;\n includeWriteOnly?: boolean;\n seenRefs?: Set<string>;\n },\n seenRefs: Set<string>,\n) {\n let { type } = schema;\n\n const hasPolymorphism = usesPolymorphism(schema);\n if (hasPolymorphism === 'allOf') {\n try {\n return sampleFromSchema(\n mergeJSONSchemaAllOf(schema, {\n resolvers: {\n // Ignore any unrecognized OAS-specific keywords that might be present on the schema\n // (like `xml`).\n defaultResolver: mergeJSONSchemaAllOf.options.resolvers.title,\n },\n }),\n {\n ...opts,\n seenRefs,\n },\n );\n } catch {\n return undefined;\n }\n } else if (hasPolymorphism) {\n const samples = (schema[hasPolymorphism] as SchemaObject[]).map(s => {\n return sampleFromSchema(s, { ...opts, seenRefs });\n });\n\n if (samples.length === 1) {\n return samples[0];\n } else if (samples.some(s => s === null)) {\n // If one of our samples is null then we should try to surface the first non-null one.\n return samples.find(s => s !== null);\n }\n\n // If we still don't have a sample then we should just return whatever the first sample we've\n // got is. The sample might not be a _full_ example but it should be enough to act as a sample.\n return samples[0];\n }\n\n const { example, additionalProperties, properties, items } = schema;\n const { includeReadOnly, includeWriteOnly } = opts;\n\n if (example !== undefined) {\n return deeplyStripKey(example, '$$ref', (val: unknown): val is string => {\n // do a couple of quick sanity tests to ensure the value\n // looks like a $$ref that swagger-client generates.\n return typeof val === 'string' && val.indexOf('#') > -1;\n });\n }\n\n if (!type) {\n if (properties || additionalProperties) {\n type = 'object';\n } else if (items) {\n type = 'array';\n } else {\n return undefined;\n }\n }\n\n if (type === 'object' || (Array.isArray(type) && type.includes('object'))) {\n const props = objectify(properties);\n const obj: Record<string, any> = {};\n for (const name in props) {\n if (props?.[name].deprecated) {\n continue;\n }\n\n if (props?.[name].readOnly && !includeReadOnly) {\n continue;\n }\n\n if (props?.[name].writeOnly && !includeWriteOnly) {\n continue;\n }\n\n if (props[name].examples?.length) {\n obj[name] = props[name].examples[0];\n continue;\n }\n\n obj[name] = sampleFromSchema(props[name], { ...opts, seenRefs });\n }\n\n if (additionalProperties === true) {\n obj.additionalProp = {};\n } else if (additionalProperties) {\n const additionalProps = objectify(additionalProperties);\n const additionalPropVal = sampleFromSchema(additionalProps, { ...opts, seenRefs });\n\n obj.additionalProp = additionalPropVal;\n }\n\n return obj;\n }\n\n if (type === 'array' || (Array.isArray(type) && type.includes('array'))) {\n // `items` should always be present on arrays, but if it isn't we should at least do our best\n // to support its absence.\n if (typeof items === 'undefined') {\n return [];\n }\n\n if (Array.isArray(items.anyOf)) {\n return items.anyOf.map((i: SchemaObject) =>\n sampleFromSchema(i, {\n ...opts,\n seenRefs,\n }),\n );\n }\n\n if (Array.isArray(items.oneOf)) {\n return items.oneOf.map((i: SchemaObject) =>\n sampleFromSchema(i, {\n ...opts,\n seenRefs,\n }),\n );\n }\n\n return [sampleFromSchema(items, { ...opts, seenRefs })];\n }\n\n if (schema.enum) {\n if (schema.default) {\n return schema.default;\n }\n\n return normalizeArray(schema.enum as string[])[0];\n }\n\n if (type === 'file') {\n return undefined;\n }\n\n return primitive(schema);\n}\n\nconst memo: typeof sampleFromSchema = memoize(sampleFromSchema);\n\n// biome-ignore lint/style/noDefaultExport: This is safe for now.\nexport default memo;\n","/**\n * Portions of this file have been extracted and modified from Swagger UI.\n *\n * @license Apache-2.0\n * @see {@link https://github.com/swagger-api/swagger-ui/blob/master/src/core/utils.js}\n */\nimport type { SchemaObject } from '../types.js';\n\nimport { isObject } from '../lib/helpers.js';\n\nexport function usesPolymorphism(schema: SchemaObject): 'allOf' | 'anyOf' | 'oneOf' | false {\n if (schema.oneOf) {\n return 'oneOf';\n } else if (schema.anyOf) {\n return 'anyOf';\n } else if (schema.allOf) {\n return 'allOf';\n }\n\n return false;\n}\n\nexport function objectify(thing: Record<string, unknown> | unknown): Record<string, any> {\n if (!isObject(thing)) {\n return {};\n }\n\n return thing;\n}\n\nexport function normalizeArray(arr: (number | string)[] | number | string): (number | string)[] {\n if (Array.isArray(arr)) {\n return arr;\n }\n\n return [arr];\n}\n\n// biome-ignore lint/complexity/noBannedTypes: This is part of a type guard.\nexport function isFunc(thing: unknown): thing is Function {\n return typeof thing === 'function';\n}\n\n// Deeply strips a specific key from an object.\n//\n// `predicate` can be used to discriminate the stripping further,\n// by preserving the key's place in the object based on its value.\n// @todo make this have a better type than `any`\nexport function deeplyStripKey(\n input: unknown,\n keyToStrip: string,\n predicate = (obj: unknown, key?: string): boolean => true,\n): SchemaObject | any {\n if (typeof input !== 'object' || Array.isArray(input) || input === null || !keyToStrip) {\n return input;\n }\n\n const obj = { ...input } as Record<string, SchemaObject>;\n\n Object.keys(obj).forEach(k => {\n if (k === keyToStrip && predicate(obj[k], k)) {\n delete obj[k];\n return;\n }\n\n obj[k] = deeplyStripKey(obj[k], keyToStrip, predicate);\n });\n\n return obj;\n}\n","import type { MediaTypeObject, OASDocument } from '../../types.js';\n\nimport matchesMimeType from '../../lib/matches-mimetype.js';\nimport sampleFromSchema from '../../samples/index.js';\nimport { isRef } from '../../types.js';\nimport { dereferenceRef } from '../../utils.js';\n\nexport interface MediaTypeExample {\n description?: string;\n summary?: string;\n title?: string;\n value: unknown;\n}\n\n/**\n * Extracts a collection of examples from an OpenAPI Media Type Object. The example will either\n * come from the `example` property, the first item in an `examples` array, or if none of those are\n * present it will generate an example based off its schema.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#media-type-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n * @param mediaType The media type that we're looking for examples for.\n * @param mediaTypeObject The media type object that we're looking for examples for.\n */\nexport function getMediaTypeExamples(\n mediaType: string,\n mediaTypeObject: MediaTypeObject,\n definition: OASDocument,\n opts: {\n /**\n * If you wish to include data that's flagged as `readOnly`.\n */\n includeReadOnly?: boolean;\n\n /**\n * If you wish to include data that's flatted as `writeOnly`.\n */\n includeWriteOnly?: boolean;\n } = {},\n): MediaTypeExample[] {\n if (mediaTypeObject.example) {\n if (isRef(mediaTypeObject.example)) {\n mediaTypeObject.example = dereferenceRef(mediaTypeObject.example, definition);\n if (!mediaTypeObject.example || isRef(mediaTypeObject.example)) {\n return [];\n }\n }\n\n return [\n {\n value: mediaTypeObject.example,\n },\n ];\n } else if (mediaTypeObject.examples) {\n const { examples } = mediaTypeObject;\n const multipleExamples = Object.keys(examples)\n .map(key => {\n let summary: string | undefined = key;\n let description: string | undefined;\n\n let example = examples[key];\n if (example !== null && typeof example === 'object') {\n if ('summary' in example) {\n summary = example.summary;\n }\n\n if ('description' in example) {\n description = example.description;\n }\n\n if (isRef(example)) {\n example = dereferenceRef(example, definition);\n if (!example || isRef(example)) {\n return false;\n }\n }\n\n if ('value' in example) {\n if (isRef(example.value)) {\n example.value = dereferenceRef(example.value, definition);\n if (!example.value || isRef(example.value)) {\n return false;\n }\n }\n\n example = example.value;\n }\n }\n\n const ret: MediaTypeExample = { summary, title: key, value: example };\n if (description) {\n ret.description = description;\n }\n\n return ret;\n })\n .filter((item): item is MediaTypeExample => item !== false);\n\n // If we were able to grab examples from the `examples` property return them (`examples` can\n // sometimes be an empty object), otherwise we should try to generate some instead.\n if (multipleExamples.length) {\n return multipleExamples;\n }\n }\n\n if (mediaTypeObject.schema) {\n // We do not fully support XML so we shouldn't generate XML samples for XML schemas.\n if (!matchesMimeType.xml(mediaType)) {\n return [\n {\n value: sampleFromSchema(structuredClone(mediaTypeObject.schema), {\n ...opts,\n definition,\n }),\n },\n ];\n }\n }\n\n return [];\n}\n","import type { OASDocument, OperationObject } from '../../types.js';\nimport type { MediaTypeExample } from './get-mediatype-examples.js';\n\nimport { dereferenceRef } from '../../lib/refs.js';\nimport { isRef } from '../../types.js';\nimport { getMediaTypeExamples } from './get-mediatype-examples.js';\n\nexport interface ResponseExample {\n mediaTypes: Record<string, MediaTypeExample[]>;\n onlyHeaders?: boolean;\n status: string;\n}\n\n/**\n * Retrieve a collection of response examples keyed, by their media type.\n *\n * @param operation Operation to retrieve response examples for.\n */\nexport function getResponseExamples(operation: OperationObject, definition: OASDocument): ResponseExample[] {\n return Object.keys(operation.responses || {})\n .map(status => {\n let response = operation.responses?.[status];\n let onlyHeaders = false;\n\n if (!response) return false;\n if (isRef(response)) {\n response = dereferenceRef(response, definition);\n if (!response || isRef(response)) return false;\n }\n\n const mediaTypes: Record<string, MediaTypeExample[]> = {};\n (response?.content ? Object.keys(response.content) : []).forEach(mediaType => {\n if (!mediaType) return;\n\n const mediaTypeObject = response.content?.[mediaType];\n if (!mediaTypeObject) return;\n\n const examples = getMediaTypeExamples(mediaType, mediaTypeObject, definition, {\n includeReadOnly: true,\n includeWriteOnly: false,\n });\n\n if (examples) {\n mediaTypes[mediaType] = examples;\n }\n });\n\n // If the response has no content, but has headers, hardcode an empty example so the headers\n // modal will still display\n if (response.headers && Object.keys(response.headers).length && !Object.keys(mediaTypes).length) {\n mediaTypes['*/*'] = [];\n onlyHeaders = true;\n }\n\n if (!Object.keys(mediaTypes).length) {\n return false;\n }\n\n return {\n status,\n mediaTypes,\n ...(onlyHeaders ? { onlyHeaders } : {}),\n };\n })\n .filter((item): item is ResponseExample => item !== false);\n}\n","import type { OASDocument, OperationObject } from '../../types.js';\nimport type { ResponseExample } from './get-response-examples.js';\n\nimport { dereferenceRef } from '../../lib/refs.js';\nimport { isRef } from '../../types.js';\nimport { getResponseExamples } from './get-response-examples.js';\n\nexport interface CallbackExample {\n example: ResponseExample[];\n expression: string;\n identifier: string;\n method: string;\n}\n\n/**\n * With an OpenAPI Operation Object return back a collection of examples for any callbacks that may\n * be present.\n *\n * @param operation Operation to retrieve callback examples from.\n */\nexport function getCallbackExamples(operation: OperationObject, definition: OASDocument): CallbackExample[] {\n if (!operation.callbacks) {\n return [];\n }\n\n const examples = Object.keys(operation.callbacks).map(identifier => {\n let callback = operation.callbacks?.[identifier];\n if (!callback) return [];\n if (isRef(callback)) {\n callback = dereferenceRef(callback, definition);\n if (!callback || isRef(callback)) return [];\n }\n\n const items = Object.keys(callback).map(expression => {\n let callbackPath = callback[expression];\n if (!callbackPath) return [];\n if (isRef(callbackPath)) {\n callbackPath = dereferenceRef(callbackPath, definition);\n if (!callbackPath || isRef(callbackPath)) return [];\n }\n\n return Object.keys(callbackPath).map(method => {\n if (['servers', 'parameters', 'summary', 'description'].includes(method)) {\n return false;\n }\n\n // This is a `PathItemObject` but `PathItemObject` extends `OperationObject` so this is\n // fine to force cast.\n const pathItem = callbackPath as Record<string, OperationObject>;\n const example = getResponseExamples(pathItem[method], definition);\n if (!example.length) return false;\n\n return {\n identifier,\n expression,\n method,\n example,\n };\n });\n });\n\n return items.flat().filter(item => item !== false);\n });\n\n return examples.flat();\n}\n","import type { Extensions } from '../../extensions.js';\nimport type { DataForHAR } from '../../types.js';\nimport type { Operation } from '../index.js';\nimport type { MediaTypeExample } from './get-mediatype-examples.js';\n\nimport { getExtension } from '../../extensions.js';\nimport { dereferenceRef } from '../../lib/refs.js';\nimport { isRef } from '../../types.js';\n\nexport type ExampleGroups = Record<\n string,\n {\n /**\n * Array of custom code samples that contain `correspondingExample` key.\n * Mutually exclusive of `request`. Note that if this object is present,\n * there may or may not be corresponding responses in the `response` object.\n */\n customCodeSamples?: (NonNullable<Extensions['code-samples']>[number] & {\n /**\n * The index in the originally defined `code-samples` array\n */\n originalIndex: number;\n })[];\n\n /**\n * Title of example group. This is derived from the `summary` field of one of\n * the operation's example objects. The precedence is as follows (from highest to lowest):\n * 1. The first custom code sample's `name` field.\n * 2. The first request parameter (e.g., cookie/header/path/query) example object that\n * contains a `summary` field\n * 3. The request body example object's `summary` field\n * 4. The response example object's `summary` field\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#example-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#example-object}\n */\n name: string;\n\n /**\n * Object containing the example request data for the current example key.\n * Mutually exclusive of `customCodeSamples`. If `customCodeSamples` is present,\n * any request example definitions are ignored.\n */\n request?: DataForHAR;\n\n /**\n * Object containing the example response data for the current example key.\n */\n response?: {\n /**\n * The content type of the current example\n *\n * @example \"application/json\"\n * @example \"text/plain\"\n */\n mediaType: string;\n\n /**\n * The entire response example object. The example value itself is contained\n * within `value`.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#example-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#example-object}\n */\n mediaTypeExample: MediaTypeExample;\n\n /**\n * The HTTP status code for the current response example\n *\n * @example \"2xx\"\n * @example \"400\"\n */\n status: string;\n };\n }\n>;\n\n/**\n * Internal key to represent custom code samples that do not have a corresponding response example.\n */\nconst noCorrespondingResponseKey = 'NoCorrespondingResponseForCustomCodeSample';\n\n/**\n * Takes a groups object and an operation and adds any matching response examples\n * to existing groups object\n */\nfunction addMatchingResponseExamples(groups: ExampleGroups, operation: Operation) {\n operation.getResponseExamples().forEach(example => {\n Object.entries(example.mediaTypes || {}).forEach(([mediaType, mediaTypeExamples]) => {\n mediaTypeExamples.forEach(mediaTypeExample => {\n // only add a response example if the `title` field exists\n // and it matches one of the existing example keys\n if (mediaTypeExample.title && Object.keys(groups).includes(mediaTypeExample.title)) {\n groups[mediaTypeExample.title].response = {\n mediaType,\n mediaTypeExample,\n status: example.status,\n };\n\n // if the current group doesn't already have a name set,\n // use the response example object's summary field\n if (!groups[mediaTypeExample.title].name) {\n groups[mediaTypeExample.title].name = mediaTypeExample.summary || mediaTypeExample.title;\n }\n }\n });\n });\n });\n}\n\n/**\n * Returns a name for the given custom code sample. If there isn't already one defined,\n * we construct a fallback value based on where the sample is in the array.\n */\nfunction getDefaultName(\n sample: NonNullable<Extensions['code-samples']>[number],\n count: Record<string, number>,\n): string {\n return sample.name && sample.name.length > 0\n ? sample.name\n : `Default${count[sample.language] > 1 ? ` #${count[sample.language]}` : ''}`;\n}\n\n/**\n * Returns an object with groups of all example definitions (body/header/query/path/response/etc.).\n * The examples are grouped by their key when defined via the `examples` map.\n *\n * Any custom code samples defined via the `x-readme.code-samples` extension are returned,\n * regardless of if they have a matching response example.\n *\n * For standard OAS request parameter (e.g., body/header/query/path/etc.) examples,\n * they are only present in the return object if they have a corresponding response example\n * (i.e., a response example with the same key in the `examples` map).\n */\nexport function getExampleGroups(operation: Operation): ExampleGroups {\n const namelessCodeSampleCounts: Record<string, number> = {};\n const groups: ExampleGroups = {};\n\n // add custom code samples\n const codeSamples = getExtension('code-samples', operation.api, operation) as Extensions['code-samples'];\n codeSamples?.forEach((sample, i) => {\n if (namelessCodeSampleCounts[sample.language]) {\n namelessCodeSampleCounts[sample.language] += 1;\n } else {\n namelessCodeSampleCounts[sample.language] = 1;\n }\n const name = getDefaultName(sample, namelessCodeSampleCounts);\n\n // sample contains `correspondingExample` key\n if (sample.correspondingExample) {\n if (groups[sample.correspondingExample]?.customCodeSamples?.length) {\n // biome-ignore lint/style/noNonNullAssertion: `customCodeSamples` is guaranteed to be an array here.\n groups[sample.correspondingExample].customCodeSamples!.push({ ...sample, name, originalIndex: i });\n } else if (sample.correspondingExample) {\n groups[sample.correspondingExample] = {\n name,\n customCodeSamples: [{ ...sample, name, originalIndex: i }],\n };\n }\n }\n\n // sample does not contain a corresponding response example\n else if (groups[noCorrespondingResponseKey]?.customCodeSamples?.length) {\n groups[noCorrespondingResponseKey].customCodeSamples.push({ ...sample, name, originalIndex: i });\n } else {\n groups[noCorrespondingResponseKey] = {\n name,\n customCodeSamples: [{ ...sample, name, originalIndex: i }],\n };\n }\n });\n\n // if we added any custom code samples, add the corresponding response examples and return\n if (Object.keys(groups).length) {\n addMatchingResponseExamples(groups, operation);\n return groups;\n }\n\n // add request param examples\n operation.getParameters().forEach(param => {\n Object.entries(param.examples || {}).forEach(([exampleKey, paramExample]) => {\n let example = paramExample;\n if (isRef(example)) {\n example = dereferenceRef(example, operation.api);\n if (!example || isRef(example)) return;\n }\n\n groups[exampleKey] = {\n ...groups[exampleKey],\n name: groups[exampleKey]?.name || example.summary || exampleKey,\n request: {\n ...groups[exampleKey]?.request,\n [param.in]: {\n ...groups[exampleKey]?.request?.[param.in],\n [param.name]: example.value,\n },\n },\n };\n });\n });\n\n // add request body examples\n operation.getRequestBodyExamples().forEach(requestExample => {\n requestExample.examples.forEach((mediaTypeExample: MediaTypeExample) => {\n if (mediaTypeExample.title) {\n const mediaType = requestExample.mediaType === 'application/x-www-form-urlencoded' ? 'formData' : 'body';\n groups[mediaTypeExample.title] = {\n ...groups[mediaTypeExample.title],\n name: groups[mediaTypeExample.title]?.name || mediaTypeExample.summary || mediaTypeExample.title,\n request: {\n ...groups[mediaTypeExample.title]?.request,\n [mediaType]: mediaTypeExample.value,\n },\n };\n }\n });\n });\n\n // if we added any request examples, add the corresponding response examples\n if (Object.keys(groups).length) {\n addMatchingResponseExamples(groups, operation);\n }\n\n // prune any objects that don't have both a request and a response\n Object.entries(groups).forEach(([groupId, group]) => {\n if (group.request && !group.response) {\n delete groups[groupId];\n }\n });\n\n return groups;\n}\n","import type { OASDocument, OperationObject } from '../../types.js';\nimport type { MediaTypeExample } from './get-mediatype-examples.js';\n\nimport { dereferenceRef } from '../../lib/refs.js';\nimport { isRef } from '../../types.js';\nimport { getMediaTypeExamples } from './get-mediatype-examples.js';\n\nexport interface RequestBodyExample {\n examples: MediaTypeExample[];\n mediaType: string;\n}\n\n/**\n * Retrieve a collection of request body examples, keyed by their media type.\n *\n * @param operation Operation to retrieve requestBody examples for.\n */\nexport function getRequestBodyExamples(operation: OperationObject, definition: OASDocument): RequestBodyExample[] {\n let requestBody = operation.requestBody;\n if (!requestBody) {\n return [];\n } else if (isRef(requestBody)) {\n requestBody = dereferenceRef(requestBody, definition);\n }\n\n // If this request body still can't be resolved then we shouldn't return anything because it's\n // either an invalid schema or a circular reference.\n if (!requestBody || isRef(requestBody) || !requestBody.content) {\n return [];\n }\n\n return Object.keys(requestBody.content || {})\n .map(mediaType => {\n const mediaTypeObject = requestBody.content[mediaType];\n const examples = getMediaTypeExamples(mediaType, mediaTypeObject, definition, {\n includeReadOnly: false,\n includeWriteOnly: true,\n });\n\n if (!examples.length) {\n return false;\n }\n\n return {\n mediaType,\n examples,\n };\n })\n .filter((item): item is RequestBodyExample => item !== false);\n}\n","import type { OperationObject } from '../../types.ts';\n\nexport interface OperationIDGeneratorOptions {\n /**\n * Generate a JS method-friendly operation ID when one isn't present.\n *\n * For backwards compatiblity reasons this option will be indefinitely supported however we\n * recommend using `friendlyCase` instead as it's a heavily improved version of this option.\n *\n * @see {friendlyCase}\n * @deprecated\n */\n camelCase?: boolean;\n\n /**\n * Generate a human-friendly, but still camelCase, operation ID when one isn't present. The\n * difference between this and `camelCase` is that this also ensure that consecutive words are\n * not present in the resulting ID. For example, for the endpoint `/candidate/{candidate}` will\n * return `getCandidateCandidate` for `camelCase` however `friendlyCase` will return\n * `getCandidate`.\n *\n * The reason this friendliness is just not a part of the `camelCase` option is because we have\n * a number of consumers of the old operation ID style and making that change there would a\n * breaking change that we don't have any easy way to resolve.\n */\n friendlyCase?: boolean;\n}\n\n/**\n * Determine if an operation has an `operationId` present in its schema. Note that if one is\n * present in the schema but is an empty string then this will return false.\n *\n */\nexport function hasOperationId(operation: OperationObject): boolean {\n return Boolean('operationId' in operation && operation.operationId?.length);\n}\n\n/**\n * Get an `operationId` for an operation. If one is not present (it's not required by the spec!)\n * a hash of the path and method will be returned instead.\n *\n */\nexport function getOperationId(\n path: string,\n method: string,\n operation: OperationObject,\n opts: OperationIDGeneratorOptions = {},\n): string {\n function sanitize(id: string) {\n // We aren't sanitizing underscores here by default in order to preserve operation IDs that\n // were already generated with this method in the past.\n return id\n .replace(opts?.camelCase || opts?.friendlyCase ? /[^a-zA-Z0-9_]/g : /[^a-zA-Z0-9]/g, '-') // Remove weird characters\n .replace(/--+/g, '-') // Remove double --'s\n .replace(/^-|-$/g, ''); // Don't start or end with -\n }\n\n const operationIdExists = hasOperationId(operation);\n let operationId: string;\n if (operationIdExists) {\n // `operationId` has already been guaranteed to be a truthy string by `hasOperationId()`.\n operationId = operation.operationId as string;\n } else {\n operationId = sanitize(path).toLowerCase();\n }\n\n const currMethod = method.toLowerCase();\n if (opts?.camelCase || opts?.friendlyCase) {\n if (opts?.friendlyCase) {\n // In order to generate friendlier operation IDs we should swap out underscores with spaces\n // so the end result will be _slightly_ more camelCase.\n operationId = operationId.replaceAll('_', ' ');\n\n if (!operationIdExists) {\n // In another effort to generate friendly operation IDs we should prevent words from\n // appearing in consecutive order (eg. `/candidate/{candidate}` should generate\n // `getCandidate` not `getCandidateCandidate`). However we only want to do this if we're\n // generating the operation ID as if they intentionally added a consecutive word into the\n // operation ID then we should respect that.\n operationId = operationId\n .replace(/[^a-zA-Z0-9_]+(.)/g, (_, chr) => ` ${chr}`)\n .split(' ')\n .filter((word, i, arr) => word !== arr[i - 1])\n .join(' ');\n }\n }\n\n operationId = operationId.replace(/[^a-zA-Z0-9_]+(.)/g, (_, chr) => chr.toUpperCase());\n if (operationIdExists) {\n operationId = sanitize(operationId);\n }\n\n // Never start with a number.\n operationId = operationId.replace(/^[0-9]/g, match => `_${match}`);\n\n // Ensure that the first character of an `operationId` is always lowercase.\n operationId = operationId.charAt(0).toLowerCase() + operationId.slice(1);\n\n // If the generated `operationId` already starts with the method (eg. `getPets`) we don't want\n // to double it up into `getGetPets`.\n if (operationId.startsWith(currMethod)) {\n return operationId;\n }\n\n // If this operation already has an `operationId` and we just cleaned it up then we shouldn't\n // prefix it with an HTTP method.\n if (operationIdExists) {\n return operationId;\n }\n\n // Because we're merging the `operationId` into an HTTP method we need to reset the first\n // character of it back to lowercase so we end up with `getBuster`, not `getbuster`.\n operationId = operationId.charAt(0).toUpperCase() + operationId.slice(1);\n return `${currMethod}${operationId}`;\n } else if (operationIdExists) {\n return operationId;\n }\n\n return `${currMethod}_${operationId}`;\n}\n","import type { toJSONSchemaOptions } from '../../lib/openapi-to-json-schema.js';\nimport type { HeaderObject, MediaTypeObject, OASDocument, ResponseObject, SchemaObject } from '../../types.js';\nimport type { Operation } from '../index.js';\n\nimport { applyDiscriminatorOneOfToUsedSchemas } from '../../lib/build-discriminator-one-of.js';\nimport { cloneObject } from '../../lib/clone-object.js';\nimport { isPrimitive } from '../../lib/helpers.js';\nimport matches from '../../lib/matches-mimetype.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\nexport interface ResponseSchemaObject {\n description?: string;\n label: string;\n schema: SchemaObject;\n type: string[] | string;\n}\n\nconst isJSON = matches.json;\n\n/**\n * Turn a header map from OpenAPI 3.0 (and some earlier versions too) into a schema.\n *\n * Note: This does not support OpenAPI 3.1's header format.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#header-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.3.md#header-object}\n * @param response Response object to build a JSON Schema object for its headers for.\n * @param schemaOptions Optional options to pass to toJSONSchema (e.g. for ref resolution).\n */\nfunction buildHeadersSchema(response: ResponseObject, schemaOptions: toJSONSchemaOptions) {\n const headersSchema: SchemaObject = {\n type: 'object',\n properties: {},\n };\n\n const api = schemaOptions.definition;\n const seenRefs = schemaOptions.seenRefs ?? new Set<string>();\n\n if (response.headers) {\n Object.keys(response.headers).forEach(key => {\n let headerEntry = response.headers?.[key];\n if (!headerEntry) return;\n if (isRef(headerEntry)) {\n headerEntry = dereferenceRef(headerEntry, api, seenRefs);\n if (!headerEntry || isRef(headerEntry)) return;\n }\n\n if (headerEntry.schema) {\n const header: HeaderObject = headerEntry;\n\n let headerSchema = header.schema;\n if (!headerSchema) return;\n if (isRef(headerSchema)) {\n headerSchema = dereferenceRef(headerSchema, api, seenRefs);\n if (!headerSchema || isRef(headerSchema)) return;\n }\n\n // TODO: Response headers are essentially parameters in OAS\n // This means they can have content instead of schema.\n // We should probably support that in the future\n // biome-ignore lint/style/noNonNullAssertion: This is guaranteed.\n headersSchema.properties![key] = toJSONSchema(cloneObject(headerSchema), {\n addEnumsToDescriptions: true,\n ...schemaOptions,\n });\n\n if (header.description) {\n // biome-ignore lint/style/noNonNullAssertion: This is guaranteed.\n headersSchema.properties![key].description = header.description;\n }\n }\n });\n }\n\n const headersWrapper: {\n description?: string;\n label: string;\n schema: SchemaObject;\n type: string;\n } = {\n schema: headersSchema,\n type: 'object',\n label: 'Headers',\n };\n\n if (response.description && headersWrapper.schema) {\n headersWrapper.description = response.description;\n }\n\n return headersWrapper;\n}\n\n/**\n * Extract all the response schemas, matching the format of `get-parameters-as-json-schema`.\n *\n * This automatically resolves `$ref` pointers on the fly and attaches used schemas as components\n * within the generated JSON Schema object.\n *\n * @param operation Operation to construct a response JSON Schema for.\n * @param api The OpenAPI definition that this operation originates.\n * @param statusCode The response status code to generate a schema for.\n * @param opts Options for schema generation.\n * @param opts.contentType Optional content-type to use. If specified and the response doesn't have\n * this content-type, the function will return null.\n */\nexport function getResponseAsJSONSchema(\n operation: Operation,\n api: OASDocument,\n statusCode: number | string,\n opts?: {\n includeDiscriminatorMappingRefs?: boolean;\n /**\n * Optional content-type to use. If specified and the response doesn't have this content-type,\n * the function will return null.\n */\n contentType?: string;\n },\n): ResponseSchemaObject[] | null {\n const response = operation.getResponseByStatusCode(statusCode);\n const jsonSchema: ResponseSchemaObject[] = [];\n\n if (!response) {\n return null;\n }\n\n const usedSchemas = new Map<string, SchemaObject>();\n const seenRefs = new Set<string>();\n const refsByGroup = new Map<'body' | 'headers', Set<string>>();\n\n function refLoggerForSchemaGroup(group: 'body' | 'headers'): Set<string> {\n let set = refsByGroup.get(group);\n if (!set) {\n set = new Set();\n refsByGroup.set(group, set);\n }\n return set;\n }\n\n const baseSchemaOptions: toJSONSchemaOptions = {\n addEnumsToDescriptions: true,\n definition: api,\n seenRefs,\n usedSchemas,\n refLogger: ref => refLoggerForSchemaGroup('body').add(ref),\n };\n\n /**\n * @param content An array of `MediaTypeObject`'s to retrieve a preferred schema out of. We\n * prefer JSON media types.\n * @param preferredContentType Optional content-type to use. If specified and not found, returns null.\n */\n function getPreferredSchema(content: Record<string, MediaTypeObject> | undefined, preferredContentType?: string) {\n if (!content) {\n return null;\n }\n\n const contentTypes = Object.keys(content);\n if (!contentTypes.length) {\n return null;\n }\n\n // If a specific content-type is requested, use it if it exists\n if (preferredContentType) {\n if (contentTypes.includes(preferredContentType)) {\n const schema = cloneObject(content[preferredContentType].schema);\n if (!schema) {\n return null;\n }\n\n return toJSONSchema(schema, baseSchemaOptions);\n }\n\n // Requested `content-type` not found, return null\n return null;\n }\n\n // Default behavior: prefer JSON media types\n for (let i = 0; i < contentTypes.length; i++) {\n if (isJSON(contentTypes[i])) {\n const schema = cloneObject(content[contentTypes[i]].schema);\n if (!schema) {\n return {};\n }\n\n return toJSONSchema(schema, baseSchemaOptions);\n }\n }\n\n // We always want to prefer the JSON-compatible content types over everything else but if we\n // haven't found one we should default to the first available.\n const contentType = contentTypes.shift();\n if (!contentType) {\n return {};\n }\n\n const schema = cloneObject(content[contentType].schema);\n if (!schema) {\n return {};\n }\n\n return toJSONSchema(schema, baseSchemaOptions);\n }\n\n const foundSchema = getPreferredSchema(response.content, opts?.contentType);\n\n // If a specific content-type was requested but not found, return null immediately\n if (opts?.contentType && !foundSchema) {\n return null;\n }\n\n if (foundSchema) {\n const schema = structuredClone(foundSchema);\n let schemaType = foundSchema.type;\n\n // If our found schema is a `$ref` pointer then we should try to resolve its type so we can\n // surface that to the root schema as its overall `type`.\n if (schemaType === undefined && isRef(foundSchema) && usedSchemas.size > 0) {\n const resolvedSchema = usedSchemas.get(foundSchema.$ref);\n const resolvedType =\n resolvedSchema && typeof resolvedSchema === 'object' && 'type' in resolvedSchema\n ? resolvedSchema.type\n : undefined;\n\n schemaType = Array.isArray(resolvedType) ? resolvedType[0] : resolvedType;\n }\n\n const schemaWrapper: {\n description?: string;\n label: string;\n schema: SchemaObject;\n type: string[] | string;\n } = {\n // If there's no `type` then the root schema is a circular `$ref` that we likely won't be\n // able to render so instead of generating a JSON Schema with an `undefined` type we should\n // default to `string` so there's at least *something* the end-user can interact with.\n type: schemaType ?? 'string',\n schema: isPrimitive(schema)\n ? schema\n : {\n ...schema,\n $schema: getSchemaVersionString(schema, api),\n },\n label: 'Response body',\n };\n\n if (response.description && schemaWrapper.schema) {\n schemaWrapper.description = response.description;\n }\n\n // Apply discriminator `oneOf` 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), {\n ...baseSchemaOptions,\n seenRefs,\n });\n\n usedSchemas.set(ref, converted);\n return converted;\n } catch {\n return undefined;\n }\n });\n\n // Include only schemas that are still referenced in the output; merge them into the root at their ref paths.\n if (schemaWrapper.schema && usedSchemas.size > 0) {\n const refsInGroup = refsByGroup.get('body') ?? new Set<string>();\n const referencedSchemas = filterRequiredRefsToReferenced(refsInGroup, usedSchemas);\n\n if (referencedSchemas.size > 0) {\n mergeReferencedSchemasIntoRoot(schemaWrapper.schema, referencedSchemas);\n }\n }\n\n jsonSchema.push(schemaWrapper);\n }\n\n // 3.0.3 and earlier headers. TODO: New format for 3.1.0\n if (response.headers) {\n const headersWrapper = buildHeadersSchema(response, {\n ...baseSchemaOptions,\n refLogger: ref => refLoggerForSchemaGroup('headers').add(ref),\n });\n\n if (headersWrapper.schema && usedSchemas.size > 0) {\n const refsInGroup = refsByGroup.get('headers') ?? new Set();\n const referencedSchemas = filterRequiredRefsToReferenced(refsInGroup, usedSchemas);\n\n if (referencedSchemas.size > 0) {\n mergeReferencedSchemasIntoRoot(headersWrapper.schema, referencedSchemas);\n }\n }\n\n jsonSchema.push(headersWrapper);\n }\n\n return jsonSchema.length ? jsonSchema : null;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas/dist/chunk-HTEFBV7K.cjs","../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"],"names":["types","converted","schema"],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACVA,SAAS,gBAAA,CAA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ACF,IAAA;AAEO,IAAA;AAEO,EAAA;AAC6B,IAAA;AAC5C,EAAA;AACL;ARk8BgD;AACA;ASzxCO;AAEV;AT0xCG;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/erunion/code/readme/oas/packages/oas/dist/chunk-HTEFBV7K.cjs","sourcesContent":[null,"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"]}