oas 38.3.0 → 38.4.0
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/README.md +38 -4
- package/dist/chunk-4CWJNFV5.js +709 -0
- package/dist/chunk-4CWJNFV5.js.map +1 -0
- package/dist/{chunk-XXX6U72S.js → chunk-5ZBXVQYR.js} +17 -3
- package/dist/chunk-5ZBXVQYR.js.map +1 -0
- package/dist/{chunk-3ZXZMZXT.cjs → chunk-Y64TRECN.cjs} +18 -4
- package/dist/chunk-Y64TRECN.cjs.map +1 -0
- package/dist/chunk-Z2WDQGCU.cjs +709 -0
- package/dist/chunk-Z2WDQGCU.cjs.map +1 -0
- package/dist/index-Borb1VXh.d.cts +174 -0
- package/dist/index-Br-eJMCh.d.ts +174 -0
- package/dist/index.cjs +29 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +12 -5
- package/dist/index.js.map +1 -1
- package/dist/operation/index.cjs +2 -2
- package/dist/operation/index.js +1 -1
- package/dist/pruner/index.cjs +87 -0
- package/dist/pruner/index.cjs.map +1 -0
- package/dist/pruner/index.d.cts +72 -0
- package/dist/pruner/index.d.ts +72 -0
- package/dist/pruner/index.js +87 -0
- package/dist/pruner/index.js.map +1 -0
- package/dist/reducer/index.cjs +39 -520
- package/dist/reducer/index.cjs.map +1 -1
- package/dist/reducer/index.d.cts +22 -108
- package/dist/reducer/index.d.ts +22 -108
- package/dist/reducer/index.js +37 -518
- package/dist/reducer/index.js.map +1 -1
- package/package.json +6 -2
- package/dist/chunk-3ZXZMZXT.cjs.map +0 -1
- package/dist/chunk-XXX6U72S.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas/dist/chunk-Z2WDQGCU.cjs","../src/lib/transformer/index.ts","../src/lib/transformer/operation-selection.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;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;AACF,MAAA;AAEiD,MAAA;AACxB,QAAA;AACzB,MAAA;AACF,IAAA;AACF,EAAA;AAAA;AAAA;AAAA;AAKkC,EAAA;AACG,IAAA;AACjC,MAAA;AACmD,IAAA;AACnD,MAAA;AACF,IAAA;AAEwB,IAAA;AAEuB,IAAA;AACN,MAAA;AACiB,MAAA;AAEX,MAAA;AACL,QAAA;AAEnB,QAAA;AACqC,UAAA;AACxD,QAAA;AAEwC,QAAA;AACxC,QAAA;AACF,MAAA;AAEiD,MAAA;AACJ,MAAA;AAC3C,QAAA;AACF,MAAA;AAOoB,MAAA;AACE,QAAA;AACoB,UAAA;AAClB,UAAA;AACsB,YAAA;AAC1C,UAAA;AACF,QAAA;AAEA,QAAA;AACF,MAAA;AAEuB,MAAA;AACgB,MAAA;AACD,QAAA;AACa,QAAA;AAC/C,UAAA;AACF,QAAA;AAE+C,QAAA;AAC/B,QAAA;AACmC,UAAA;AACnD,QAAA;AAEuD,QAAA;AACA,QAAA;AACT,UAAA;AAChC,YAAA;AACyC,cAAA;AACnD,YAAA;AACF,UAAA;AAEoB,UAAA;AACkB,YAAA;AACjB,YAAA;AACnB,YAAA;AACF,UAAA;AACF,QAAA;AAI+C,QAAA;AAEC,QAAA;AACzB,UAAA;AACtB,QAAA;AAE+C,QAAA;AACX,UAAA;AACc,YAAA;AAChD,UAAA;AACF,QAAA;AACF,MAAA;AAGkD,MAAA;AAGT,QAAA;AAC1C,MAAA;AACD,IAAA;AAE0D,IAAA;AACvC,MAAA;AACpB,IAAA;AACF,EAAA;AACF;AD/KgE;AACA;AACA;AACA","file":"/Users/erunion/code/readme/oas/packages/oas/dist/chunk-Z2WDQGCU.cjs","sourcesContent":[null,"import type {\n ComponentsObject,\n HttpMethods,\n OASDocument,\n OperationObject,\n PathItemObject,\n TagObject,\n} from '../../types.js';\nimport type { OpenAPIV3_1 } from 'openapi-types';\n\nimport jsonPointer from 'jsonpointer';\n\nimport { query } from '../../analyzer/util.js';\nimport { Operation } from '../../operation/index.js';\nimport { isOpenAPI31, isRef } from '../../types.js';\nimport { supportedMethods } from '../../utils.js';\nimport { decodePointer } from '../refs.js';\n\nimport { OperationSelection } from './operation-selection.js';\n\ninterface OpenAPITransformerOptions {\n /** Whether selected paths, operations, and webhooks should be retained or removed. */\n mode: 'prune' | 'reduce';\n}\n\n/**\n * Internal engine for selecting operations and transforming an OpenAPI definition down to its\n * reachable paths, webhooks, components, and tags.\n */\nexport class OpenAPITransformer {\n private definition: OASDocument;\n\n private readonly mode: 'prune' | 'reduce';\n\n /**\n * A collection of `$ref` pointers that are used within our transformed API definition. This is\n * used 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 the transformed 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're retaining. This collection is used to ensure that those operations\n * are retained in our resulting API definition. Not retaining them would result in an invalid\n * 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 to ensure that those operations are\n * retained in our resulting API definition. Not retaining them would result in an invalid\n * OpenAPI definition.\n */\n private retainWebhookMethods: Set<`${string}|${string}`> = new Set();\n\n /** An array of OpenAPI tags selected for the current transformation. */\n private tagSelection: string[] = [];\n\n /** A collection of operation IDs selected for the current transformation. */\n private operationIdSelection = new Set<string>();\n\n /** A collection of OpenAPI paths and operations selected for the current transformation. */\n private pathSelection = new OperationSelection();\n\n /** A collection of OpenAPI webhooks selected for the current transformation. */\n private webhookSelection = new OperationSelection();\n\n private hasTagSelection: boolean = false;\n private hasOperationIdSelection: boolean = false;\n private hasPathSelection: boolean = false;\n private hasWebhookSelection: boolean = false;\n\n /**\n * @param definition OpenAPI definition to transform.\n * @param options Transformation mode.\n */\n protected constructor(definition: OASDocument, options: OpenAPITransformerOptions) {\n this.definition = structuredClone(definition);\n this.mode = options.mode;\n }\n\n /**\n * Select an OpenAPI tag. Operations with this tag are retained when reducing and removed when\n * pruning. Tag casing does not matter.\n *\n * @param tag Tag to select.\n */\n protected selectTag(tag: string): void {\n this.tagSelection.push(tag.toLowerCase());\n }\n\n /**\n * Select an entire OpenAPI path and all operations that it contains. Selected paths are retained\n * when reducing and removed when pruning. Path casing does not matter.\n *\n * @param path Path to select.\n */\n protected selectPath(path: string): void {\n this.pathSelection.addAll(path);\n }\n\n /**\n * Select a single OpenAPI operation. Selected operations are retained when reducing and removed\n * when pruning. Path and method casing does not matter.\n *\n * In reduce mode, selecting an operation after its entire path replaces the all-operation\n * selection with that operation and any operations selected afterward. Prune mode keeps the\n * entire path selected.\n *\n * @param path Path containing the operation.\n * @param method HTTP method of the operation to select.\n */\n protected selectOperation(path: string, method: string): void {\n if (this.mode === 'reduce' && this.pathSelection.matchesAll(path)) {\n this.pathSelection.clear(path);\n }\n\n this.pathSelection.addOperation(path, method);\n }\n\n /**\n * Select an OpenAPI operation by its operation ID. IDs are matched exactly and are generated\n * from the operation path and method when one is not authored in the definition.\n *\n * @param operationId Operation ID to select.\n */\n protected selectOperationId(operationId: string): void {\n this.operationIdSelection.add(operationId);\n }\n\n /**\n * Select an OpenAPI webhook or one of its operations. Selected webhooks are retained when\n * reducing and removed when pruning. Webhook and method casing does not matter.\n *\n * @param webhookName Webhook to select.\n * @param method Optional HTTP method of an individual webhook operation to select.\n */\n protected selectWebhook(webhookName: string, method?: string): void {\n if (!method) {\n this.webhookSelection.addAll(webhookName);\n return;\n }\n\n if (this.mode === 'reduce' && this.webhookSelection.matchesAll(webhookName)) {\n this.webhookSelection.clear(webhookName);\n }\n\n this.webhookSelection.addOperation(webhookName, method);\n }\n\n /** Transform the OpenAPI definition according to the configured mode and selections. */\n protected transform(): OASDocument {\n if (!this.definition.openapi) {\n throw new Error('Sorry, only OpenAPI definitions are supported.');\n }\n\n this.hasTagSelection = Boolean(this.tagSelection.length);\n this.hasOperationIdSelection = this.operationIdSelection.size > 0;\n this.hasPathSelection = this.pathSelection.hasSelections;\n this.hasWebhookSelection = this.webhookSelection.hasSelections;\n\n // Retain any root-level security definitions, regardless if they're used or not on operations\n // that we're retaining.\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 /**\n * @fixme Resolve referenced Path Items and expand the complete dependency set of operations and\n * Path Items retained transitively through cross-operation references before mutating paths or\n * webhooks.\n */\n this.transformPaths();\n this.transformWebhooks();\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 we don't have any paths or webhooks left, retain the reducer's no-match error to help catch\n // invalid selections. An empty definition is valid OpenAPI so we allow it when pruning.\n if (this.mode === 'reduce' && !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 transformed\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 transformed 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 transformer can 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 transformer 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 /** Determine whether a path or webhook is excluded in the current transformation mode. */\n private isContainerExcluded(selection: OperationSelection, key: string): boolean {\n if (this.mode === 'prune') {\n return selection.matchesAll(key);\n }\n\n return !selection.has(key);\n }\n\n /**\n * Determine whether an operation passes the configured filters before cross-operation references\n * are considered.\n */\n private shouldRetainOperation(\n selection: OperationSelection,\n key: string,\n method: string,\n operation: OperationObject,\n ): boolean {\n if (this.mode === 'reduce') {\n // Reduction filters intersect, so an operation must match every configured filter.\n if (selection.hasSelections && !selection.matches(key, method)) return false;\n if (\n this.hasOperationIdSelection &&\n !this.operationIdSelection.has(Operation.getOperationId(key, method, operation))\n ) {\n return false;\n }\n if (this.hasTagSelection && !(operation.tags || []).some(tag => this.tagSelection.includes(tag.toLowerCase()))) {\n return false;\n }\n } else {\n // Pruning filters are additive, so matching any configured filter removes an operation.\n if (selection.hasSelections && selection.matches(key, method)) return false;\n if (\n this.hasOperationIdSelection &&\n this.operationIdSelection.has(Operation.getOperationId(key, method, operation))\n ) {\n return false;\n }\n if (this.hasTagSelection && (operation.tags || []).some(tag => this.tagSelection.includes(tag.toLowerCase()))) {\n return false;\n }\n }\n\n // No configured filter excluded this operation, so retain it in the transformed definition.\n return true;\n }\n\n /** Determine whether a path item contains at least one HTTP operation. */\n private hasOperations(pathItem: PathItemObject | undefined): boolean {\n return Boolean(pathItem && supportedMethods.some(method => method in pathItem));\n }\n\n /**\n * Accumulate any `$ref` pointers that are used by common Path Item parameters.\n *\n * @param parameters Common Path Item parameters to inspect for `$ref` pointers.\n */\n private accumulateParameterRefs(parameters: PathItemObject['parameters'] | undefined): void {\n if (!parameters) {\n return;\n }\n\n this.queryForRefPointers(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(this.definition, this.$refs, refStr);\n });\n }\n\n /**\n * Walk through the `paths` in our OpenAPI definition and determine which operations we want to\n * retain. Accumulate any `$ref` pointers that they use so their referenced schemas can also be\n * retained in our resulting API definition.\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 // When only webhooks were requested (no path/operation filter), ignore all paths, but don't\n // delete them yet because a selected webhook may reference one of their operations. We'll\n // remove any that aren't referenced later.\n if (this.mode === 'reduce' && this.hasWebhookSelection && !this.hasPathSelection) {\n return;\n } else if (this.hasPathSelection && this.isContainerExcluded(this.pathSelection, path)) {\n return;\n }\n\n const pathItem = this.definition.paths?.[path];\n\n /**\n * Referenced Path Items that remain in the result are preserved intact rather than partially\n * transformed. Retain the target and continue walking any local sibling fields so that we\n * retain their dependencies too.\n * @fixme Resolve referenced Path Items so their operations can be transformed individually.\n */\n if (isRef(pathItem)) {\n this.$refs.add(pathItem.$ref);\n this.accumulateUsedRefs(this.definition, this.$refs, pathItem.$ref);\n }\n\n // If this Path Item has no operations then it will remain in our resulting API definition,\n // so we need to retain any components referenced by its common parameters.\n if (!this.hasOperations(pathItem)) {\n this.accumulateParameterRefs(pathItem?.parameters);\n }\n\n Object.keys(pathItem || {}).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 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 operation isn't part of our resulting API definition then ignore it. We'll\n // remove it later.\n if (!this.shouldRetainOperation(this.pathSelection, path, method, operation)) {\n return;\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 this.accumulateParameterRefs(pathItem?.parameters);\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 determine which operations we want\n * to retain. Accumulate any `$ref` pointers that they use so their referenced schemas can also be\n * retained in our resulting API definition.\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 if (this.hasWebhookSelection && this.isContainerExcluded(this.webhookSelection, webhookName)) {\n return;\n }\n\n const webhook: PathItemObject | undefined = definition.webhooks?.[webhookName];\n if (!webhook || typeof webhook !== 'object') {\n return;\n }\n\n /**\n * Referenced webhook Path Items that remain in the result are preserved intact rather than\n * partially transformed. Retain the target and continue walking any local sibling fields so\n * that we retain their dependencies too.\n * @fixme Resolve referenced Path Items so their operations can be transformed individually.\n */\n if (typeof webhook.$ref === 'string') {\n this.$refs.add(webhook.$ref);\n this.accumulateUsedRefs(definition, this.$refs, webhook.$ref);\n }\n\n // If this webhook has no operations then it will remain in our resulting API definition, so\n // we need to retain any components referenced by its common parameters.\n if (!this.hasOperations(webhook)) {\n this.accumulateParameterRefs(webhook.parameters);\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 const operation = webhook[method as HttpMethods] as OperationObject;\n if (!operation) {\n throw new Error(`Webhook operation \\`${method} ${webhookName}\\` not found`);\n }\n\n // If this operation isn't part of our resulting API definition then ignore it. We'll\n // remove it later.\n if (!this.shouldRetainOperation(this.webhookSelection, webhookName, method, operation)) {\n return;\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 this.accumulateParameterRefs(webhook.parameters);\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 * Transform our `paths` object according to the paths and operations that we've selected.\n */\n private transformPaths(): 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 const excludePathItem =\n (this.hasPathSelection && this.isContainerExcluded(this.pathSelection, path)) ||\n (this.mode === 'reduce' && this.hasWebhookSelection && !this.hasPathSelection);\n\n if (this.mode === 'prune' && excludePathItem) {\n if (Array.from(this.retainPathMethods).some(key => key.startsWith(`${pathLC}|`))) {\n throw new Error(`Cannot remove path \\`${path}\\` because one of its operations is referenced.`);\n }\n\n delete this.definition.paths?.[path];\n return;\n }\n\n const pathItem = this.definition.paths?.[path];\n\n /**\n * Referenced Path Items are preserved intact during operation-level filtering. If the whole\n * Path Item is excluded, remove it unless a surviving operation references it.\n * @fixme Resolve referenced Path Items so their operations can be transformed individually.\n */\n if (isRef(pathItem)) {\n if (excludePathItem) {\n const retainedByRef = Array.from(this.retainPathMethods).some(key => key.startsWith(`${pathLC}|`));\n if (!retainedByRef) {\n delete this.definition.paths?.[path];\n }\n }\n\n return;\n }\n\n let removedOperation = false;\n Object.keys(pathItem || {}).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 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 (excludePathItem || !this.shouldRetainOperation(this.pathSelection, path, method, operation)) {\n if (this.mode === 'prune' && retainedByRef) {\n throw new Error(`Cannot remove operation \\`${method.toUpperCase()} ${path}\\` because it is referenced.`);\n }\n\n if (!retainedByRef) {\n delete this.definition.paths?.[path]?.[method as HttpMethods];\n removedOperation = true;\n return;\n }\n }\n\n // This operation remains in the transformed definition, so retain any components\n // referenced by its common Path Item parameters.\n this.accumulateParameterRefs(pathItem?.parameters);\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 filtering removed every operation from this path then remove its path-level properties\n // as well. We leave path items that were authored without operations untouched.\n if (\n ((removedOperation || (this.mode === 'reduce' && excludePathItem)) && !this.hasOperations(pathItem)) ||\n (this.mode === 'reduce' && !Object.keys(this.definition.paths?.[path] || {}).length)\n ) {\n delete this.definition.paths?.[path];\n }\n });\n\n // If we don't have any paths left then retain the reducer's no-match error. An empty Paths\n // Object is valid OpenAPI so we allow it when pruning.\n if (!Object.keys(this.definition.paths || {}).length) {\n if (this.mode === 'reduce' && !(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 if (this.definition.webhooks && Object.keys(this.definition.webhooks).length) {\n delete this.definition.paths;\n }\n }\n }\n\n /**\n * Transform our `webhooks` object according to the webhooks and operations that we've selected.\n */\n private transformWebhooks(): 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 const excludeWebhook = this.hasWebhookSelection && this.isContainerExcluded(this.webhookSelection, webhookName);\n\n if (this.mode === 'prune' && excludeWebhook) {\n const retainedByRef = Array.from(this.retainWebhookMethods).some(key => key.startsWith(`${nameLC}|`));\n\n if (retainedByRef) {\n throw new Error(`Cannot remove webhook \\`${webhookName}\\` because one of its operations is referenced.`);\n }\n\n delete definition.webhooks?.[webhookName];\n return;\n }\n\n const webhook = definition.webhooks?.[webhookName];\n if (!webhook || typeof webhook !== 'object') {\n return;\n }\n\n /**\n * Referenced webhook Path Items are preserved intact during operation-level filtering. If\n * the whole webhook is excluded, remove it unless a surviving operation references it.\n * @fixme Resolve referenced Path Items so their operations can be transformed individually.\n */\n if (isRef(webhook)) {\n if (excludeWebhook) {\n const retainedByRef = Array.from(this.retainWebhookMethods).some(key => key.startsWith(`${nameLC}|`));\n if (!retainedByRef) {\n delete definition.webhooks?.[webhookName];\n }\n }\n\n return;\n }\n\n let removedOperation = false;\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 operation = webhook[method as HttpMethods];\n if (!operation) {\n throw new Error(`Webhook operation \\`${method} ${webhookName}\\` not found`);\n }\n\n const retainedByRef = this.retainWebhookMethods.has(`${nameLC}|${methodLC}`);\n if (excludeWebhook || !this.shouldRetainOperation(this.webhookSelection, webhookName, method, operation)) {\n if (this.mode === 'prune' && retainedByRef) {\n throw new Error(\n `Cannot remove operation \\`${method.toUpperCase()} ${webhookName}\\` because it is referenced.`,\n );\n }\n\n if (!retainedByRef) {\n delete webhook[method as HttpMethods];\n removedOperation = true;\n return;\n }\n }\n\n // This operation remains in the transformed definition, so retain any components\n // referenced by its common Path Item parameters.\n this.accumulateParameterRefs(webhook.parameters);\n\n (operation.tags || []).forEach((tag: string) => {\n this.usedTags.add(tag);\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 if (\n ((removedOperation || (this.mode === 'reduce' && excludeWebhook)) && !this.hasOperations(webhook)) ||\n (this.mode === 'reduce' && !Object.keys(definition.webhooks?.[webhookName] || {}).length)\n ) {\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","/**\n * Track selected HTTP operations within OpenAPI paths or webhooks. Container keys and HTTP methods\n * are matched without regard to casing.\n */\nexport class OperationSelection {\n private selections: Map<string, '*' | Set<string>> = new Map();\n\n /** Whether any paths or webhooks have been selected. */\n get hasSelections(): boolean {\n return this.selections.size > 0;\n }\n\n /**\n * Select every operation within a path or webhook.\n *\n * @param key Path or webhook key whose operations should be selected.\n */\n addAll(key: string): void {\n this.selections.set(this.normalize(key), '*');\n }\n\n /**\n * Add an operation to the selection for a path or webhook. If every operation for the key is\n * already selected, that selection remains unchanged.\n *\n * @param key Path or webhook key that contains the operation.\n * @param method HTTP method of the operation to select.\n */\n addOperation(key: string, method: string): void {\n const normalizedKey = this.normalize(key);\n const normalizedMethod = this.normalize(method);\n const selection = this.selections.get(normalizedKey);\n\n if (selection === '*') {\n return;\n }\n\n if (selection instanceof Set) {\n selection.add(normalizedMethod);\n return;\n }\n\n this.selections.set(normalizedKey, new Set([normalizedMethod]));\n }\n\n /**\n * Clear every operation selection for a path or webhook.\n *\n * @param key Path or webhook key to clear.\n */\n clear(key: string): void {\n this.selections.delete(this.normalize(key));\n }\n\n /**\n * Determine whether a path or webhook has any selected operations.\n *\n * @param key Path or webhook key to check.\n */\n has(key: string): boolean {\n return this.selections.has(this.normalize(key));\n }\n\n /**\n * Determine whether every operation within a path or webhook is selected.\n *\n * @param key Path or webhook key to check.\n */\n matchesAll(key: string): boolean {\n return this.selections.get(this.normalize(key)) === '*';\n }\n\n /**\n * Determine whether an operation is selected.\n *\n * @param key Path or webhook key that contains the operation.\n * @param method HTTP method of the operation to check.\n */\n matches(key: string, method: string): boolean {\n const selection = this.selections.get(this.normalize(key));\n return selection === '*' || Boolean(selection?.has(this.normalize(method)));\n }\n\n /** Normalize path, webhook, and method casing for comparisons. */\n private normalize(value: string): string {\n return value.toLowerCase();\n }\n}\n"]}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { OASDocument } from './types.cjs';
|
|
2
|
+
|
|
3
|
+
interface OpenAPITransformerOptions {
|
|
4
|
+
/** Whether selected paths, operations, and webhooks should be retained or removed. */
|
|
5
|
+
mode: 'prune' | 'reduce';
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Internal engine for selecting operations and transforming an OpenAPI definition down to its
|
|
9
|
+
* reachable paths, webhooks, components, and tags.
|
|
10
|
+
*/
|
|
11
|
+
declare class OpenAPITransformer {
|
|
12
|
+
private definition;
|
|
13
|
+
private readonly mode;
|
|
14
|
+
/**
|
|
15
|
+
* A collection of `$ref` pointers that are used within our transformed API definition. This is
|
|
16
|
+
* used to ensure that all referenced schemas are retained in our resulting API definition. Not
|
|
17
|
+
* retaining them would result in an invalid OpenAPI definition.
|
|
18
|
+
*/
|
|
19
|
+
private $refs;
|
|
20
|
+
/**
|
|
21
|
+
* A collection of OpenAPI tags that are used within the transformed API definition.
|
|
22
|
+
*/
|
|
23
|
+
private usedTags;
|
|
24
|
+
/**
|
|
25
|
+
* A collection of OpenAPI paths and operations that are cross-referenced from any other paths
|
|
26
|
+
* and operations that we're retaining. This collection is used to ensure that those operations
|
|
27
|
+
* are retained in our resulting API definition. Not retaining them would result in an invalid
|
|
28
|
+
* OpenAPI definition.
|
|
29
|
+
*/
|
|
30
|
+
private retainPathMethods;
|
|
31
|
+
/**
|
|
32
|
+
* A collection of OpenAPI webhook names and methods that are cross-referenced from any other
|
|
33
|
+
* schemas. This collection, like `retainPathMethods`, is used to ensure that those operations are
|
|
34
|
+
* retained in our resulting API definition. Not retaining them would result in an invalid
|
|
35
|
+
* OpenAPI definition.
|
|
36
|
+
*/
|
|
37
|
+
private retainWebhookMethods;
|
|
38
|
+
/** An array of OpenAPI tags selected for the current transformation. */
|
|
39
|
+
private tagSelection;
|
|
40
|
+
/** A collection of operation IDs selected for the current transformation. */
|
|
41
|
+
private operationIdSelection;
|
|
42
|
+
/** A collection of OpenAPI paths and operations selected for the current transformation. */
|
|
43
|
+
private pathSelection;
|
|
44
|
+
/** A collection of OpenAPI webhooks selected for the current transformation. */
|
|
45
|
+
private webhookSelection;
|
|
46
|
+
private hasTagSelection;
|
|
47
|
+
private hasOperationIdSelection;
|
|
48
|
+
private hasPathSelection;
|
|
49
|
+
private hasWebhookSelection;
|
|
50
|
+
/**
|
|
51
|
+
* @param definition OpenAPI definition to transform.
|
|
52
|
+
* @param options Transformation mode.
|
|
53
|
+
*/
|
|
54
|
+
protected constructor(definition: OASDocument, options: OpenAPITransformerOptions);
|
|
55
|
+
/**
|
|
56
|
+
* Select an OpenAPI tag. Operations with this tag are retained when reducing and removed when
|
|
57
|
+
* pruning. Tag casing does not matter.
|
|
58
|
+
*
|
|
59
|
+
* @param tag Tag to select.
|
|
60
|
+
*/
|
|
61
|
+
protected selectTag(tag: string): void;
|
|
62
|
+
/**
|
|
63
|
+
* Select an entire OpenAPI path and all operations that it contains. Selected paths are retained
|
|
64
|
+
* when reducing and removed when pruning. Path casing does not matter.
|
|
65
|
+
*
|
|
66
|
+
* @param path Path to select.
|
|
67
|
+
*/
|
|
68
|
+
protected selectPath(path: string): void;
|
|
69
|
+
/**
|
|
70
|
+
* Select a single OpenAPI operation. Selected operations are retained when reducing and removed
|
|
71
|
+
* when pruning. Path and method casing does not matter.
|
|
72
|
+
*
|
|
73
|
+
* In reduce mode, selecting an operation after its entire path replaces the all-operation
|
|
74
|
+
* selection with that operation and any operations selected afterward. Prune mode keeps the
|
|
75
|
+
* entire path selected.
|
|
76
|
+
*
|
|
77
|
+
* @param path Path containing the operation.
|
|
78
|
+
* @param method HTTP method of the operation to select.
|
|
79
|
+
*/
|
|
80
|
+
protected selectOperation(path: string, method: string): void;
|
|
81
|
+
/**
|
|
82
|
+
* Select an OpenAPI operation by its operation ID. IDs are matched exactly and are generated
|
|
83
|
+
* from the operation path and method when one is not authored in the definition.
|
|
84
|
+
*
|
|
85
|
+
* @param operationId Operation ID to select.
|
|
86
|
+
*/
|
|
87
|
+
protected selectOperationId(operationId: string): void;
|
|
88
|
+
/**
|
|
89
|
+
* Select an OpenAPI webhook or one of its operations. Selected webhooks are retained when
|
|
90
|
+
* reducing and removed when pruning. Webhook and method casing does not matter.
|
|
91
|
+
*
|
|
92
|
+
* @param webhookName Webhook to select.
|
|
93
|
+
* @param method Optional HTTP method of an individual webhook operation to select.
|
|
94
|
+
*/
|
|
95
|
+
protected selectWebhook(webhookName: string, method?: string): void;
|
|
96
|
+
/** Transform the OpenAPI definition according to the configured mode and selections. */
|
|
97
|
+
protected transform(): OASDocument;
|
|
98
|
+
/**
|
|
99
|
+
* Recursively process a `$ref` pointer and accumulate any other `$ref` pointers that it or its
|
|
100
|
+
* children use. This handles circular references by skipping `$ref` pointers we have already seen.
|
|
101
|
+
* Additionally when a `$ref` points to `#/paths` we record the used path + method so we can
|
|
102
|
+
* retain cross-operation references within the transformed definition.
|
|
103
|
+
*
|
|
104
|
+
* @param schema JSON Schema object to look for and accumulate any `$ref` pointers that it may have.
|
|
105
|
+
* @param $refs Known set of `$ref` pointers.
|
|
106
|
+
* @param $ref `$ref` pointer to fetch a schema from out of the supplied schema.
|
|
107
|
+
*/
|
|
108
|
+
private accumulateUsedRefs;
|
|
109
|
+
/**
|
|
110
|
+
* Query a JSON Schema object for any `$ref` pointers using JSONPath and return any pointers that
|
|
111
|
+
* exist.
|
|
112
|
+
*
|
|
113
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc9535}
|
|
114
|
+
* @param schema JSON Schema object to look for any `$ref` pointers within it.
|
|
115
|
+
*/
|
|
116
|
+
private queryForRefPointers;
|
|
117
|
+
/**
|
|
118
|
+
* Normalize a value from a `jsonpath-plus` `$ref` query to a `$ref` pointer because JSONPath
|
|
119
|
+
* queries may return the property value or the parent.
|
|
120
|
+
*
|
|
121
|
+
*/
|
|
122
|
+
private toRefString;
|
|
123
|
+
/**
|
|
124
|
+
* If the given `$ref` points into a path (e.g. `#/paths/~1anything/post/...`), return the path
|
|
125
|
+
* and method so the transformer can retain cross-operation references.
|
|
126
|
+
*
|
|
127
|
+
*/
|
|
128
|
+
private parsePathRef;
|
|
129
|
+
/**
|
|
130
|
+
* If the given `$ref` points into webhooks (e.g. `#/webhooks/newBooking/post/...`), return the
|
|
131
|
+
* webhook name and method so the transformer can retain cross-referenced webhook operations.
|
|
132
|
+
*
|
|
133
|
+
*/
|
|
134
|
+
private parseWebhookRef;
|
|
135
|
+
/** Determine whether a path or webhook is excluded in the current transformation mode. */
|
|
136
|
+
private isContainerExcluded;
|
|
137
|
+
/**
|
|
138
|
+
* Determine whether an operation passes the configured filters before cross-operation references
|
|
139
|
+
* are considered.
|
|
140
|
+
*/
|
|
141
|
+
private shouldRetainOperation;
|
|
142
|
+
/** Determine whether a path item contains at least one HTTP operation. */
|
|
143
|
+
private hasOperations;
|
|
144
|
+
/**
|
|
145
|
+
* Accumulate any `$ref` pointers that are used by common Path Item parameters.
|
|
146
|
+
*
|
|
147
|
+
* @param parameters Common Path Item parameters to inspect for `$ref` pointers.
|
|
148
|
+
*/
|
|
149
|
+
private accumulateParameterRefs;
|
|
150
|
+
/**
|
|
151
|
+
* Walk through the `paths` in our OpenAPI definition and determine which operations we want to
|
|
152
|
+
* retain. Accumulate any `$ref` pointers that they use so their referenced schemas can also be
|
|
153
|
+
* retained in our resulting API definition.
|
|
154
|
+
*
|
|
155
|
+
*/
|
|
156
|
+
private walkPaths;
|
|
157
|
+
/**
|
|
158
|
+
* Walk through the `webhooks` in our OpenAPI definition and determine which operations we want
|
|
159
|
+
* to retain. Accumulate any `$ref` pointers that they use so their referenced schemas can also be
|
|
160
|
+
* retained in our resulting API definition.
|
|
161
|
+
*
|
|
162
|
+
*/
|
|
163
|
+
private walkWebhooks;
|
|
164
|
+
/**
|
|
165
|
+
* Transform our `paths` object according to the paths and operations that we've selected.
|
|
166
|
+
*/
|
|
167
|
+
private transformPaths;
|
|
168
|
+
/**
|
|
169
|
+
* Transform our `webhooks` object according to the webhooks and operations that we've selected.
|
|
170
|
+
*/
|
|
171
|
+
private transformWebhooks;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export { OpenAPITransformer as O };
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { OASDocument } from './types.js';
|
|
2
|
+
|
|
3
|
+
interface OpenAPITransformerOptions {
|
|
4
|
+
/** Whether selected paths, operations, and webhooks should be retained or removed. */
|
|
5
|
+
mode: 'prune' | 'reduce';
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Internal engine for selecting operations and transforming an OpenAPI definition down to its
|
|
9
|
+
* reachable paths, webhooks, components, and tags.
|
|
10
|
+
*/
|
|
11
|
+
declare class OpenAPITransformer {
|
|
12
|
+
private definition;
|
|
13
|
+
private readonly mode;
|
|
14
|
+
/**
|
|
15
|
+
* A collection of `$ref` pointers that are used within our transformed API definition. This is
|
|
16
|
+
* used to ensure that all referenced schemas are retained in our resulting API definition. Not
|
|
17
|
+
* retaining them would result in an invalid OpenAPI definition.
|
|
18
|
+
*/
|
|
19
|
+
private $refs;
|
|
20
|
+
/**
|
|
21
|
+
* A collection of OpenAPI tags that are used within the transformed API definition.
|
|
22
|
+
*/
|
|
23
|
+
private usedTags;
|
|
24
|
+
/**
|
|
25
|
+
* A collection of OpenAPI paths and operations that are cross-referenced from any other paths
|
|
26
|
+
* and operations that we're retaining. This collection is used to ensure that those operations
|
|
27
|
+
* are retained in our resulting API definition. Not retaining them would result in an invalid
|
|
28
|
+
* OpenAPI definition.
|
|
29
|
+
*/
|
|
30
|
+
private retainPathMethods;
|
|
31
|
+
/**
|
|
32
|
+
* A collection of OpenAPI webhook names and methods that are cross-referenced from any other
|
|
33
|
+
* schemas. This collection, like `retainPathMethods`, is used to ensure that those operations are
|
|
34
|
+
* retained in our resulting API definition. Not retaining them would result in an invalid
|
|
35
|
+
* OpenAPI definition.
|
|
36
|
+
*/
|
|
37
|
+
private retainWebhookMethods;
|
|
38
|
+
/** An array of OpenAPI tags selected for the current transformation. */
|
|
39
|
+
private tagSelection;
|
|
40
|
+
/** A collection of operation IDs selected for the current transformation. */
|
|
41
|
+
private operationIdSelection;
|
|
42
|
+
/** A collection of OpenAPI paths and operations selected for the current transformation. */
|
|
43
|
+
private pathSelection;
|
|
44
|
+
/** A collection of OpenAPI webhooks selected for the current transformation. */
|
|
45
|
+
private webhookSelection;
|
|
46
|
+
private hasTagSelection;
|
|
47
|
+
private hasOperationIdSelection;
|
|
48
|
+
private hasPathSelection;
|
|
49
|
+
private hasWebhookSelection;
|
|
50
|
+
/**
|
|
51
|
+
* @param definition OpenAPI definition to transform.
|
|
52
|
+
* @param options Transformation mode.
|
|
53
|
+
*/
|
|
54
|
+
protected constructor(definition: OASDocument, options: OpenAPITransformerOptions);
|
|
55
|
+
/**
|
|
56
|
+
* Select an OpenAPI tag. Operations with this tag are retained when reducing and removed when
|
|
57
|
+
* pruning. Tag casing does not matter.
|
|
58
|
+
*
|
|
59
|
+
* @param tag Tag to select.
|
|
60
|
+
*/
|
|
61
|
+
protected selectTag(tag: string): void;
|
|
62
|
+
/**
|
|
63
|
+
* Select an entire OpenAPI path and all operations that it contains. Selected paths are retained
|
|
64
|
+
* when reducing and removed when pruning. Path casing does not matter.
|
|
65
|
+
*
|
|
66
|
+
* @param path Path to select.
|
|
67
|
+
*/
|
|
68
|
+
protected selectPath(path: string): void;
|
|
69
|
+
/**
|
|
70
|
+
* Select a single OpenAPI operation. Selected operations are retained when reducing and removed
|
|
71
|
+
* when pruning. Path and method casing does not matter.
|
|
72
|
+
*
|
|
73
|
+
* In reduce mode, selecting an operation after its entire path replaces the all-operation
|
|
74
|
+
* selection with that operation and any operations selected afterward. Prune mode keeps the
|
|
75
|
+
* entire path selected.
|
|
76
|
+
*
|
|
77
|
+
* @param path Path containing the operation.
|
|
78
|
+
* @param method HTTP method of the operation to select.
|
|
79
|
+
*/
|
|
80
|
+
protected selectOperation(path: string, method: string): void;
|
|
81
|
+
/**
|
|
82
|
+
* Select an OpenAPI operation by its operation ID. IDs are matched exactly and are generated
|
|
83
|
+
* from the operation path and method when one is not authored in the definition.
|
|
84
|
+
*
|
|
85
|
+
* @param operationId Operation ID to select.
|
|
86
|
+
*/
|
|
87
|
+
protected selectOperationId(operationId: string): void;
|
|
88
|
+
/**
|
|
89
|
+
* Select an OpenAPI webhook or one of its operations. Selected webhooks are retained when
|
|
90
|
+
* reducing and removed when pruning. Webhook and method casing does not matter.
|
|
91
|
+
*
|
|
92
|
+
* @param webhookName Webhook to select.
|
|
93
|
+
* @param method Optional HTTP method of an individual webhook operation to select.
|
|
94
|
+
*/
|
|
95
|
+
protected selectWebhook(webhookName: string, method?: string): void;
|
|
96
|
+
/** Transform the OpenAPI definition according to the configured mode and selections. */
|
|
97
|
+
protected transform(): OASDocument;
|
|
98
|
+
/**
|
|
99
|
+
* Recursively process a `$ref` pointer and accumulate any other `$ref` pointers that it or its
|
|
100
|
+
* children use. This handles circular references by skipping `$ref` pointers we have already seen.
|
|
101
|
+
* Additionally when a `$ref` points to `#/paths` we record the used path + method so we can
|
|
102
|
+
* retain cross-operation references within the transformed definition.
|
|
103
|
+
*
|
|
104
|
+
* @param schema JSON Schema object to look for and accumulate any `$ref` pointers that it may have.
|
|
105
|
+
* @param $refs Known set of `$ref` pointers.
|
|
106
|
+
* @param $ref `$ref` pointer to fetch a schema from out of the supplied schema.
|
|
107
|
+
*/
|
|
108
|
+
private accumulateUsedRefs;
|
|
109
|
+
/**
|
|
110
|
+
* Query a JSON Schema object for any `$ref` pointers using JSONPath and return any pointers that
|
|
111
|
+
* exist.
|
|
112
|
+
*
|
|
113
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc9535}
|
|
114
|
+
* @param schema JSON Schema object to look for any `$ref` pointers within it.
|
|
115
|
+
*/
|
|
116
|
+
private queryForRefPointers;
|
|
117
|
+
/**
|
|
118
|
+
* Normalize a value from a `jsonpath-plus` `$ref` query to a `$ref` pointer because JSONPath
|
|
119
|
+
* queries may return the property value or the parent.
|
|
120
|
+
*
|
|
121
|
+
*/
|
|
122
|
+
private toRefString;
|
|
123
|
+
/**
|
|
124
|
+
* If the given `$ref` points into a path (e.g. `#/paths/~1anything/post/...`), return the path
|
|
125
|
+
* and method so the transformer can retain cross-operation references.
|
|
126
|
+
*
|
|
127
|
+
*/
|
|
128
|
+
private parsePathRef;
|
|
129
|
+
/**
|
|
130
|
+
* If the given `$ref` points into webhooks (e.g. `#/webhooks/newBooking/post/...`), return the
|
|
131
|
+
* webhook name and method so the transformer can retain cross-referenced webhook operations.
|
|
132
|
+
*
|
|
133
|
+
*/
|
|
134
|
+
private parseWebhookRef;
|
|
135
|
+
/** Determine whether a path or webhook is excluded in the current transformation mode. */
|
|
136
|
+
private isContainerExcluded;
|
|
137
|
+
/**
|
|
138
|
+
* Determine whether an operation passes the configured filters before cross-operation references
|
|
139
|
+
* are considered.
|
|
140
|
+
*/
|
|
141
|
+
private shouldRetainOperation;
|
|
142
|
+
/** Determine whether a path item contains at least one HTTP operation. */
|
|
143
|
+
private hasOperations;
|
|
144
|
+
/**
|
|
145
|
+
* Accumulate any `$ref` pointers that are used by common Path Item parameters.
|
|
146
|
+
*
|
|
147
|
+
* @param parameters Common Path Item parameters to inspect for `$ref` pointers.
|
|
148
|
+
*/
|
|
149
|
+
private accumulateParameterRefs;
|
|
150
|
+
/**
|
|
151
|
+
* Walk through the `paths` in our OpenAPI definition and determine which operations we want to
|
|
152
|
+
* retain. Accumulate any `$ref` pointers that they use so their referenced schemas can also be
|
|
153
|
+
* retained in our resulting API definition.
|
|
154
|
+
*
|
|
155
|
+
*/
|
|
156
|
+
private walkPaths;
|
|
157
|
+
/**
|
|
158
|
+
* Walk through the `webhooks` in our OpenAPI definition and determine which operations we want
|
|
159
|
+
* to retain. Accumulate any `$ref` pointers that they use so their referenced schemas can also be
|
|
160
|
+
* retained in our resulting API definition.
|
|
161
|
+
*
|
|
162
|
+
*/
|
|
163
|
+
private walkWebhooks;
|
|
164
|
+
/**
|
|
165
|
+
* Transform our `paths` object according to the paths and operations that we've selected.
|
|
166
|
+
*/
|
|
167
|
+
private transformPaths;
|
|
168
|
+
/**
|
|
169
|
+
* Transform our `webhooks` object according to the webhooks and operations that we've selected.
|
|
170
|
+
*/
|
|
171
|
+
private transformWebhooks;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export { OpenAPITransformer as O };
|
package/dist/index.cjs
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
var _chunkY64TRECNcjs = require('./chunk-Y64TRECN.cjs');
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
|
|
@@ -145,16 +146,16 @@ var Oas = class _Oas {
|
|
|
145
146
|
url(selected = 0, variables) {
|
|
146
147
|
const url = _optionalChain([this, 'access', _8 => _8.api, 'access', _9 => _9.servers, 'optionalAccess', _10 => _10[selected], 'optionalAccess', _11 => _11.url]);
|
|
147
148
|
const resolvedUrl = url ? this.replaceUrl(url, variables || this.defaultVariables(selected)) : void 0;
|
|
148
|
-
return
|
|
149
|
+
return _chunkY64TRECNcjs.normalizeURL.call(void 0, resolvedUrl).trim();
|
|
149
150
|
}
|
|
150
151
|
variables(selected = 0) {
|
|
151
|
-
return
|
|
152
|
+
return _chunkY64TRECNcjs.variablesFromServers.call(void 0, this.api.servers, selected);
|
|
152
153
|
}
|
|
153
154
|
defaultVariables(selected = 0) {
|
|
154
|
-
return
|
|
155
|
+
return _chunkY64TRECNcjs.defaultVariablesFromServers.call(void 0, this.api.servers, selected, this.user);
|
|
155
156
|
}
|
|
156
157
|
splitUrl(selected = 0) {
|
|
157
|
-
return
|
|
158
|
+
return _chunkY64TRECNcjs.splitUrlFromServers.call(void 0, this.api.servers, selected);
|
|
158
159
|
}
|
|
159
160
|
/**
|
|
160
161
|
* With a fully composed server URL, run through our list of known OAS servers and return back
|
|
@@ -172,7 +173,7 @@ var Oas = class _Oas {
|
|
|
172
173
|
*/
|
|
173
174
|
splitVariables(baseUrl) {
|
|
174
175
|
const matchedServer = (this.api.servers || []).map((server, i) => {
|
|
175
|
-
const rgx =
|
|
176
|
+
const rgx = _chunkY64TRECNcjs.transformURLIntoRegex.call(void 0, server.url);
|
|
176
177
|
const found = new RegExp(rgx).exec(baseUrl);
|
|
177
178
|
if (!found) {
|
|
178
179
|
return false;
|
|
@@ -208,7 +209,7 @@ var Oas = class _Oas {
|
|
|
208
209
|
* @param variables An object containing variables to swap into the URL.
|
|
209
210
|
*/
|
|
210
211
|
replaceUrl(url, variables = {}) {
|
|
211
|
-
return
|
|
212
|
+
return _chunkY64TRECNcjs.stripTrailingSlash.call(void 0,
|
|
212
213
|
url.replace(_chunk7WBPPWYIcjs.SERVER_VARIABLE_REGEX, (original, key) => {
|
|
213
214
|
if (key in variables) {
|
|
214
215
|
const data = variables[key];
|
|
@@ -220,7 +221,7 @@ var Oas = class _Oas {
|
|
|
220
221
|
return String(data);
|
|
221
222
|
}
|
|
222
223
|
}
|
|
223
|
-
const userVariable =
|
|
224
|
+
const userVariable = _chunkY64TRECNcjs.getUserVariable.call(void 0, this.user, key);
|
|
224
225
|
if (userVariable) {
|
|
225
226
|
return String(userVariable);
|
|
226
227
|
}
|
|
@@ -244,7 +245,7 @@ var Oas = class _Oas {
|
|
|
244
245
|
if (webhookPath && !_chunk7PWF3F2Wcjs.isRef.call(void 0, webhookPath)) {
|
|
245
246
|
if (_optionalChain([webhookPath, 'optionalAccess', _15 => _15[method]])) {
|
|
246
247
|
operation = webhookPath[method];
|
|
247
|
-
return new (0,
|
|
248
|
+
return new (0, _chunkY64TRECNcjs.Webhook)(this, path, method, operation);
|
|
248
249
|
}
|
|
249
250
|
}
|
|
250
251
|
}
|
|
@@ -255,7 +256,7 @@ var Oas = class _Oas {
|
|
|
255
256
|
operation = _chunk7WBPPWYIcjs.dereferenceRef.call(void 0, pathItem[method], this.api);
|
|
256
257
|
}
|
|
257
258
|
}
|
|
258
|
-
return new (0,
|
|
259
|
+
return new (0, _chunkY64TRECNcjs.Operation)(this, path, method, operation);
|
|
259
260
|
}
|
|
260
261
|
findOperationMatches(url) {
|
|
261
262
|
const annotatedPaths = [
|
|
@@ -269,8 +270,14 @@ var Oas = class _Oas {
|
|
|
269
270
|
* Find matches for a URL against paths as they are served by the root-level `servers`.
|
|
270
271
|
*/
|
|
271
272
|
findRootServerOperationMatches(url) {
|
|
272
|
-
|
|
273
|
-
|
|
273
|
+
let origin;
|
|
274
|
+
let hostname;
|
|
275
|
+
try {
|
|
276
|
+
({ origin, hostname } = new URL(url));
|
|
277
|
+
} catch (e) {
|
|
278
|
+
return void 0;
|
|
279
|
+
}
|
|
280
|
+
const originRegExp = new RegExp(_chunkY64TRECNcjs.escapeRegExp.call(void 0, origin), "i");
|
|
274
281
|
const { servers, paths } = this.api;
|
|
275
282
|
let matchedServer;
|
|
276
283
|
if (!servers || !servers.length) {
|
|
@@ -280,7 +287,7 @@ var Oas = class _Oas {
|
|
|
280
287
|
} else {
|
|
281
288
|
matchedServer = servers.find((s) => originRegExp.exec(this.replaceUrl(s.url, s.variables || {})));
|
|
282
289
|
if (!matchedServer) {
|
|
283
|
-
const hostnameRegExp = new RegExp(hostname);
|
|
290
|
+
const hostnameRegExp = new RegExp(_chunkY64TRECNcjs.escapeRegExp.call(void 0, hostname));
|
|
284
291
|
matchedServer = servers.find((s) => hostnameRegExp.exec(this.replaceUrl(s.url, s.variables || {})));
|
|
285
292
|
}
|
|
286
293
|
}
|
|
@@ -293,7 +300,7 @@ var Oas = class _Oas {
|
|
|
293
300
|
}
|
|
294
301
|
}
|
|
295
302
|
if (!target || !paths) return void 0;
|
|
296
|
-
const annotatedPaths =
|
|
303
|
+
const annotatedPaths = _chunkY64TRECNcjs.generatePathMatches.call(void 0, paths, target.pathName || "/", target.origin);
|
|
297
304
|
if (!annotatedPaths.length) return void 0;
|
|
298
305
|
return annotatedPaths;
|
|
299
306
|
}
|
|
@@ -341,7 +348,7 @@ var Oas = class _Oas {
|
|
|
341
348
|
for (const server of servers) {
|
|
342
349
|
const target = this.splitURLIntoOriginAndPathName(url, server);
|
|
343
350
|
if (!target) continue;
|
|
344
|
-
const annotatedPaths =
|
|
351
|
+
const annotatedPaths = _chunkY64TRECNcjs.generatePathMatches.call(void 0,
|
|
345
352
|
{ [path]: operations },
|
|
346
353
|
target.pathName || "/",
|
|
347
354
|
target.origin
|
|
@@ -368,11 +375,11 @@ var Oas = class _Oas {
|
|
|
368
375
|
splitURLOnSubstitutedServer(url, server) {
|
|
369
376
|
try {
|
|
370
377
|
const substitutedUrl = this.replaceUrl(server.url, server.variables || {});
|
|
371
|
-
const [, pathName] = url.split(new RegExp(substitutedUrl, "i"));
|
|
378
|
+
const [, pathName] = url.split(new RegExp(_chunkY64TRECNcjs.escapeRegExp.call(void 0, substitutedUrl), "i"));
|
|
372
379
|
if (pathName !== void 0) {
|
|
373
380
|
return { origin: substitutedUrl, pathName };
|
|
374
381
|
}
|
|
375
|
-
} catch (
|
|
382
|
+
} catch (e2) {
|
|
376
383
|
}
|
|
377
384
|
return void 0;
|
|
378
385
|
}
|
|
@@ -382,11 +389,11 @@ var Oas = class _Oas {
|
|
|
382
389
|
*/
|
|
383
390
|
splitURLOnServerRegex(url, server) {
|
|
384
391
|
try {
|
|
385
|
-
const regex =
|
|
392
|
+
const regex = _chunkY64TRECNcjs.transformURLIntoRegex.call(void 0, server.url);
|
|
386
393
|
if (new RegExp(regex).exec(url)) {
|
|
387
394
|
return { origin: server.url, pathName: url.split(new RegExp(regex)).slice(-1).pop() || "" };
|
|
388
395
|
}
|
|
389
|
-
} catch (
|
|
396
|
+
} catch (e3) {
|
|
390
397
|
}
|
|
391
398
|
return void 0;
|
|
392
399
|
}
|
|
@@ -403,9 +410,9 @@ var Oas = class _Oas {
|
|
|
403
410
|
if (!annotatedPaths) {
|
|
404
411
|
return void 0;
|
|
405
412
|
}
|
|
406
|
-
const matches =
|
|
413
|
+
const matches = _chunkY64TRECNcjs.filterPathMethods.call(void 0, annotatedPaths, method);
|
|
407
414
|
if (!matches.length) return void 0;
|
|
408
|
-
return
|
|
415
|
+
return _chunkY64TRECNcjs.findTargetPath.call(void 0, matches);
|
|
409
416
|
}
|
|
410
417
|
/**
|
|
411
418
|
* Discover an operation in an OAS from a fully-formed URL without an HTTP method. Will return an
|
|
@@ -418,7 +425,7 @@ var Oas = class _Oas {
|
|
|
418
425
|
if (!annotatedPaths) {
|
|
419
426
|
return void 0;
|
|
420
427
|
}
|
|
421
|
-
return
|
|
428
|
+
return _chunkY64TRECNcjs.findTargetPath.call(void 0, annotatedPaths);
|
|
422
429
|
}
|
|
423
430
|
/**
|
|
424
431
|
* Retrieve an operation in an OAS from a fully-formed URL and HTTP method. Differs from
|