oas 32.1.11 → 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.
- package/dist/analyzer/index.cjs +5 -5
- package/dist/analyzer/index.js +3 -3
- package/dist/{chunk-2J4VKLIT.js → chunk-2EISA7HB.js} +4 -4
- package/dist/chunk-2EISA7HB.js.map +1 -0
- package/dist/{chunk-DNLCD3K6.cjs → chunk-7BWVOLZR.cjs} +131 -130
- package/dist/chunk-7BWVOLZR.cjs.map +1 -0
- package/dist/{chunk-FGPV2UXT.cjs → chunk-BJEFIYTO.cjs} +20 -20
- package/dist/chunk-BJEFIYTO.cjs.map +1 -0
- package/dist/{chunk-JCBISKOK.js → chunk-GIFUTDD5.js} +18 -17
- package/dist/chunk-GIFUTDD5.js.map +1 -0
- package/dist/{chunk-QINBUHP2.js → chunk-K5WNB3M7.js} +10 -7
- package/dist/chunk-K5WNB3M7.js.map +1 -0
- package/dist/{chunk-X7KOY66H.cjs → chunk-SAB2PGCD.cjs} +10 -7
- package/dist/chunk-SAB2PGCD.cjs.map +1 -0
- package/dist/index.cjs +4 -4
- package/dist/index.js +3 -3
- package/dist/operation/index.cjs +3 -3
- package/dist/operation/index.js +2 -2
- package/dist/reducer/index.cjs +7 -7
- package/dist/reducer/index.cjs.map +1 -1
- package/dist/reducer/index.js +1 -1
- package/dist/reducer/index.js.map +1 -1
- package/dist/utils.cjs +2 -2
- package/dist/utils.js +1 -1
- package/package.json +6 -8
- package/dist/chunk-2J4VKLIT.js.map +0 -1
- package/dist/chunk-DNLCD3K6.cjs.map +0 -1
- package/dist/chunk-FGPV2UXT.cjs.map +0 -1
- package/dist/chunk-JCBISKOK.js.map +0 -1
- package/dist/chunk-QINBUHP2.js.map +0 -1
- package/dist/chunk-X7KOY66H.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/reducer/index.ts"],"sourcesContent":["import type { OpenAPIV3_1 } from 'openapi-types';\nimport type { ComponentsObject, HttpMethods, OASDocument, OperationObject, TagObject } from '../types.js';\n\nimport jsonPointer from 'jsonpointer';\n\nimport { query } from '../analyzer/util.js';\nimport { decodePointer } from '../lib/refs.js';\nimport { isOpenAPI31, isRef } from '../types.js';\nimport { supportedMethods } from '../utils.js';\n\nexport class OpenAPIReducer {\n private definition: OASDocument;\n\n /**\n * A collection of `$ref` pointers that are used within our reduced API definition. This is used\n * to ensure that all referenced schemas are retained in our resulting API definition. Not\n * retaining them would result in an invalid OpenAPI definition.\n */\n private $refs: Set<string> = new Set();\n\n /**\n * A collection of OpenAPI tags that are used within our reduced API definition.\n */\n private usedTags: Set<string> = new Set();\n\n /**\n * A collection of OpenAPI paths and operations that are cross-referenced from any other paths\n * and operations that we are reducing. This collection is used in order to ensure that those\n * schemas are retained with our resulting API definition. Not retaining them would result in an\n * invalid OpenAPI definition.\n */\n private retainPathMethods: Set<`${string}|${string}`> = new Set();\n\n /**\n * A collection of OpenAPI webhook names and methods that are cross-referenced from any other\n * schemas. This collection, like `retainPathMethods`, is used in order to ensure that those\n * schemas are retained with our resulting API definition. Not retaining them would result in an\n * invalid OpenAPI definition.\n */\n private retainWebhookMethods: Set<`${string}|${string}`> = new Set();\n\n /**\n * An array of OpenAPI tags to reduce down to.\n */\n private tagsToReduceBy: string[] = [];\n\n /**\n * A collection of OpenAPI paths and operations to reduce down to.\n */\n private pathsToReduceBy: Record<string, '*' | string[]> = {};\n\n /**\n * A collection of OpenAPI webhooks to reduce down to.\n */\n private webhooksToReduceBy: Record<string, '*' | string[]> = {};\n\n private hasTagsToReduceBy: boolean = false;\n private hasPathsToReduceBy: boolean = false;\n private hasWebhooksToReduceBy: boolean = false;\n\n private constructor(definition: OASDocument) {\n this.definition = structuredClone(definition);\n }\n\n /**\n * Initialize a new instance of the `OpenAPIReducer`. The reducer allows you to reduce an OpenAPI\n * definition down to only the information necessary to fulfill a specific set of tags, paths,\n * operations, and webhooks.\n *\n * OpenAPI reduction can be helpful not only to isolate and troubleshoot issues with large API\n * definitions, but also to compress a large API definition down to a manageable size containing\n * a specific set of items.\n *\n * All OpenAPI definitions reduced will still be fully functional and valid OpenAPI definitions.\n *\n * @param definition An OpenAPI definition to reduce.\n */\n static init(definition: OASDocument): OpenAPIReducer {\n return new OpenAPIReducer(definition);\n }\n\n /**\n * Mark an OpenAPI tag to be included in our reduced API definition. Tag casing does not matter.\n *\n * @param tag The tag to mark for reduction.\n */\n byTag(tag: string): OpenAPIReducer {\n this.tagsToReduceBy.push(tag.toLowerCase());\n return this;\n }\n\n /**\n * Mark an entire OpenAPI path, and all methods that it contains, to be included in your reduced\n * API definition. Path casing does not matter.\n *\n * @param path The path to mark for reduction.\n */\n byPath(path: string): OpenAPIReducer {\n this.pathsToReduceBy[path.toLowerCase()] = '*';\n return this;\n }\n\n /**\n * Mark a single OpenAPI operation to be included in your reduced API definition. If the path\n * that this operation is a part of utilizes common parameters, those will be automatically\n * included. Path and method casing does not matter.\n *\n * Note that if you previously called `.byPath()` to reduce an entire path down, calling\n * `.byOperation()` will override that to just reduce this specific method (or this plus\n * subsequent calls to `.byOperation()`).\n *\n * @param path The path that the operation is a part of.\n * @param method The HTTP method of the operation to mark for reduction.\n *\n */\n byOperation(path: string, method: string): OpenAPIReducer {\n const pathLC = path.toLowerCase(); // Casing should not matter.\n const methodLC = method.toLowerCase();\n\n if (this.pathsToReduceBy[pathLC] && Array.isArray(this.pathsToReduceBy[pathLC])) {\n this.pathsToReduceBy[pathLC].push(methodLC);\n } else {\n this.pathsToReduceBy[pathLC] = [methodLC];\n }\n\n return this;\n }\n\n /**\n * Mark an OpenAPI webhook (and all of its operations) to be included in your reduced API\n * definition. Casing does not matter.\n *\n * @param webhookName The webhook name to mark for reduction.\n */\n byWebhook(webhookName: string): OpenAPIReducer;\n\n /**\n * Mark a single OpenAPI webhook operation to be included in your reduced API definition.\n * Casing does not matter.\n *\n * @param webhookName The webhook name that the operation belongs to.\n * @param method The HTTP method of the webhook operation to mark for reduction.\n */\n byWebhook(webhookName: string, method: string): OpenAPIReducer;\n\n byWebhook(webhookName: string, method?: string): OpenAPIReducer {\n const nameLC = webhookName.toLowerCase();\n if (!method) {\n this.webhooksToReduceBy[nameLC] = '*';\n return this;\n }\n\n const methodLC = method.toLowerCase();\n if (this.webhooksToReduceBy[nameLC] && Array.isArray(this.webhooksToReduceBy[nameLC])) {\n this.webhooksToReduceBy[nameLC].push(methodLC);\n } else {\n this.webhooksToReduceBy[nameLC] = [methodLC];\n }\n\n return this;\n }\n\n /**\n * Reduce the current OpenAPI definition down to the configured filters.\n *\n */\n reduce(): OASDocument {\n if (!this.definition.openapi) {\n throw new Error('Sorry, only OpenAPI definitions are supported.');\n }\n\n this.hasPathsToReduceBy = Boolean(Object.keys(this.pathsToReduceBy).length);\n this.hasWebhooksToReduceBy = Boolean(Object.keys(this.webhooksToReduceBy).length);\n this.hasTagsToReduceBy = Boolean(this.tagsToReduceBy.length);\n\n // Retain any root-level security definitions, regardless if they're used or not on our reduced\n // operations.\n if ('security' in this.definition) {\n Object.values(this.definition.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n }\n\n this.walkPaths();\n this.walkWebhooks();\n\n // Recursively accumulate any components that are in use.\n this.$refs.forEach($ref => {\n this.accumulateUsedRefs(this.definition, this.$refs, $ref);\n });\n\n this.$refs.forEach(ref => {\n const usedPathRef = this.parsePathRef(ref);\n if (usedPathRef) {\n this.retainPathMethods.add(`${usedPathRef.path.toLowerCase()}|${usedPathRef.method.toLowerCase()}`);\n }\n\n const usedWebhookRef = this.parseWebhookRef(ref);\n if (usedWebhookRef) {\n this.retainWebhookMethods.add(`${usedWebhookRef.name.toLowerCase()}|${usedWebhookRef.method.toLowerCase()}`);\n }\n });\n\n this.reducePaths();\n this.reduceWebhooks();\n\n // Require at least one path or one webhook in the result.\n const hasPaths = Boolean(this.definition.paths && Object.keys(this.definition.paths).length);\n const hasWebhooks = Boolean(\n 'webhooks' in this.definition && this.definition.webhooks && Object.keys(this.definition.webhooks).length,\n );\n\n if (!hasPaths && !hasWebhooks) {\n throw new Error(\n 'All paths and webhooks in the API definition were removed. Did you supply the right path, operation, or webhook to reduce by?',\n );\n }\n\n // Remove any unused components.\n if ('components' in this.definition) {\n Object.keys(this.definition.components || {}).forEach(componentType => {\n Object.keys(this.definition.components?.[componentType as keyof ComponentsObject] || {}).forEach(component => {\n // If our `$ref` either is a full, or deep match, then we should preserve it.\n const refIsUsed =\n this.$refs.has(`#/components/${componentType}/${component}`) ||\n Array.from(this.$refs).some(ref => {\n // Because you can have a `$ref` like `#/components/examples/event-min/value`, which\n // would be accumulated via our `$refs` query, we want to make sure we account for them.\n // If we don't look for these then we'll end up removing them from the overall reduced\n // definition, resulting in data loss and schema corruption.\n return ref.startsWith(`#/components/${componentType}/${component}/`);\n });\n\n if (!refIsUsed) {\n delete this.definition.components?.[componentType as keyof ComponentsObject]?.[component];\n }\n });\n\n // If this component group is now empty, delete it.\n if (!Object.keys(this.definition.components?.[componentType as keyof ComponentsObject] || {}).length) {\n delete this.definition.components?.[componentType as keyof ComponentsObject];\n }\n });\n\n // If this path no longer has any components, delete it.\n if (!Object.keys(this.definition.components || {}).length) {\n delete this.definition.components;\n }\n }\n\n // Remove any unused tags.\n if ('tags' in this.definition) {\n this.definition.tags = (this.definition.tags ?? []).filter((tag): tag is TagObject => {\n return Boolean(tag) && this.usedTags.has(tag.name);\n });\n\n if (!this.definition.tags?.length) {\n delete this.definition.tags;\n }\n }\n\n return this.definition;\n }\n\n /**\n * Recursively process a `$ref` pointer and accumulate any other `$ref` pointers that it or its\n * children use. This handles circular references by skipping `$ref` pointers we have already seen.\n * Additionally when a `$ref` points to `#/paths` we record the used path + method so we can\n * retain cross-operation references within the reduced definition.\n *\n * @param schema JSON Schema object to look for and accumulate any `$ref` pointers that it may have.\n * @param $refs Known set of `$ref` pointers.\n * @param $ref `$ref` pointer to fetch a schema from out of the supplied schema.\n */\n private accumulateUsedRefs(schema: Record<string, unknown>, $refs: Set<string>, $ref: string): void {\n // Record `$ref` pointers aimed at `#/paths` so we can retain any cross-operation references.\n const pathRef = this.parsePathRef($ref);\n if (pathRef) {\n this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);\n }\n\n const webhookRef = this.parseWebhookRef($ref);\n if (webhookRef) {\n this.retainWebhookMethods.add(`${webhookRef.name.toLowerCase()}|${webhookRef.method.toLowerCase()}`);\n }\n\n let $refSchema: unknown;\n if (typeof $ref === 'string') $refSchema = jsonPointer.get(schema, $ref.substring(1));\n if ($refSchema === undefined) {\n // If the schema we have wasn't fully dereferenced or bundled for whatever reason and this\n // `$ref` that we have doesn't exist here we shouldn't try to search for more `$ref` pointers\n // in a schema that doesn't exist.\n return;\n }\n\n this.queryForRefPointers($refSchema).forEach(({ value: currRef }) => {\n // Because it's possible to have a schema property named `$ref` that is not a `$ref` pointer,\n // which our JSONPath query would pick up as a false positive, we want to exclude that from\n // `$ref` matching as it's not a reference pointer.\n const foundRef = this.toRefString(currRef);\n if (!foundRef) {\n return;\n }\n\n // If we've already processed this `$ref` then don't send us into an infinite loop of processing\n // circular references.\n if ($refs.has(foundRef)) {\n return;\n }\n\n $refs.add(foundRef);\n this.accumulateUsedRefs(schema, $refs, foundRef);\n });\n }\n\n /**\n * Query a JSON Schema object for any `$ref` pointers using JSONPath and return any pointers that\n * exist.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc9535}\n * @param schema JSON Schema object to look for any `$ref` pointers within it.\n */\n private queryForRefPointers(schema: any) {\n return query([\"$..['$ref']\"], schema);\n }\n\n /**\n * Normalize a value from a `jsonpath-plus` `$ref` query to a `$ref` pointer because JSONPath\n * queries may return the property value or the parent.\n *\n */\n private toRefString(value: unknown): string | null {\n if (typeof value === 'string') {\n return value;\n } else if (value && typeof value === 'object' && '$ref' in value && typeof value.$ref === 'string') {\n return value.$ref;\n }\n\n return null;\n }\n\n /**\n * If the given `$ref` points into a path (e.g. `#/paths/~1anything/post/...`), return the path\n * and method so the reducer can ultimately retain cross-operation references.\n *\n */\n private parsePathRef($ref: string): { path: string; method: string } | null {\n if (typeof $ref !== 'string' || !$ref.startsWith('#/paths/')) {\n return null;\n }\n\n // Extract path segment and method: `#/paths/<pathSegment>/<method>/...`\n const match = $ref.match(/^#\\/paths\\/([^/]+)\\/([^/]+)(?:\\/|$)/);\n if (match) {\n const pathSegment = match[1];\n const method = match[2];\n if (pathSegment && method) {\n return { path: decodePointer(pathSegment), method };\n }\n }\n\n return null;\n }\n\n /**\n * If the given `$ref` points into webhooks (e.g. `#/webhooks/newBooking/post/...`), return the\n * webhook name and method so the reducer can retain cross-referenced webhook operations.\n *\n */\n private parseWebhookRef($ref: string): { name: string; method: string } | null {\n if (typeof $ref !== 'string' || !$ref.startsWith('#/webhooks/')) {\n return null;\n }\n\n // Extract path segment and method: `#/webhooks/<webhookName>/<method>/...`\n const match = $ref.match(/^#\\/webhooks\\/([^/]+)\\/([^/]+)(?:\\/|$)/);\n if (match) {\n const webhookName = match[1];\n const method = match[2];\n if (webhookName && method) {\n return { name: decodePointer(webhookName), method };\n }\n }\n\n return null;\n }\n\n /**\n * Walk through the `paths` in our OpenAPI definition and reduce down any that we know we do not\n * want to keep and accumulate any `$ref` pointers that we find that may be cross-referenced in\n * paths, webhooks, operations, and schemas that we _do_ want to keep.\n *\n */\n private walkPaths(): void {\n if (!('paths' in this.definition) || !this.definition.paths) {\n return;\n }\n\n Object.keys(this.definition.paths).forEach(path => {\n const pathLC = path.toLowerCase();\n\n // When only webhooks were requested (no path/operation filter), remove all paths.\n if (this.hasWebhooksToReduceBy && !this.hasPathsToReduceBy) {\n delete this.definition.paths?.[path];\n return;\n }\n\n if (this.hasPathsToReduceBy) {\n if (!(pathLC in this.pathsToReduceBy)) {\n delete this.definition.paths?.[path];\n return;\n }\n }\n\n Object.keys(this.definition.paths?.[path] || {}).forEach(method => {\n // Only process operations and retain any common path-level common properties like\n // `parameters`, `servers`, `summary`, etc.\n if (method === 'parameters' || !supportedMethods.includes(method.toLowerCase() as HttpMethods)) {\n return;\n }\n\n if (this.hasPathsToReduceBy) {\n // If we have paths we want to reduce but this isn't part of our filter set, then ignore.\n // We'll remove it later.\n if (\n this.pathsToReduceBy[pathLC] !== '*' &&\n Array.isArray(this.pathsToReduceBy[pathLC]) &&\n !this.pathsToReduceBy[pathLC].includes(method.toLowerCase())\n ) {\n return;\n }\n }\n\n const operation = this.definition.paths?.[path]?.[method as HttpMethods] as OperationObject;\n if (!operation) {\n throw new Error(`Operation \\`${method} ${path}\\` not found`);\n }\n\n if (this.hasTagsToReduceBy) {\n // If this endpoint either has no tags or none that we want to preseve, then prune it.\n if (!(operation.tags || []).filter(tag => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {\n return;\n }\n }\n\n (operation.tags || []).forEach((tag: string) => {\n this.usedTags.add(tag);\n });\n\n // Skipped by the `method === 'parameters'` guard above; accumulate here so refs are only\n // retained when at least one operation on this path passes all filters.\n const pathLevelParams = this.definition.paths?.[path]?.parameters;\n if (pathLevelParams) {\n this.queryForRefPointers(pathLevelParams).forEach(({ value: ref }) => {\n const refStr = this.toRefString(ref);\n if (!refStr) {\n return;\n }\n\n this.$refs.add(refStr);\n this.accumulateUsedRefs(this.definition, this.$refs, refStr);\n });\n }\n\n this.queryForRefPointers(operation).forEach(({ value: ref }) => {\n const refStr = this.toRefString(ref);\n if (!refStr) {\n return;\n }\n\n this.$refs.add(refStr);\n\n // If this operation has a cross-operation `$ref` pointer then we need to track it so\n // it's retained.\n const pathRef = this.parsePathRef(refStr);\n if (pathRef) {\n this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);\n }\n\n // Re-run through any `$ref` pointers that we found within this operation and search for\n // any `$ref` pointers that they also may be using.\n this.accumulateUsedRefs(this.definition, this.$refs, refStr);\n });\n\n Object.values(operation.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n });\n });\n }\n\n /**\n * Walk through the `webhooks` in our OpenAPI definition and reduce down any that we know we do\n * not want to keep and accumulate any `$ref` pointers that we find that may be cross-referenced\n * in paths, operations, and schemas that we _do_ want to keep.\n *\n */\n private walkWebhooks() {\n if (!isOpenAPI31(this.definition)) {\n return;\n } else if (!('webhooks' in this.definition) || !this.definition.webhooks) {\n return;\n }\n\n const definition = this.definition satisfies OpenAPIV3_1.Document;\n\n Object.keys(definition.webhooks || {}).forEach(webhookName => {\n const nameLC = webhookName.toLowerCase();\n if (this.hasWebhooksToReduceBy && !(nameLC in this.webhooksToReduceBy)) {\n return;\n }\n\n const webhook = definition.webhooks?.[webhookName];\n if (!webhook || typeof webhook !== 'object') {\n return;\n }\n\n Object.keys(webhook).forEach(method => {\n // Only process operations and retain any common path-level common properties like\n // `parameters`, `servers`, `summary`, etc.\n if (method === 'parameters' || !supportedMethods.includes(method.toLowerCase() as HttpMethods)) {\n return;\n }\n\n if (this.hasWebhooksToReduceBy) {\n // If we have webhooks we want to reduce but this isn't part of our filter set, then\n // ignore. We'll remove it later.\n const methodFilter = this.webhooksToReduceBy[nameLC];\n if (methodFilter !== '*' && Array.isArray(methodFilter) && !methodFilter.includes(method.toLowerCase())) {\n return;\n }\n }\n\n /**\n * If this webhook path item is a `$ref` then ignore it.\n * @fixme we should better support reducing this.\n */\n if (isRef(webhook)) {\n return;\n }\n\n const operation = webhook[method as HttpMethods] as OperationObject;\n if (!operation) {\n return;\n }\n\n if (this.hasTagsToReduceBy) {\n // If this operation either has no tags or none that we want to preseve, then prune it.\n if (!(operation.tags || []).filter(tag => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {\n return;\n }\n }\n\n (operation.tags || []).forEach((tag: string) => {\n this.usedTags.add(tag);\n });\n\n // Skipped by the `method === 'parameters'` guard above; accumulate here so refs are only\n // retained when at least one operation on this webhook passes all filters.\n if (webhook.parameters) {\n this.queryForRefPointers(webhook.parameters).forEach(({ value: ref }) => {\n const refStr = this.toRefString(ref);\n if (!refStr) {\n return;\n }\n\n this.$refs.add(refStr);\n this.accumulateUsedRefs(definition, this.$refs, refStr);\n });\n }\n\n this.queryForRefPointers(operation).forEach(({ value: ref }) => {\n const refStr = this.toRefString(ref);\n if (!refStr) {\n return;\n }\n\n this.$refs.add(refStr);\n const pathRef = this.parsePathRef(refStr);\n if (pathRef) {\n this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);\n }\n\n const webhookRef = this.parseWebhookRef(refStr);\n if (webhookRef) {\n this.retainWebhookMethods.add(`${webhookRef.name.toLowerCase()}|${webhookRef.method.toLowerCase()}`);\n }\n\n this.accumulateUsedRefs(definition, this.$refs, refStr);\n });\n\n Object.values(operation.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n });\n });\n }\n\n /**\n * Prune back our `paths` object in the OpenAPI definition to only include paths that we want to\n * preserve.\n *\n */\n private reducePaths(): void {\n if (!('paths' in this.definition) || !this.definition.paths) {\n return;\n }\n\n Object.keys(this.definition.paths).forEach(path => {\n const pathLC = path.toLowerCase();\n\n if (this.hasPathsToReduceBy && !(pathLC in this.pathsToReduceBy)) {\n delete this.definition.paths?.[path];\n return;\n }\n\n Object.keys(this.definition.paths?.[path] || {}).forEach(method => {\n const methodLC = method.toLowerCase();\n\n // Only process operations and retain any common path-level common properties like\n // `parameters`, `servers`, `summary`, etc.\n if (method === 'parameters' || !supportedMethods.includes(methodLC as HttpMethods)) {\n return;\n }\n\n const retainedByRef =\n this.retainPathMethods.has(`${pathLC}|${methodLC}`) ||\n Array.from(this.$refs).some(ref => {\n const pathRef = this.parsePathRef(ref);\n return pathRef?.path.toLowerCase() === pathLC && pathRef?.method.toLowerCase() === methodLC;\n });\n\n if (methodLC !== 'parameters') {\n // If we're reducing paths and this operation isn't part of our filter set, and it's\n // not a cross-referenced operation that we want to retain, then we should prune it.\n if (this.hasPathsToReduceBy) {\n if (\n !retainedByRef &&\n this.pathsToReduceBy[pathLC] !== '*' &&\n Array.isArray(this.pathsToReduceBy[pathLC]) &&\n !this.pathsToReduceBy[pathLC].includes(methodLC)\n ) {\n delete this.definition.paths?.[path]?.[method as HttpMethods];\n return;\n }\n }\n }\n\n const operation = this.definition.paths?.[path]?.[method as HttpMethods];\n if (!operation) {\n throw new Error(`Operation \\`${method} ${path}\\` not found`);\n }\n\n // If we're reducing by tags and this operation doesn't live in one of those, remove it.\n if (this.hasTagsToReduceBy) {\n // If this operation doesn't have any tags that we want to preserve, and it isn't\n // cross-referenced from an operation we _do_ want to preserve, then remove it.\n if (!(operation.tags || []).filter(tag => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {\n if (!retainedByRef) {\n delete this.definition.paths?.[path]?.[method as HttpMethods];\n }\n\n return;\n }\n }\n\n // Accumulate a list of used tags so we can filter out any ones that we don't need later.\n if ('tags' in operation) {\n operation.tags?.forEach((tag: string) => {\n this.usedTags.add(tag);\n });\n }\n\n // Accumulate any used operation-level security schemas that we need to retain.\n if ('security' in operation) {\n Object.values(operation.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n }\n });\n\n // If this path no longer has any methods, delete it.\n if (!Object.keys(this.definition.paths?.[path] || {}).length) {\n delete this.definition.paths?.[path];\n }\n });\n\n // If we don't have any more paths after cleanup, and we don't have any webhooks, then throw\n // an error because an OpenAPI definition must have at least one path.\n if (!Object.keys(this.definition.paths || {}).length) {\n if (!(this.definition.webhooks && Object.keys(this.definition.webhooks).length)) {\n throw new Error(\n 'All paths in the API definition were removed. Did you supply the right path name to reduce by?',\n );\n }\n\n delete this.definition.paths;\n }\n }\n\n /**\n * Prune back our `webhooks` object in the OpenAPI definition to only include webhooks that we\n * want to preserve.\n *\n */\n private reduceWebhooks(): void {\n if (!isOpenAPI31(this.definition)) {\n return;\n } else if (!('webhooks' in this.definition) || !this.definition.webhooks) {\n return;\n }\n\n const definition = this.definition satisfies OpenAPIV3_1.Document;\n\n Object.keys(definition.webhooks || {}).forEach(webhookName => {\n const nameLC = webhookName.toLowerCase();\n if (this.hasWebhooksToReduceBy && !(nameLC in this.webhooksToReduceBy)) {\n const retainedByRef = Array.from(this.retainWebhookMethods).some(\n key => key.startsWith(`${nameLC}|`) || key === `${nameLC}|`,\n );\n\n if (!retainedByRef) {\n delete definition.webhooks?.[webhookName];\n return;\n }\n }\n\n const webhook = definition.webhooks?.[webhookName];\n if (!webhook || typeof webhook !== 'object') {\n return;\n }\n\n /**\n * If this webhook path item is a `$ref` then ignore it.\n * @fixme we should better support reducing this.\n */\n if (isRef(webhook)) {\n return;\n }\n\n Object.keys(webhook).forEach(method => {\n const methodLC = method.toLowerCase();\n if (method === 'parameters' || !supportedMethods.includes(methodLC as HttpMethods)) {\n return;\n }\n\n const retainedByRef = this.retainWebhookMethods.has(`${nameLC}|${methodLC}`);\n if (this.hasWebhooksToReduceBy && !retainedByRef) {\n const methodFilter = this.webhooksToReduceBy[nameLC];\n if (methodFilter !== '*' && Array.isArray(methodFilter) && !methodFilter.includes(methodLC)) {\n /**\n * If this webhook path item is a `$ref` then ignore and retain it.\n * @fixme we should better support reducing this.\n */\n if (!definition.webhooks?.[webhookName] || isRef(definition.webhooks?.[webhookName])) {\n return;\n }\n\n delete definition.webhooks?.[webhookName]?.[method as HttpMethods];\n }\n }\n });\n\n if (!Object.keys(definition.webhooks?.[webhookName] || {}).length) {\n delete definition.webhooks?.[webhookName];\n }\n });\n\n if (definition.webhooks && !Object.keys(definition.webhooks).length) {\n delete definition.webhooks;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAGA,OAAO,iBAAiB;AAOjB,IAAM,iBAAN,MAAM,gBAAe;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,QAAqB,oBAAI,IAAI;AAAA;AAAA;AAAA;AAAA,EAK7B,WAAwB,oBAAI,IAAI;AAAA;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AY;AACpC,YAAI,WAAW,gBAAgB,CAAC,iBAAiB,SAAS,QAAuB,GAAG;AAClF;AAAA,QACF;AAEA,cAAM,gBAAgB,KAAK,qBAAqB,IAAI,GAAG,MAAM,IAAI,QAAQ,EAAE;AAC3E,YAAI,KAAK,yBAAyB,CAAC,eAAe;AAChD,gBAAM,eAAe,KAAK,mBAAmB,MAAM;AACnD,cAAI,iBAAiB,OAAO,MAAM,QAAQ,YAAY,KAAK,CAAC,aAAa,SAAS,QAAQ,GAAG;AAK3F,gBAAI,CAAC,WAAW,WAAW,WAAW,KAAK,MAAM,WAAW,WAAW,WAAW,CAAC,GAAG;AACpF;AAAA,YACF;AAEA,mBAAO,WAAW,WAAW,WAAW,IAAI,MAAqB;AAAA,UACnE;AAAA,QACF;AAAA,MACF,CAAC;AAED,UAAI,CAAC,OAAO,KAAK,WAAW,WAAW,WAAW,KAAK,CAAC,CAAC,EAAE,QAAQ;AACjE,eAAO,WAAW,WAAW,WAAW;AAAA,MAC1C;AAAA,IACF,CAAC;AAED,QAAI,WAAW,YAAY,CAAC,OAAO,KAAK,WAAW,QAAQ,EAAE,QAAQ;AACnE,aAAO,WAAW;AAAA,IACpB;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/reducer/index.ts"],"sourcesContent":["import type { ComponentsObject, HttpMethods, OASDocument, OperationObject, TagObject } from '../types.js';\nimport type { OpenAPIV3_1 } from 'openapi-types';\n\nimport jsonPointer from 'jsonpointer';\n\nimport { query } from '../analyzer/util.js';\nimport { decodePointer } from '../lib/refs.js';\nimport { isOpenAPI31, isRef } from '../types.js';\nimport { supportedMethods } from '../utils.js';\n\nexport class OpenAPIReducer {\n private definition: OASDocument;\n\n /**\n * A collection of `$ref` pointers that are used within our reduced API definition. This is used\n * to ensure that all referenced schemas are retained in our resulting API definition. Not\n * retaining them would result in an invalid OpenAPI definition.\n */\n private $refs: Set<string> = new Set();\n\n /**\n * A collection of OpenAPI tags that are used within our reduced API definition.\n */\n private usedTags: Set<string> = new Set();\n\n /**\n * A collection of OpenAPI paths and operations that are cross-referenced from any other paths\n * and operations that we are reducing. This collection is used in order to ensure that those\n * schemas are retained with our resulting API definition. Not retaining them would result in an\n * invalid OpenAPI definition.\n */\n private retainPathMethods: Set<`${string}|${string}`> = new Set();\n\n /**\n * A collection of OpenAPI webhook names and methods that are cross-referenced from any other\n * schemas. This collection, like `retainPathMethods`, is used in order to ensure that those\n * schemas are retained with our resulting API definition. Not retaining them would result in an\n * invalid OpenAPI definition.\n */\n private retainWebhookMethods: Set<`${string}|${string}`> = new Set();\n\n /**\n * An array of OpenAPI tags to reduce down to.\n */\n private tagsToReduceBy: string[] = [];\n\n /**\n * A collection of OpenAPI paths and operations to reduce down to.\n */\n private pathsToReduceBy: Record<string, '*' | string[]> = {};\n\n /**\n * A collection of OpenAPI webhooks to reduce down to.\n */\n private webhooksToReduceBy: Record<string, '*' | string[]> = {};\n\n private hasTagsToReduceBy: boolean = false;\n private hasPathsToReduceBy: boolean = false;\n private hasWebhooksToReduceBy: boolean = false;\n\n private constructor(definition: OASDocument) {\n this.definition = structuredClone(definition);\n }\n\n /**\n * Initialize a new instance of the `OpenAPIReducer`. The reducer allows you to reduce an OpenAPI\n * definition down to only the information necessary to fulfill a specific set of tags, paths,\n * operations, and webhooks.\n *\n * OpenAPI reduction can be helpful not only to isolate and troubleshoot issues with large API\n * definitions, but also to compress a large API definition down to a manageable size containing\n * a specific set of items.\n *\n * All OpenAPI definitions reduced will still be fully functional and valid OpenAPI definitions.\n *\n * @param definition An OpenAPI definition to reduce.\n */\n static init(definition: OASDocument): OpenAPIReducer {\n return new OpenAPIReducer(definition);\n }\n\n /**\n * Mark an OpenAPI tag to be included in our reduced API definition. Tag casing does not matter.\n *\n * @param tag The tag to mark for reduction.\n */\n byTag(tag: string): OpenAPIReducer {\n this.tagsToReduceBy.push(tag.toLowerCase());\n return this;\n }\n\n /**\n * Mark an entire OpenAPI path, and all methods that it contains, to be included in your reduced\n * API definition. Path casing does not matter.\n *\n * @param path The path to mark for reduction.\n */\n byPath(path: string): OpenAPIReducer {\n this.pathsToReduceBy[path.toLowerCase()] = '*';\n return this;\n }\n\n /**\n * Mark a single OpenAPI operation to be included in your reduced API definition. If the path\n * that this operation is a part of utilizes common parameters, those will be automatically\n * included. Path and method casing does not matter.\n *\n * Note that if you previously called `.byPath()` to reduce an entire path down, calling\n * `.byOperation()` will override that to just reduce this specific method (or this plus\n * subsequent calls to `.byOperation()`).\n *\n * @param path The path that the operation is a part of.\n * @param method The HTTP method of the operation to mark for reduction.\n *\n */\n byOperation(path: string, method: string): OpenAPIReducer {\n const pathLC = path.toLowerCase(); // Casing should not matter.\n const methodLC = method.toLowerCase();\n\n if (this.pathsToReduceBy[pathLC] && Array.isArray(this.pathsToReduceBy[pathLC])) {\n this.pathsToReduceBy[pathLC].push(methodLC);\n } else {\n this.pathsToReduceBy[pathLC] = [methodLC];\n }\n\n return this;\n }\n\n /**\n * Mark an OpenAPI webhook (and all of its operations) to be included in your reduced API\n * definition. Casing does not matter.\n *\n * @param webhookName The webhook name to mark for reduction.\n */\n byWebhook(webhookName: string): OpenAPIReducer;\n\n /**\n * Mark a single OpenAPI webhook operation to be included in your reduced API definition.\n * Casing does not matter.\n *\n * @param webhookName The webhook name that the operation belongs to.\n * @param method The HTTP method of the webhook operation to mark for reduction.\n */\n byWebhook(webhookName: string, method: string): OpenAPIReducer;\n\n byWebhook(webhookName: string, method?: string): OpenAPIReducer {\n const nameLC = webhookName.toLowerCase();\n if (!method) {\n this.webhooksToReduceBy[nameLC] = '*';\n return this;\n }\n\n const methodLC = method.toLowerCase();\n if (this.webhooksToReduceBy[nameLC] && Array.isArray(this.webhooksToReduceBy[nameLC])) {\n this.webhooksToReduceBy[nameLC].push(methodLC);\n } else {\n this.webhooksToReduceBy[nameLC] = [methodLC];\n }\n\n return this;\n }\n\n /**\n * Reduce the current OpenAPI definition down to the configured filters.\n *\n */\n reduce(): OASDocument {\n if (!this.definition.openapi) {\n throw new Error('Sorry, only OpenAPI definitions are supported.');\n }\n\n this.hasPathsToReduceBy = Boolean(Object.keys(this.pathsToReduceBy).length);\n this.hasWebhooksToReduceBy = Boolean(Object.keys(this.webhooksToReduceBy).length);\n this.hasTagsToReduceBy = Boolean(this.tagsToReduceBy.length);\n\n // Retain any root-level security definitions, regardless if they're used or not on our reduced\n // operations.\n if ('security' in this.definition) {\n Object.values(this.definition.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n }\n\n this.walkPaths();\n this.walkWebhooks();\n\n // Recursively accumulate any components that are in use.\n this.$refs.forEach($ref => {\n this.accumulateUsedRefs(this.definition, this.$refs, $ref);\n });\n\n this.$refs.forEach(ref => {\n const usedPathRef = this.parsePathRef(ref);\n if (usedPathRef) {\n this.retainPathMethods.add(`${usedPathRef.path.toLowerCase()}|${usedPathRef.method.toLowerCase()}`);\n }\n\n const usedWebhookRef = this.parseWebhookRef(ref);\n if (usedWebhookRef) {\n this.retainWebhookMethods.add(`${usedWebhookRef.name.toLowerCase()}|${usedWebhookRef.method.toLowerCase()}`);\n }\n });\n\n this.reducePaths();\n this.reduceWebhooks();\n\n // Require at least one path or one webhook in the result.\n const hasPaths = Boolean(this.definition.paths && Object.keys(this.definition.paths).length);\n const hasWebhooks = Boolean(\n 'webhooks' in this.definition && this.definition.webhooks && Object.keys(this.definition.webhooks).length,\n );\n\n if (!hasPaths && !hasWebhooks) {\n throw new Error(\n 'All paths and webhooks in the API definition were removed. Did you supply the right path, operation, or webhook to reduce by?',\n );\n }\n\n // Remove any unused components.\n if ('components' in this.definition) {\n Object.keys(this.definition.components || {}).forEach(componentType => {\n Object.keys(this.definition.components?.[componentType as keyof ComponentsObject] || {}).forEach(component => {\n // If our `$ref` either is a full, or deep match, then we should preserve it.\n const refIsUsed =\n this.$refs.has(`#/components/${componentType}/${component}`) ||\n Array.from(this.$refs).some(ref => {\n // Because you can have a `$ref` like `#/components/examples/event-min/value`, which\n // would be accumulated via our `$refs` query, we want to make sure we account for them.\n // If we don't look for these then we'll end up removing them from the overall reduced\n // definition, resulting in data loss and schema corruption.\n return ref.startsWith(`#/components/${componentType}/${component}/`);\n });\n\n if (!refIsUsed) {\n delete this.definition.components?.[componentType as keyof ComponentsObject]?.[component];\n }\n });\n\n // If this component group is now empty, delete it.\n if (!Object.keys(this.definition.components?.[componentType as keyof ComponentsObject] || {}).length) {\n delete this.definition.components?.[componentType as keyof ComponentsObject];\n }\n });\n\n // If this path no longer has any components, delete it.\n if (!Object.keys(this.definition.components || {}).length) {\n delete this.definition.components;\n }\n }\n\n // Remove any unused tags.\n if ('tags' in this.definition) {\n this.definition.tags = (this.definition.tags ?? []).filter((tag): tag is TagObject => {\n return Boolean(tag) && this.usedTags.has(tag.name);\n });\n\n if (!this.definition.tags?.length) {\n delete this.definition.tags;\n }\n }\n\n return this.definition;\n }\n\n /**\n * Recursively process a `$ref` pointer and accumulate any other `$ref` pointers that it or its\n * children use. This handles circular references by skipping `$ref` pointers we have already seen.\n * Additionally when a `$ref` points to `#/paths` we record the used path + method so we can\n * retain cross-operation references within the reduced definition.\n *\n * @param schema JSON Schema object to look for and accumulate any `$ref` pointers that it may have.\n * @param $refs Known set of `$ref` pointers.\n * @param $ref `$ref` pointer to fetch a schema from out of the supplied schema.\n */\n private accumulateUsedRefs(schema: Record<string, unknown>, $refs: Set<string>, $ref: string): void {\n // Record `$ref` pointers aimed at `#/paths` so we can retain any cross-operation references.\n const pathRef = this.parsePathRef($ref);\n if (pathRef) {\n this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);\n }\n\n const webhookRef = this.parseWebhookRef($ref);\n if (webhookRef) {\n this.retainWebhookMethods.add(`${webhookRef.name.toLowerCase()}|${webhookRef.method.toLowerCase()}`);\n }\n\n let $refSchema: unknown;\n if (typeof $ref === 'string') $refSchema = jsonPointer.get(schema, $ref.substring(1));\n if ($refSchema === undefined) {\n // If the schema we have wasn't fully dereferenced or bundled for whatever reason and this\n // `$ref` that we have doesn't exist here we shouldn't try to search for more `$ref` pointers\n // in a schema that doesn't exist.\n return;\n }\n\n this.queryForRefPointers($refSchema).forEach(({ value: currRef }) => {\n // Because it's possible to have a schema property named `$ref` that is not a `$ref` pointer,\n // which our JSONPath query would pick up as a false positive, we want to exclude that from\n // `$ref` matching as it's not a reference pointer.\n const foundRef = this.toRefString(currRef);\n if (!foundRef) {\n return;\n }\n\n // If we've already processed this `$ref` then don't send us into an infinite loop of processing\n // circular references.\n if ($refs.has(foundRef)) {\n return;\n }\n\n $refs.add(foundRef);\n this.accumulateUsedRefs(schema, $refs, foundRef);\n });\n }\n\n /**\n * Query a JSON Schema object for any `$ref` pointers using JSONPath and return any pointers that\n * exist.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc9535}\n * @param schema JSON Schema object to look for any `$ref` pointers within it.\n */\n private queryForRefPointers(schema: any) {\n return query([\"$..['$ref']\"], schema);\n }\n\n /**\n * Normalize a value from a `jsonpath-plus` `$ref` query to a `$ref` pointer because JSONPath\n * queries may return the property value or the parent.\n *\n */\n private toRefString(value: unknown): string | null {\n if (typeof value === 'string') {\n return value;\n } else if (value && typeof value === 'object' && '$ref' in value && typeof value.$ref === 'string') {\n return value.$ref;\n }\n\n return null;\n }\n\n /**\n * If the given `$ref` points into a path (e.g. `#/paths/~1anything/post/...`), return the path\n * and method so the reducer can ultimately retain cross-operation references.\n *\n */\n private parsePathRef($ref: string): { path: string; method: string } | null {\n if (typeof $ref !== 'string' || !$ref.startsWith('#/paths/')) {\n return null;\n }\n\n // Extract path segment and method: `#/paths/<pathSegment>/<method>/...`\n const match = $ref.match(/^#\\/paths\\/([^/]+)\\/([^/]+)(?:\\/|$)/);\n if (match) {\n const pathSegment = match[1];\n const method = match[2];\n if (pathSegment && method) {\n return { path: decodePointer(pathSegment), method };\n }\n }\n\n return null;\n }\n\n /**\n * If the given `$ref` points into webhooks (e.g. `#/webhooks/newBooking/post/...`), return the\n * webhook name and method so the reducer can retain cross-referenced webhook operations.\n *\n */\n private parseWebhookRef($ref: string): { name: string; method: string } | null {\n if (typeof $ref !== 'string' || !$ref.startsWith('#/webhooks/')) {\n return null;\n }\n\n // Extract path segment and method: `#/webhooks/<webhookName>/<method>/...`\n const match = $ref.match(/^#\\/webhooks\\/([^/]+)\\/([^/]+)(?:\\/|$)/);\n if (match) {\n const webhookName = match[1];\n const method = match[2];\n if (webhookName && method) {\n return { name: decodePointer(webhookName), method };\n }\n }\n\n return null;\n }\n\n /**\n * Walk through the `paths` in our OpenAPI definition and reduce down any that we know we do not\n * want to keep and accumulate any `$ref` pointers that we find that may be cross-referenced in\n * paths, webhooks, operations, and schemas that we _do_ want to keep.\n *\n */\n private walkPaths(): void {\n if (!('paths' in this.definition) || !this.definition.paths) {\n return;\n }\n\n Object.keys(this.definition.paths).forEach(path => {\n const pathLC = path.toLowerCase();\n\n // When only webhooks were requested (no path/operation filter), remove all paths.\n if (this.hasWebhooksToReduceBy && !this.hasPathsToReduceBy) {\n delete this.definition.paths?.[path];\n return;\n }\n\n if (this.hasPathsToReduceBy) {\n if (!(pathLC in this.pathsToReduceBy)) {\n delete this.definition.paths?.[path];\n return;\n }\n }\n\n Object.keys(this.definition.paths?.[path] || {}).forEach(method => {\n // Only process operations and retain any common path-level common properties like\n // `parameters`, `servers`, `summary`, etc.\n if (method === 'parameters' || !supportedMethods.includes(method.toLowerCase() as HttpMethods)) {\n return;\n }\n\n if (this.hasPathsToReduceBy) {\n // If we have paths we want to reduce but this isn't part of our filter set, then ignore.\n // We'll remove it later.\n if (\n this.pathsToReduceBy[pathLC] !== '*' &&\n Array.isArray(this.pathsToReduceBy[pathLC]) &&\n !this.pathsToReduceBy[pathLC].includes(method.toLowerCase())\n ) {\n return;\n }\n }\n\n const operation = this.definition.paths?.[path]?.[method as HttpMethods] as OperationObject;\n if (!operation) {\n throw new Error(`Operation \\`${method} ${path}\\` not found`);\n }\n\n if (this.hasTagsToReduceBy) {\n // If this endpoint either has no tags or none that we want to preseve, then prune it.\n if (!(operation.tags || []).filter(tag => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {\n return;\n }\n }\n\n (operation.tags || []).forEach((tag: string) => {\n this.usedTags.add(tag);\n });\n\n // Skipped by the `method === 'parameters'` guard above; accumulate here so refs are only\n // retained when at least one operation on this path passes all filters.\n const pathLevelParams = this.definition.paths?.[path]?.parameters;\n if (pathLevelParams) {\n this.queryForRefPointers(pathLevelParams).forEach(({ value: ref }) => {\n const refStr = this.toRefString(ref);\n if (!refStr) {\n return;\n }\n\n this.$refs.add(refStr);\n this.accumulateUsedRefs(this.definition, this.$refs, refStr);\n });\n }\n\n this.queryForRefPointers(operation).forEach(({ value: ref }) => {\n const refStr = this.toRefString(ref);\n if (!refStr) {\n return;\n }\n\n this.$refs.add(refStr);\n\n // If this operation has a cross-operation `$ref` pointer then we need to track it so\n // it's retained.\n const pathRef = this.parsePathRef(refStr);\n if (pathRef) {\n this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);\n }\n\n // Re-run through any `$ref` pointers that we found within this operation and search for\n // any `$ref` pointers that they also may be using.\n this.accumulateUsedRefs(this.definition, this.$refs, refStr);\n });\n\n Object.values(operation.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n });\n });\n }\n\n /**\n * Walk through the `webhooks` in our OpenAPI definition and reduce down any that we know we do\n * not want to keep and accumulate any `$ref` pointers that we find that may be cross-referenced\n * in paths, operations, and schemas that we _do_ want to keep.\n *\n */\n private walkWebhooks() {\n if (!isOpenAPI31(this.definition)) {\n return;\n } else if (!('webhooks' in this.definition) || !this.definition.webhooks) {\n return;\n }\n\n const definition = this.definition satisfies OpenAPIV3_1.Document;\n\n Object.keys(definition.webhooks || {}).forEach(webhookName => {\n const nameLC = webhookName.toLowerCase();\n if (this.hasWebhooksToReduceBy && !(nameLC in this.webhooksToReduceBy)) {\n return;\n }\n\n const webhook = definition.webhooks?.[webhookName];\n if (!webhook || typeof webhook !== 'object') {\n return;\n }\n\n Object.keys(webhook).forEach(method => {\n // Only process operations and retain any common path-level common properties like\n // `parameters`, `servers`, `summary`, etc.\n if (method === 'parameters' || !supportedMethods.includes(method.toLowerCase() as HttpMethods)) {\n return;\n }\n\n if (this.hasWebhooksToReduceBy) {\n // If we have webhooks we want to reduce but this isn't part of our filter set, then\n // ignore. We'll remove it later.\n const methodFilter = this.webhooksToReduceBy[nameLC];\n if (methodFilter !== '*' && Array.isArray(methodFilter) && !methodFilter.includes(method.toLowerCase())) {\n return;\n }\n }\n\n /**\n * If this webhook path item is a `$ref` then ignore it.\n * @fixme we should better support reducing this.\n */\n if (isRef(webhook)) {\n return;\n }\n\n const operation = webhook[method as HttpMethods] as OperationObject;\n if (!operation) {\n return;\n }\n\n if (this.hasTagsToReduceBy) {\n // If this operation either has no tags or none that we want to preseve, then prune it.\n if (!(operation.tags || []).filter(tag => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {\n return;\n }\n }\n\n (operation.tags || []).forEach((tag: string) => {\n this.usedTags.add(tag);\n });\n\n // Skipped by the `method === 'parameters'` guard above; accumulate here so refs are only\n // retained when at least one operation on this webhook passes all filters.\n if (webhook.parameters) {\n this.queryForRefPointers(webhook.parameters).forEach(({ value: ref }) => {\n const refStr = this.toRefString(ref);\n if (!refStr) {\n return;\n }\n\n this.$refs.add(refStr);\n this.accumulateUsedRefs(definition, this.$refs, refStr);\n });\n }\n\n this.queryForRefPointers(operation).forEach(({ value: ref }) => {\n const refStr = this.toRefString(ref);\n if (!refStr) {\n return;\n }\n\n this.$refs.add(refStr);\n const pathRef = this.parsePathRef(refStr);\n if (pathRef) {\n this.retainPathMethods.add(`${pathRef.path.toLowerCase()}|${pathRef.method.toLowerCase()}`);\n }\n\n const webhookRef = this.parseWebhookRef(refStr);\n if (webhookRef) {\n this.retainWebhookMethods.add(`${webhookRef.name.toLowerCase()}|${webhookRef.method.toLowerCase()}`);\n }\n\n this.accumulateUsedRefs(definition, this.$refs, refStr);\n });\n\n Object.values(operation.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n });\n });\n }\n\n /**\n * Prune back our `paths` object in the OpenAPI definition to only include paths that we want to\n * preserve.\n *\n */\n private reducePaths(): void {\n if (!('paths' in this.definition) || !this.definition.paths) {\n return;\n }\n\n Object.keys(this.definition.paths).forEach(path => {\n const pathLC = path.toLowerCase();\n\n if (this.hasPathsToReduceBy && !(pathLC in this.pathsToReduceBy)) {\n delete this.definition.paths?.[path];\n return;\n }\n\n Object.keys(this.definition.paths?.[path] || {}).forEach(method => {\n const methodLC = method.toLowerCase();\n\n // Only process operations and retain any common path-level common properties like\n // `parameters`, `servers`, `summary`, etc.\n if (method === 'parameters' || !supportedMethods.includes(methodLC as HttpMethods)) {\n return;\n }\n\n const retainedByRef =\n this.retainPathMethods.has(`${pathLC}|${methodLC}`) ||\n Array.from(this.$refs).some(ref => {\n const pathRef = this.parsePathRef(ref);\n return pathRef?.path.toLowerCase() === pathLC && pathRef?.method.toLowerCase() === methodLC;\n });\n\n if (methodLC !== 'parameters') {\n // If we're reducing paths and this operation isn't part of our filter set, and it's\n // not a cross-referenced operation that we want to retain, then we should prune it.\n if (this.hasPathsToReduceBy) {\n if (\n !retainedByRef &&\n this.pathsToReduceBy[pathLC] !== '*' &&\n Array.isArray(this.pathsToReduceBy[pathLC]) &&\n !this.pathsToReduceBy[pathLC].includes(methodLC)\n ) {\n delete this.definition.paths?.[path]?.[method as HttpMethods];\n return;\n }\n }\n }\n\n const operation = this.definition.paths?.[path]?.[method as HttpMethods];\n if (!operation) {\n throw new Error(`Operation \\`${method} ${path}\\` not found`);\n }\n\n // If we're reducing by tags and this operation doesn't live in one of those, remove it.\n if (this.hasTagsToReduceBy) {\n // If this operation doesn't have any tags that we want to preserve, and it isn't\n // cross-referenced from an operation we _do_ want to preserve, then remove it.\n if (!(operation.tags || []).filter(tag => this.tagsToReduceBy.includes(tag.toLowerCase())).length) {\n if (!retainedByRef) {\n delete this.definition.paths?.[path]?.[method as HttpMethods];\n }\n\n return;\n }\n }\n\n // Accumulate a list of used tags so we can filter out any ones that we don't need later.\n if ('tags' in operation) {\n operation.tags?.forEach((tag: string) => {\n this.usedTags.add(tag);\n });\n }\n\n // Accumulate any used operation-level security schemas that we need to retain.\n if ('security' in operation) {\n Object.values(operation.security || {}).forEach(sec => {\n Object.keys(sec).forEach(scheme => {\n this.$refs.add(`#/components/securitySchemes/${scheme}`);\n });\n });\n }\n });\n\n // If this path no longer has any methods, delete it.\n if (!Object.keys(this.definition.paths?.[path] || {}).length) {\n delete this.definition.paths?.[path];\n }\n });\n\n // If we don't have any more paths after cleanup, and we don't have any webhooks, then throw\n // an error because an OpenAPI definition must have at least one path.\n if (!Object.keys(this.definition.paths || {}).length) {\n if (!(this.definition.webhooks && Object.keys(this.definition.webhooks).length)) {\n throw new Error(\n 'All paths in the API definition were removed. Did you supply the right path name to reduce by?',\n );\n }\n\n delete this.definition.paths;\n }\n }\n\n /**\n * Prune back our `webhooks` object in the OpenAPI definition to only include webhooks that we\n * want to preserve.\n *\n */\n private reduceWebhooks(): void {\n if (!isOpenAPI31(this.definition)) {\n return;\n } else if (!('webhooks' in this.definition) || !this.definition.webhooks) {\n return;\n }\n\n const definition = this.definition satisfies OpenAPIV3_1.Document;\n\n Object.keys(definition.webhooks || {}).forEach(webhookName => {\n const nameLC = webhookName.toLowerCase();\n if (this.hasWebhooksToReduceBy && !(nameLC in this.webhooksToReduceBy)) {\n const retainedByRef = Array.from(this.retainWebhookMethods).some(\n key => key.startsWith(`${nameLC}|`) || key === `${nameLC}|`,\n );\n\n if (!retainedByRef) {\n delete definition.webhooks?.[webhookName];\n return;\n }\n }\n\n const webhook = definition.webhooks?.[webhookName];\n if (!webhook || typeof webhook !== 'object') {\n return;\n }\n\n /**\n * If this webhook path item is a `$ref` then ignore it.\n * @fixme we should better support reducing this.\n */\n if (isRef(webhook)) {\n return;\n }\n\n Object.keys(webhook).forEach(method => {\n const methodLC = method.toLowerCase();\n if (method === 'parameters' || !supportedMethods.includes(methodLC as HttpMethods)) {\n return;\n }\n\n const retainedByRef = this.retainWebhookMethods.has(`${nameLC}|${methodLC}`);\n if (this.hasWebhooksToReduceBy && !retainedByRef) {\n const methodFilter = this.webhooksToReduceBy[nameLC];\n if (methodFilter !== '*' && Array.isArray(methodFilter) && !methodFilter.includes(methodLC)) {\n /**\n * If this webhook path item is a `$ref` then ignore and retain it.\n * @fixme we should better support reducing this.\n */\n if (!definition.webhooks?.[webhookName] || isRef(definition.webhooks?.[webhookName])) {\n return;\n }\n\n delete definition.webhooks?.[webhookName]?.[method as HttpMethods];\n }\n }\n });\n\n if (!Object.keys(definition.webhooks?.[webhookName] || {}).length) {\n delete definition.webhooks?.[webhookName];\n }\n });\n\n if (definition.webhooks && !Object.keys(definition.webhooks).length) {\n delete definition.webhooks;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAGA,OAAO,iBAAiB;AAOjB,IAAM,iBAAN,MAAM,gBAAe;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,QAAqB,oBAAI,IAAI;AAAA;AAAA;AAAA;AAAA,EAK7B,WAAwB,oBAAI,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQhC,oBAAgD,oBAAI,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQxD,uBAAmD,oBAAI,IAAI;AAAA;AAAA;AAAA;AAAA,EAK3D,iBAA2B,CAAC;AAAA;AAAA;AAAA;AAAA,EAK5B,kBAAkD,CAAC;AAAA;AAAA;AAAA;AAAA,EAKnD,qBAAqD,CAAC;AAAA,EAEtD,oBAA6B;AAAA,EAC7B,qBAA8B;AAAA,EAC9B,wBAAiC;AAAA,EAEjC,YAAY,YAAyB;AAC3C,SAAK,aAAa,gBAAgB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AAG;AACpF;AAAA,YACF;AAEA,mBAAO,WAAW,WAAW,WAAW,IAAI,MAAqB;AAAA,UACnE;AAAA,QACF;AAAA,MACF,CAAC;AAED,UAAI,CAAC,OAAO,KAAK,WAAW,WAAW,WAAW,KAAK,CAAC,CAAC,EAAE,QAAQ;AACjE,eAAO,WAAW,WAAW,WAAW;AAAA,MAC1C;AAAA,IACF,CAAC;AAED,QAAI,WAAW,YAAY,CAAC,OAAO,KAAK,WAAW,QAAQ,EAAE,QAAQ;AACnE,aAAO,WAAW;AAAA,IACpB;AAAA,EACF;AACF;","names":[]}
|
package/dist/utils.cjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkSAB2PGCDcjs = require('./chunk-SAB2PGCD.cjs');
|
|
9
9
|
require('./chunk-AYA3UT4L.cjs');
|
|
10
10
|
require('./chunk-3MTU2ESP.cjs');
|
|
11
11
|
|
|
@@ -15,5 +15,5 @@ require('./chunk-3MTU2ESP.cjs');
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
exports.SERVER_VARIABLE_REGEX =
|
|
18
|
+
exports.SERVER_VARIABLE_REGEX = _chunkSAB2PGCDcjs.SERVER_VARIABLE_REGEX; exports.dereferenceRef = _chunkSAB2PGCDcjs.dereferenceRef; exports.getParameterContentType = _chunkSAB2PGCDcjs.getParameterContentType; exports.jsonSchemaTypes = _chunkSAB2PGCDcjs.types; exports.matchesMimeType = _chunkSAB2PGCDcjs.matches_mimetype_default; exports.supportedMethods = _chunkSAB2PGCDcjs.supportedMethods;
|
|
19
19
|
//# sourceMappingURL=utils.cjs.map
|
package/dist/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oas",
|
|
3
|
-
"version": "32.1.
|
|
3
|
+
"version": "32.1.13",
|
|
4
4
|
"description": "Comprehensive tooling for working with OpenAPI definitions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ReadMe <support@readme.io> (https://readme.com)",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
86
|
"@apidevtools/json-schema-ref-parser": "^14.1.1",
|
|
87
|
-
"@readme/openapi-parser": "
|
|
87
|
+
"@readme/openapi-parser": "6.0.1",
|
|
88
88
|
"@types/json-schema": "^7.0.11",
|
|
89
89
|
"json-schema-merge-allof": "^0.8.1",
|
|
90
90
|
"jsonpath-plus": "^10.4.0",
|
|
@@ -95,16 +95,14 @@
|
|
|
95
95
|
"remove-undefined-objects": "^7.0.0"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
|
-
"@readme/oas-examples": "
|
|
98
|
+
"@readme/oas-examples": "file:../oas-examples",
|
|
99
99
|
"@types/json-schema-merge-allof": "^0.6.5",
|
|
100
100
|
"@types/memoizee": "^0.4.12",
|
|
101
101
|
"@types/node": "^25.3.0",
|
|
102
|
-
"jest-expect-jsonschema": "
|
|
103
|
-
"jest-expect-openapi": "
|
|
102
|
+
"jest-expect-jsonschema": "file:../jest-expect-jsonschema",
|
|
103
|
+
"jest-expect-openapi": "file:../jest-expect-openapi",
|
|
104
104
|
"tsup": "^8.5.0",
|
|
105
105
|
"typescript": "^5.4.4",
|
|
106
106
|
"vitest": "^4.0.8"
|
|
107
|
-
}
|
|
108
|
-
"prettier": "@readme/standards/prettier",
|
|
109
|
-
"gitHead": "c6614f66e1404b08f71ec510fa92bb150391b537"
|
|
107
|
+
}
|
|
110
108
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/lib/get-auth.ts","../src/lib/get-user-variable.ts","../src/lib/urls.ts"],"sourcesContent":["import type { OpenAPIV3_1 } from 'openapi-types';\nimport type { Extensions } from './extensions.js';\nimport type { PathMatch, PathMatches } from './lib/urls.js';\nimport type {\n AuthForHAR,\n HttpMethods,\n OASDocument,\n OperationObject,\n SecuritySchemeObject,\n ServerObject,\n Servers,\n ServerVariable,\n ServerVariablesObject,\n User,\n} from './types.js';\n\nimport { dereference } from '@readme/openapi-parser';\n\nimport {\n CODE_SAMPLES,\n extensionDefaults,\n getExtension,\n HEADERS,\n hasRootExtension,\n OAUTH_OPTIONS,\n PARAMETER_ORDERING,\n SAMPLES_LANGUAGES,\n validateParameterOrdering,\n} from './extensions.js';\nimport { getAuth } from './lib/get-auth.js';\nimport getUserVariable from './lib/get-user-variable.js';\nimport { decorateComponentSchemasWithRefName, dereferenceRef, getDereferencingOptions } from './lib/refs.js';\nimport {\n filterPathMethods,\n findTargetPath,\n generatePathMatches,\n normalizedURL,\n stripTrailingSlash,\n transformURLIntoRegex,\n} from './lib/urls.js';\nimport { Operation, Webhook } from './operation/index.js';\nimport { isOpenAPI31, isRef } from './types.js';\nimport { SERVER_VARIABLE_REGEX, supportedMethods } from './utils.js';\n\n// biome-ignore lint/style/noDefaultExport: This file doesn't have any other exports so this is fine.\nexport default class Oas {\n /**\n * The current OpenAPI definition.\n */\n api: OASDocument;\n\n /**\n * The current user that we should use when pulling auth tokens from security schemes.\n */\n user: User;\n\n /**\n * Internal storage array that the library utilizes to keep track of the times the\n * {@see Oas.dereference} has been called so that if you initiate multiple promises they'll all\n * 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 /**\n * @param oas An OpenAPI definition.\n * @param user The information about a user that we should use when pulling auth tokens from\n * security schemes.\n */\n constructor(oas: OASDocument | string, user?: User) {\n if (typeof oas === 'string') {\n this.api = (JSON.parse(oas) || {}) as OASDocument;\n } else {\n this.api = oas || ({} as OASDocument);\n }\n\n this.user = user || {};\n\n this.promises = [];\n this.dereferencing = {\n processing: false,\n complete: false,\n circularRefs: [],\n };\n }\n\n /**\n * This will initialize a new instance of the `Oas` class. This method is useful if you're using\n * Typescript and are attempting to supply an untyped JSON object into `Oas` as it will force-type\n * that object to an `OASDocument` for you.\n *\n * @param oas An OpenAPI definition.\n * @param user The information about a user that we should use when pulling auth tokens from\n * security schemes.\n */\n static init(oas: OASDocument | Record<string, unknown>, user?: User): Oas {\n return new Oas(oas as OASDocument, user);\n }\n\n /**\n * Retrieve the OpenAPI version that this API definition is targeted for.\n */\n getVersion(): string {\n if (this.api.openapi) {\n return this.api.openapi;\n }\n\n throw new Error('Unable to recognize what specification version this API definition conforms to.');\n }\n\n /**\n * Retrieve the current OpenAPI API Definition.\n *\n */\n getDefinition(): OASDocument {\n return this.api;\n }\n\n url(selected = 0, variables?: ServerVariable): string {\n const url = normalizedURL(this.api, selected);\n return this.replaceUrl(url, variables || this.defaultVariables(selected)).trim();\n }\n\n variables(selected = 0): ServerVariablesObject {\n return this.api.servers?.[selected]?.variables || {};\n }\n\n defaultVariables(selected = 0): ServerVariable {\n const variables = this.variables(selected);\n const defaults: ServerVariable = {};\n\n Object.keys(variables).forEach(key => {\n defaults[key] = getUserVariable(this.user, key) || variables[key].default || '';\n });\n\n return defaults;\n }\n\n splitUrl(selected = 0): (\n | {\n /**\n * A unique key, where the `value` is concatenated to its index\n */\n key: string;\n type: 'text';\n value: string;\n }\n | {\n /**\n * An optional description for the server variable.\n *\n * @see {@link https://spec.openapis.org/oas/v3.1.0#fixed-fields-4}\n */\n description?: string;\n\n /**\n * An enumeration of string values to be used if the substitution options are from a limited set.\n *\n * @see {@link https://spec.openapis.org/oas/v3.1.0#fixed-fields-4}\n */\n enum?: string[];\n\n /**\n * A unique key, where the `value` is concatenated to its index\n */\n key: string;\n type: 'variable';\n value: string;\n }\n )[] {\n const url = normalizedURL(this.api, selected);\n const variables = this.variables(selected);\n\n return url\n .split(/({.+?})/)\n .filter(Boolean)\n .map((part, i) => {\n const isVariable = part.match(/[{}]/);\n const value = part.replace(/[{}]/g, '');\n // To ensure unique keys, we're going to create a key\n // with the value concatenated to its index.\n const key = `${value}-${i}`;\n\n if (!isVariable) {\n return {\n type: 'text',\n value,\n key,\n };\n }\n\n const variable = variables?.[value];\n\n return {\n type: 'variable',\n value,\n key,\n description: variable?.description,\n enum: variable?.enum,\n };\n });\n }\n\n /**\n * With a fully composed server URL, run through our list of known OAS servers and return back\n * which server URL was selected along with any contained server variables split out.\n *\n * For example, if you have an OAS server URL of `https://{name}.example.com:{port}/{basePath}`,\n * and pass in `https://buster.example.com:3000/pet` to this function, you'll get back the\n * following:\n *\n * { selected: 0, variables: { name: 'buster', port: 3000, basePath: 'pet' } }\n *\n * Re-supplying this data to `oas.url()` should return the same URL you passed into this method.\n *\n * @param baseUrl A given URL to extract server variables out of.\n */\n splitVariables(baseUrl: string): Servers | false {\n const matchedServer = (this.api.servers || [])\n .map((server, i) => {\n const rgx = transformURLIntoRegex(server.url);\n const found = new RegExp(rgx).exec(baseUrl);\n if (!found) {\n return false;\n }\n\n // While it'd be nice to use named regex groups to extract path parameters from the URL and\n // match them up with the variables that we have present in it, JS unfortunately doesn't\n // support having the groups duplicated. So instead of doing that we need to re-regex the\n // server URL, this time splitting on the path parameters -- this way we'll be able to\n // extract the parameter names and match them up with the matched server that we obtained\n // above.\n const variables: Record<string, number | string> = {};\n Array.from(server.url.matchAll(SERVER_VARIABLE_REGEX)).forEach((variable, y) => {\n variables[variable[1]] = found[y + 1];\n });\n\n return {\n selected: i,\n variables,\n };\n })\n .filter(item => item !== false);\n\n return matchedServer.length ? matchedServer[0] : false;\n }\n\n /**\n * Replace templated variables with supplied data in a given URL.\n *\n * There are a couple ways that this will utilize variable data:\n *\n * - Supplying a `variables` object. If this is supplied, this data will always take priority.\n * This incoming `variables` object can be two formats:\n * `{ variableName: { default: 'value' } }` and `{ variableName: 'value' }`. If the former is\n * present, that will take precedence over the latter.\n * - If the supplied `variables` object is empty or does not match the current template name,\n * we fallback to the data stored in `this.user` and attempt to match against that.\n * See `getUserVariable` for some more information on how this data is pulled from `this.user`.\n *\n * If no variables supplied match up with the template name, the template name will instead be\n * used as the variable data.\n *\n * @param url A URL to swap variables into.\n * @param variables An object containing variables to swap into the URL.\n */\n replaceUrl(url: string, variables: ServerVariable = {}): string {\n // When we're constructing URLs, server URLs with trailing slashes cause problems with doing\n // lookups, so if we have one here on, slice it off.\n return stripTrailingSlash(\n url.replace(SERVER_VARIABLE_REGEX, (original: string, key: string) => {\n if (key in variables) {\n const data = variables[key];\n if (typeof data === 'object') {\n if (!Array.isArray(data) && data !== null && 'default' in data) {\n return String(data.default);\n }\n } else {\n return String(data);\n }\n }\n\n const userVariable = getUserVariable(this.user, key);\n if (userVariable) {\n return String(userVariable);\n }\n\n return original;\n }),\n );\n }\n\n /**\n * Retrieve an Operation of Webhook class instance for a given path and method.\n *\n * @param path Path to lookup and retrieve.\n * @param method HTTP Method to retrieve on the path.\n */\n operation(\n path: string,\n method: HttpMethods,\n opts: {\n /**\n * If you prefer to first look for a webhook with this path and method.\n */\n isWebhook?: boolean;\n } = {},\n ): Operation {\n // If we're unable to locate an operation for this path+method combination within the API\n // definition, we should still set an empty schema on the operation in the `Operation` class\n // because if we don't trying to use any of the accessors on that class are going to fail as\n // `schema` will be `undefined`.\n let operation: OperationObject = {\n parameters: [],\n };\n\n if (opts.isWebhook) {\n if (isOpenAPI31(this.api)) {\n const webhookPath = dereferenceRef(this.api?.webhooks?.[path], this.api);\n if (webhookPath && !isRef(webhookPath)) {\n if (webhookPath?.[method]) {\n operation = webhookPath[method];\n return new Webhook(this, path, method, operation);\n }\n }\n }\n }\n\n if (this?.api?.paths?.[path]) {\n const pathItem = dereferenceRef(this.api.paths[path], this.api);\n if (pathItem?.[method]) {\n operation = dereferenceRef(pathItem[method], this.api);\n }\n }\n\n return new Operation(this, path, method, operation);\n }\n\n findOperationMatches(url: string): PathMatches | undefined {\n const { origin, hostname } = new URL(url);\n const originRegExp = new RegExp(origin, 'i');\n const { servers, paths } = this.api;\n\n let pathName: string | undefined;\n let targetServer: ServerObject | undefined;\n let matchedServer: ServerObject | undefined;\n\n if (!servers || !servers.length) {\n // If this API definition doesn't have any servers set up let's treat it as if it were\n // https://example.com because that's the default origin we add in `normalizedUrl` under the\n // same circumstances. Without this we won't be able to match paths within what is otherwise\n // a valid OpenAPI definition.\n matchedServer = {\n url: 'https://example.com',\n };\n } else {\n matchedServer = servers.find(s => originRegExp.exec(this.replaceUrl(s.url, s.variables || {})));\n if (!matchedServer) {\n const hostnameRegExp = new RegExp(hostname);\n matchedServer = servers.find(s => hostnameRegExp.exec(this.replaceUrl(s.url, s.variables || {})));\n }\n }\n\n if (matchedServer) {\n // Instead of setting `url` directly against `matchedServer` we need to set it to an\n // intermediary object as directly modifying `matchedServer.url` will in turn update\n // `this.servers[idx].url` which we absolutely do not want to happen.\n targetServer = {\n ...matchedServer,\n url: this.replaceUrl(matchedServer.url, matchedServer.variables || {}),\n };\n\n [, pathName] = url.split(new RegExp(targetServer.url, 'i'));\n }\n\n // If we **still** haven't found a matching server, then the OAS server URL might have server\n // variables and we should loosen it up with regex to try to discover a matching path.\n //\n // For example if an OAS has `https://{region}.node.example.com/v14` set as its server URL, and\n // the `this.user` object has a `region` value of `us`, if we're trying to locate an operation\n // for https://eu.node.example.com/v14/api/esm we won't be able to because normally the users\n // `region` of `us` will be transposed in and we'll be trying to locate `eu.node.example.com`\n // in `us.node.example.com` -- which won't work.\n //\n // So what this does is transform `https://{region}.node.example.com/v14` into\n // `https://([-_a-zA-Z0-9[\\\\]]+).node.example.com/v14`, and from there we'll be able to match\n // https://eu.node.example.com/v14/api/esm and ultimately find the operation matches for\n // `/api/esm`.\n if (!matchedServer || !pathName) {\n const matchedServerAndPath = (servers || [])\n .map(server => {\n const rgx = transformURLIntoRegex(server.url);\n const found = new RegExp(rgx).exec(url);\n if (!found) {\n return undefined;\n }\n\n return {\n matchedServer: server,\n pathName: url.split(new RegExp(rgx)).slice(-1).pop(),\n };\n })\n .filter((item): item is { matchedServer: ServerObject; pathName: string | undefined } => item !== undefined);\n\n if (!matchedServerAndPath.length) {\n return undefined;\n }\n\n pathName = matchedServerAndPath[0].pathName;\n targetServer = {\n ...matchedServerAndPath[0].matchedServer,\n };\n }\n\n if (pathName === undefined) return undefined;\n if (pathName === '') pathName = '/';\n if (!paths || !targetServer) return undefined;\n const annotatedPaths = generatePathMatches(paths, pathName, targetServer.url);\n if (!annotatedPaths.length) return undefined;\n\n return annotatedPaths;\n }\n\n /**\n * Discover an operation in an OAS from a fully-formed URL and HTTP method. Will return an object\n * containing a `url` object and another one for `operation`. This differs from `getOperation()`\n * in that it does not return an instance of the `Operation` class.\n *\n * @param url A full URL to look up.\n * @param method The cooresponding HTTP method to look up.\n */\n findOperation(url: string, method: HttpMethods): PathMatch | undefined {\n const annotatedPaths = this.findOperationMatches(url);\n if (!annotatedPaths) {\n return undefined;\n }\n\n const matches = filterPathMethods(annotatedPaths, method);\n if (!matches.length) return undefined;\n return findTargetPath(matches);\n }\n\n /**\n * Discover an operation in an OAS from a fully-formed URL without an HTTP method. Will return an\n * object containing a `url` object and another one for `operation`.\n *\n * @param url A full URL to look up.\n */\n findOperationWithoutMethod(url: string): PathMatch | undefined {\n const annotatedPaths = this.findOperationMatches(url);\n if (!annotatedPaths) {\n return undefined;\n }\n\n return findTargetPath(annotatedPaths);\n }\n\n /**\n * Retrieve an operation in an OAS from a fully-formed URL and HTTP method. Differs from\n * `findOperation` in that while this method will return an `Operation` instance,\n * `findOperation()` does not.\n *\n * @param url A full URL to look up.\n * @param method The cooresponding HTTP method to look up.\n */\n getOperation(url: string, method: HttpMethods): Operation | undefined {\n const op = this.findOperation(url, method);\n if (op === undefined) {\n return undefined;\n }\n\n return this.operation(op.url.nonNormalizedPath, method);\n }\n\n /**\n * Retrieve an operation in an OAS by an `operationId`.\n *\n * If an operation does not have an `operationId` one will be generated in place, using the\n * default behavior of `Operation.getOperationId()`, and then asserted against your query.\n *\n * Note that because `operationId`s are unique that uniqueness does include casing so the ID\n * you are looking for will be asserted as an exact match.\n *\n * @see {Operation.getOperationId()}\n * @param id The `operationId` to look up.\n */\n getOperationById(id: string): Operation | Webhook | undefined {\n let found: Operation | Webhook | undefined;\n\n Object.values(this.getPaths()).forEach(operations => {\n if (found) return;\n found = Object.values(operations).find(operation => operation.getOperationId() === id);\n });\n\n if (found) {\n return found;\n }\n\n Object.entries(this.getWebhooks()).forEach(([, webhooks]) => {\n if (found) return;\n found = Object.values(webhooks).find(webhook => webhook.getOperationId() === id);\n });\n\n return found;\n }\n\n /**\n * With an object of user information, retrieve the appropriate API auth keys from the current\n * OAS definition.\n *\n * @see {@link https://docs.readme.com/docs/passing-data-to-jwt}\n * @param user User\n * @param selectedApp The user app to retrieve an auth key for.\n */\n getAuth(user: User, selectedApp?: number | string): AuthForHAR {\n if (!this.api?.components?.securitySchemes) {\n return {};\n }\n\n return getAuth(this.api, user, selectedApp);\n }\n\n /**\n * Determine if a security scheme exists within the API definition.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#security-scheme-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#security-scheme-object}\n * @param name The name of the security scheme to check for.\n */\n hasSecurityScheme(name: string): boolean {\n return Boolean(this.api?.components?.securitySchemes?.[name]);\n }\n\n /**\n * Retrieve a security scheme from the API definition.\n *\n * If the found security scheme is a `$ref` pointer it will be lazily dereferenced; if the scheme\n * cannot be resolved after that process (eg. it's circular or is an invalid `$ref`) then\n * `undefined` will be returned.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#security-scheme-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#security-scheme-object}\n * @param name The name of the security scheme to retrieve.\n */\n getSecurityScheme(name: string): SecuritySchemeObject | undefined {\n if (!this.hasSecurityScheme(name)) {\n return undefined;\n }\n\n let scheme = this.api?.components?.securitySchemes?.[name];\n if (!scheme) return undefined;\n if (isRef(scheme)) {\n scheme = dereferenceRef(scheme, this.api);\n if (!scheme || isRef(scheme)) return undefined;\n }\n\n return scheme;\n }\n\n /**\n * Returns the `paths` object that exists in this API definition but with every `method` mapped\n * to an instance of the `Operation` class.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#openapi-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-object}\n */\n getPaths(): Record<string, Record<HttpMethods, Operation | Webhook>> {\n const paths: Record<string, Record<HttpMethods, Operation | Webhook>> = {};\n if (!this.api.paths) {\n return paths;\n }\n\n Object.keys(this.api.paths).forEach(path => {\n // If this is a specification extension then we should ignore it.\n if (path.startsWith('x-')) {\n return;\n }\n\n paths[path] = {} as Record<HttpMethods, Operation | Webhook>;\n\n // biome-ignore-start lint/style/noNonNullAssertion: We're guaranteed to have `api.paths[path]` from the `.keys()` loop.\n let pathItem = this.api.paths![path];\n if (!pathItem) {\n return;\n } else if (isRef(pathItem)) {\n // Though this library is generally unaware of `$ref` pointers we're making a singular\n // exception with this accessor out of convenience.\n this.api.paths![path] = dereferenceRef(pathItem, this.api);\n pathItem = this.api.paths![path];\n if (!pathItem || isRef(pathItem)) {\n return;\n }\n }\n\n Object.keys(pathItem).forEach(method => {\n /**\n * Because a path doesn't need to contain a keyed-object of HTTP methods, we should exclude\n * anything from within the paths object that isn't a known HTTP method.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#fixed-fields-7}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#fixed-fields-7}\n */\n if (!supportedMethods.includes(method as HttpMethods)) {\n return;\n }\n\n paths[path][method as HttpMethods] = this.operation(path, method as HttpMethods);\n });\n // biome-ignore-end lint/style/noNonNullAssertion: --end--\n });\n\n return paths;\n }\n\n /**\n * Returns the `webhooks` object that exists in this API definition but with every `method`\n * mapped to an instance of the `Webhook` class.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#openapi-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-object}\n */\n getWebhooks(): Record<string, Record<HttpMethods, Webhook>> {\n const webhooks: Record<string, Record<HttpMethods, Webhook>> = {};\n if (!isOpenAPI31(this.api) || !this.api.webhooks) {\n return webhooks;\n }\n\n Object.keys(this.api.webhooks).forEach(id => {\n webhooks[id] = {} as Record<HttpMethods, Webhook>;\n\n const webhookPath = dereferenceRef((this.api as OpenAPIV3_1.Document).webhooks?.[id], this.api);\n if (webhookPath) {\n Object.keys(webhookPath).forEach(method => {\n if (!supportedMethods.includes(method as HttpMethods)) {\n return;\n }\n\n webhooks[id][method as HttpMethods] = this.operation(id, method as HttpMethods, {\n isWebhook: true,\n }) as Webhook;\n });\n }\n });\n\n return webhooks;\n }\n\n /**\n * Return an array of all tag names that exist on this API definition.\n *\n * If the API definition uses the `x-disable-tag-sorting` extension then tags will be returned in\n * the order they're defined.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#openapi-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-object}\n * @param setIfMissing If a tag is not present on an operation that operations path will be added\n * into the list of tags returned.\n */\n getTags(setIfMissing = false): string[] {\n const allTags = new Set<string>();\n\n const oasTags = this.api.tags?.map(tag => tag.name) || [];\n\n const disableTagSorting = getExtension('disable-tag-sorting', this.api);\n\n Object.entries(this.getPaths()).forEach(([path, operations]) => {\n Object.values(operations).forEach(operation => {\n const tags = operation.getTags();\n if (setIfMissing && !tags.length) {\n allTags.add(path);\n return;\n }\n\n tags.forEach(tag => {\n allTags.add(tag.name);\n });\n });\n });\n\n Object.entries(this.getWebhooks()).forEach(([path, webhooks]) => {\n Object.values(webhooks).forEach(webhook => {\n const tags = webhook.getTags();\n if (setIfMissing && !tags.length) {\n allTags.add(path);\n return;\n }\n\n tags.forEach(tag => {\n allTags.add(tag.name);\n });\n });\n });\n\n // Tags that exist only on the endpoint\n const endpointTags: string[] = [];\n // Tags that the user has defined in the `tags` array\n const tagsArray: string[] = [];\n\n // Distinguish between which tags exist in the `tags` array and which tags\n // exist only at the endpoint level. For tags that exist only at the\n // endpoint level, we'll just tack that on to the end of the sorted tags.\n if (disableTagSorting) {\n return Array.from(allTags);\n }\n\n Array.from(allTags).forEach(tag => {\n if (oasTags.includes(tag)) {\n tagsArray.push(tag);\n } else {\n endpointTags.push(tag);\n }\n });\n\n let sortedTags = tagsArray.sort((a, b) => {\n return oasTags.indexOf(a) - oasTags.indexOf(b);\n });\n\n sortedTags = sortedTags.concat(endpointTags);\n\n return sortedTags;\n }\n\n /**\n * Determine if a given a custom specification extension exists within the API definition.\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 hasRootExtension(extension, this.api);\n }\n\n /**\n * Retrieve a custom specification extension off of the API definition.\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 getExtension(extension: string | keyof Extensions, operation?: Operation): any {\n return getExtension(extension, this.api, operation);\n }\n\n /**\n * Determine if a given OpenAPI custom extension is valid or not.\n *\n * @see {@link https://docs.readme.com/docs/openapi-extensions}\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 validate.\n * @throws\n */\n validateExtension(extension: keyof Extensions): void {\n if (this.hasExtension('x-readme')) {\n const data = this.getExtension('x-readme') satisfies Extensions;\n if (typeof data !== 'object' || Array.isArray(data) || data === null) {\n throw new TypeError('\"x-readme\" must be of type \"Object\"');\n }\n\n if (extension in data) {\n if ([CODE_SAMPLES, HEADERS, PARAMETER_ORDERING, SAMPLES_LANGUAGES].includes(extension)) {\n if (data[extension] !== undefined) {\n if (!Array.isArray(data[extension])) {\n throw new TypeError(`\"x-readme.${extension}\" must be of type \"Array\"`);\n }\n\n if (extension === PARAMETER_ORDERING) {\n validateParameterOrdering(data[extension], `x-readme.${extension}`);\n }\n }\n } else if (extension === OAUTH_OPTIONS) {\n if (typeof data[extension] !== 'object') {\n throw new TypeError(`\"x-readme.${extension}\" must be of type \"Object\"`);\n }\n } else if (typeof data[extension] !== 'boolean') {\n throw new TypeError(`\"x-readme.${extension}\" must be of type \"Boolean\"`);\n }\n }\n }\n\n // If the extension isn't grouped under `x-readme`, we need to look for them with `x-` prefixes.\n if (this.hasExtension(`x-${extension}`)) {\n const data = this.getExtension(`x-${extension}`);\n if ([CODE_SAMPLES, HEADERS, PARAMETER_ORDERING, SAMPLES_LANGUAGES].includes(extension)) {\n if (!Array.isArray(data)) {\n throw new TypeError(`\"x-${extension}\" must be of type \"Array\"`);\n }\n\n if (extension === PARAMETER_ORDERING) {\n validateParameterOrdering(data, `x-${extension}`);\n }\n } else if (extension === OAUTH_OPTIONS) {\n if (typeof data !== 'object') {\n throw new TypeError(`\"x-${extension}\" must be of type \"Object\"`);\n }\n } else if (typeof data !== 'boolean') {\n throw new TypeError(`\"x-${extension}\" must be of type \"Boolean\"`);\n }\n }\n }\n\n /**\n * Validate all of our custom or known OpenAPI extensions, throwing exceptions when necessary.\n *\n * @see {@link https://docs.readme.com/docs/openapi-extensions}\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 */\n validateExtensions(): void {\n Object.keys(extensionDefaults).forEach(extension => {\n this.validateExtension(extension as keyof Extensions);\n });\n }\n\n /**\n * Dereference the current API definition so it can be parsed free from the hassle of resolving\n * `$ref` schemas 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 new Promise(resolve => {\n resolve(true);\n });\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 if (!this.schemasDecorated) {\n decorateComponentSchemasWithRefName(this.api);\n this.schemasDecorated = true;\n }\n\n const { api, promises } = this;\n\n const circularRefs: Set<string> = new Set();\n const dereferencingOptions = getDereferencingOptions(circularRefs);\n\n return dereference<OASDocument>(api, dereferencingOptions)\n .then((dereferenced: OASDocument) => {\n this.api = dereferenced;\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 API definition has been dereferenced or not.\n *\n * @see Oas.dereference\n */\n isDereferenced(): boolean {\n return this.dereferencing.processing || this.dereferencing.complete;\n }\n\n /**\n * Retrieve any circular `$ref` pointers that maybe present within the API definition.\n *\n * This method requires that you first dereference the definition.\n *\n * @see Oas.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","import type { AuthForHAR, KeyedSecuritySchemeObject, OASDocument, User } from '../types.js';\n\nimport { isRef } from '../types.js';\nimport { dereferenceRef } from './refs.js';\n\ntype authKey = unknown | { password: number | string; user: number | string } | null;\n\n/**\n * @param user User to retrieve retrieve an auth key for.\n * @param scheme The type of security scheme that we want a key for.\n */\nfunction getKey(user: User, scheme: KeyedSecuritySchemeObject): authKey {\n switch (scheme.type) {\n case 'oauth2':\n case 'apiKey':\n return user[scheme._key] || user.apiKey || scheme['x-default'] || null;\n\n case 'http':\n if (scheme.scheme === 'basic') {\n return user[scheme._key] || { user: user.user || null, pass: user.pass || null };\n }\n\n if (scheme.scheme === 'bearer') {\n return user[scheme._key] || user.apiKey || scheme['x-default'] || null;\n }\n return null;\n\n default:\n return null;\n }\n}\n\n/**\n * Retrieve auth keys for a specific security scheme for a given user for a specific \"app\" that\n * they have configured.\n *\n * For `scheme` we're typing it to a union of `SecurityScheme` and `any` because we have handling\n * and tests for an unknown or unrecognized `type` and though it's not possible with the\n * `SecurityScheme.type` to be unrecognized it may still be possible to get an unrecognized scheme\n * with this method in the wild as we have API definitions in our database that were ingested\n * before we had good validation in place.\n *\n * @param user User\n * @param scheme Security scheme to get auth keys for.\n * @param selectedApp The user app to retrieve an auth key for.\n */\nexport function getByScheme(\n user: User,\n scheme = {} as KeyedSecuritySchemeObject,\n selectedApp?: number | string,\n): authKey {\n if (user?.keys?.length) {\n if (selectedApp) {\n const userKey = user.keys.find(k => k.name === selectedApp);\n if (!userKey) {\n return null;\n }\n\n return getKey(userKey, scheme);\n }\n\n return getKey(user.keys[0], scheme);\n }\n\n return getKey(user, scheme);\n}\n\n/**\n * Retrieve auth keys for an API definition from a given user for a specific \"app\" that they have\n * configured.\n *\n * @param api API definition\n * @param user User\n * @param selectedApp The user app to retrieve an auth key for.\n */\nexport function getAuth(api: OASDocument, user: User, selectedApp?: number | string): AuthForHAR {\n return Object.keys(api?.components?.securitySchemes || {})\n .map(scheme => {\n const securityScheme = dereferenceRef(api.components?.securitySchemes?.[scheme], api);\n if (!securityScheme || isRef(securityScheme)) {\n // If this security scheme is invalid or an unresolvable `$ref` pointer then we should skip\n // it.\n return false;\n }\n\n return {\n [scheme]: getByScheme(\n user,\n {\n ...securityScheme,\n _key: scheme,\n },\n selectedApp,\n ),\n };\n })\n .filter((item): item is AuthForHAR => item !== undefined)\n .reduce((prev, next) => Object.assign(prev, next), {});\n}\n","import type { User } from '../types.js';\n\n/**\n * Retrieve a user variable off of a given user.\n *\n * @see {@link https://docs.readme.com/docs/passing-data-to-jwt}\n * @param user The user to get a user variable for.\n * @param property The name of the variable to retrieve.\n * @param selectedApp The user app to retrieve an auth key for.\n */\n// biome-ignore lint/style/noDefaultExport: This is safe for now.\nexport default function getUserVariable(user: User, property: string, selectedApp?: number | string): unknown {\n let key: User | undefined = user;\n\n if ('keys' in user && Array.isArray(user.keys) && user.keys.length) {\n if (selectedApp) {\n key = user.keys.find(k => k.name === selectedApp);\n } else {\n key = user.keys[0];\n }\n }\n\n return key?.[property] || user[property] || null;\n}\n","import type { Match, ParamData } from 'path-to-regexp';\nimport type { HttpMethods, OASDocument, PathsObject } from '../types';\n\nimport { match, pathToRegexp } from 'path-to-regexp';\n\nimport { SERVER_VARIABLE_REGEX } from '../utils';\n\nexport interface PathMatch {\n match?: Match<ParamData>;\n operation: PathsObject;\n url: {\n method?: HttpMethods;\n nonNormalizedPath: string;\n origin: string;\n path: string;\n slugs: Record<string, string>;\n };\n}\n\nexport type PathMatches = PathMatch[];\n\nexport function stripTrailingSlash(url: string): string {\n if (url[url.length - 1] === '/') {\n return url.slice(0, -1);\n }\n\n return url;\n}\n\nfunction ensureProtocol(url: string) {\n // Add protocol to urls starting with // e.g. //example.com\n // This is because httpsnippet throws a HARError when it doesnt have a protocol\n if (url.match(/^\\/\\//)) {\n return `https:${url}`;\n }\n\n // Add protocol to urls with no // within them\n // This is because httpsnippet throws a HARError when it doesnt have a protocol\n if (!url.match(/\\/\\//)) {\n return `https://${url}`;\n }\n\n return url;\n}\n\n/**\n * Normalize a OpenAPI server URL by ensuring that it has a proper HTTP protocol and doesn't have a\n * trailing slash.\n *\n * @param api The API definition that we're processing.\n * @param selected The index of the `servers` array in the API definition that we want to normalize.\n */\nexport function normalizedURL(api: OASDocument, selected: number): string {\n const exampleDotCom = 'https://example.com';\n let url: string | undefined;\n try {\n url = api.servers?.[selected].url;\n // This is to catch the case where servers = [{}]\n if (!url) throw new Error('no url');\n\n // Stripping the '/' off the end\n url = stripTrailingSlash(url);\n\n // Check if the URL is just a path a missing an origin, for example `/api/v3`. If so, then make\n // `example.com` the origin to avoid it becoming something invalid like `https:///api/v3`.\n // RM-1044\n if (url.startsWith('/') && !url.startsWith('//')) {\n const urlWithOrigin = new URL(exampleDotCom);\n urlWithOrigin.pathname = url;\n url = urlWithOrigin.href;\n }\n } catch {\n url = exampleDotCom;\n }\n\n return ensureProtocol(url);\n}\n\n/**\n * With a URL that may contain server variables, transform those server variables into regex that\n * we can query against.\n *\n * For example, when given `https://{region}.node.example.com/v14` this will return back:\n *\n * https://([-_a-zA-Z0-9:.[\\\\]]+).node.example.com/v14\n *\n * @param url URL to transform\n */\nexport function transformURLIntoRegex(url: string): string {\n return stripTrailingSlash(url.replace(SERVER_VARIABLE_REGEX, '([-_a-zA-Z0-9:.[\\\\]]+)'));\n}\n\n/**\n * Normalize a path so that we can use it with `path-to-regexp` to do operation lookups.\n *\n * @param path Path to normalize.\n */\nfunction normalizePath(path: string) {\n return (\n path\n // This regex transforms `{pathParam}` into `:pathParam` so we can regex against it. We're\n // also handling quirks here like if there's an optional proceeding or trailing curly bracket\n // (`{{pathParam}` or `{pathParam}}`) as any unescaped curlys, which would be present in\n // `:pathParam}`, will throw a regex exception.\n .replace(/({?){(.*?)}(}?)/g, (str, ...args) => {\n // If a path contains a path parameter with hyphens, like `:dlc-release`, when it's regexd\n // with `path-to-regexp` it match against the `:dlc` portion of the parameter, breaking all\n // matching against the full path.\n //\n // For example on `/games/:game/dlc/:dlc-release` the regex that's actually used to search\n // against a path like `/games/destiny-2/dlc/witch-queen` is the following:\n // /^\\/games(?:\\/([^\\/#\\?]+?))\\/dlc(?:\\/([^\\/#\\?]+?))-release[\\/#\\?]?$/i\n //\n // However if `:dlc-release` is rewritten to `:dlcrelease` we end up with a functional\n // regex: /^\\/games(?:\\/([^\\/#\\?]+?))\\/dlc(?:\\/([^\\/#\\?]+?))[\\/#\\?]?$/i.\n return `:${args[1].replace('-', '')}`;\n })\n\n // In addition to transforming `{pathParam}` into `:pathParam` we also need to escape cases\n // where a non-variabled colon is next to a variabled-colon because if we don't then\n // `path-to-regexp` won't be able to correct identify where the variable starts.\n //\n // For example if the URL is `/post/:param1::param2` we'll be escaping it to\n // `/post/:param1\\::param2`.\n .replace(/::/, '\\\\::')\n\n // We also need to escape question marks too because they're treated as regex modifiers.\n .split('?')[0]\n );\n}\n\n/**\n * Generate path matches for a given path and origin on a set of OpenAPI path objects.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#paths-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#paths-object}\n * @param paths The OpenAPI Paths Object to process.\n * @param pathName Path to look for a match.\n * @param origin The origin that we're matching against.\n */\nexport function generatePathMatches(paths: PathsObject, pathName: string, origin: string): PathMatches {\n const prunedPathName = pathName.split('?')[0];\n const matches: PathMatches = Object.keys(paths)\n .map(path => {\n const cleanedPath = normalizePath(path);\n\n let matchResult: PathMatch['match'];\n try {\n const matchStatement = match(cleanedPath, { decode: decodeURIComponent });\n matchResult = matchStatement(prunedPathName);\n } catch {\n // If path matching fails for whatever reason (maybe they have a malformed path parameter)\n // then we shouldn't also fail.\n return false;\n }\n\n const slugs: Record<string, string> = {};\n\n if (matchResult && Object.keys(matchResult.params).length) {\n Object.keys(matchResult.params).forEach(param => {\n slugs[`:${param}`] = (matchResult.params as Record<string, string>)[param];\n });\n }\n\n return {\n url: {\n origin,\n path: cleanedPath.replace(/\\\\::/, '::'),\n nonNormalizedPath: path,\n slugs,\n },\n operation: paths[path] as PathsObject,\n match: matchResult,\n } satisfies PathMatch;\n })\n .filter(item => item !== false);\n\n return matches.filter(p => p.match);\n}\n\n/**\n * @param pathMatches Array of path matches to filter down.\n * @param targetMethod HTTP method to look for.\n * @returns Filtered down path matches.\n */\nexport function filterPathMethods(pathMatches: PathMatches, targetMethod: HttpMethods): PathMatch[] {\n const regExp = pathToRegexp(targetMethod);\n return pathMatches\n .map(p => {\n const captures = Object.keys(p.operation).filter(r => regExp.regexp.exec(r));\n\n if (captures.length) {\n const method = captures[0];\n p.url.method = method.toUpperCase() as HttpMethods;\n\n return {\n url: p.url,\n operation: p.operation[method],\n };\n }\n\n return false;\n })\n .filter((item): item is PathMatch => Boolean(item));\n}\n\n/**\n * @param pathMatches URL and PathsObject matches to narrow down to find a target path.\n * @returns An object containing matches that were discovered in the API definition.\n */\nexport function findTargetPath(pathMatches: PathMatch[]): PathMatch | undefined {\n if (!pathMatches.length) {\n return undefined;\n }\n\n let minCount = Object.keys(pathMatches[0].url.slugs).length;\n let found: PathMatch | undefined;\n\n for (let m = 0; m < pathMatches.length; m += 1) {\n const selection = pathMatches[m];\n const paramCount = Object.keys(selection.url.slugs).length;\n if (paramCount <= minCount) {\n minCount = paramCount;\n found = selection;\n }\n }\n\n return found;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,SAAS,mBAAmB;;;ACL5B,SAAS,OAAO,MAAY,QAA4C;AACtE,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK;AAAA,IACL,KAAK;AACH,aAAO,KAAK,OAAO,IAAI,KAAK,KAAK,UAAU,OAAO,WAAW,KAAK;AAAA,IAEpE,KAAK;AACH,UAAI,OAAO,WAAW,SAAS;AAC7B,eAAO,KAAK,OAAO,IA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