oas 32.1.10 → 32.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/index.cjs +6 -6
- package/dist/analyzer/index.js +4 -4
- package/dist/{chunk-WXXVCSCN.js → chunk-2EISA7HB.js} +5 -5
- package/dist/chunk-2EISA7HB.js.map +1 -0
- package/dist/{chunk-YPR7YTHM.cjs → chunk-3MTU2ESP.cjs} +1 -1
- package/dist/{chunk-YPR7YTHM.cjs.map → chunk-3MTU2ESP.cjs.map} +1 -1
- package/dist/{chunk-EYI3QYOG.cjs → chunk-7BWVOLZR.cjs} +211 -198
- package/dist/chunk-7BWVOLZR.cjs.map +1 -0
- package/dist/{chunk-DKPOVGFI.cjs → chunk-BJEFIYTO.cjs} +29 -29
- package/dist/chunk-BJEFIYTO.cjs.map +1 -0
- package/dist/{chunk-2TQO63CW.js → chunk-GIFUTDD5.js} +53 -40
- package/dist/chunk-GIFUTDD5.js.map +1 -0
- package/dist/{chunk-7BC6KXMO.js → chunk-K5WNB3M7.js} +133 -49
- package/dist/chunk-K5WNB3M7.js.map +1 -0
- package/dist/{chunk-MNOEMVCF.js → chunk-PSNTODZL.js} +1 -1
- package/dist/{chunk-MNOEMVCF.js.map → chunk-PSNTODZL.js.map} +1 -1
- package/dist/{chunk-HTEFBV7K.cjs → chunk-SAB2PGCD.cjs} +158 -74
- package/dist/chunk-SAB2PGCD.cjs.map +1 -0
- package/dist/index.cjs +5 -5
- package/dist/index.js +4 -4
- package/dist/operation/index.cjs +4 -4
- package/dist/operation/index.js +3 -3
- package/dist/reducer/index.cjs +49 -28
- package/dist/reducer/index.cjs.map +1 -1
- package/dist/reducer/index.js +23 -2
- package/dist/reducer/index.js.map +1 -1
- package/dist/types.cjs +2 -2
- package/dist/types.d.cts +3 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.js +1 -1
- package/dist/utils.cjs +3 -3
- package/dist/utils.js +2 -2
- package/package.json +6 -8
- package/dist/chunk-2TQO63CW.js.map +0 -1
- package/dist/chunk-7BC6KXMO.js.map +0 -1
- package/dist/chunk-DKPOVGFI.cjs.map +0 -1
- package/dist/chunk-EYI3QYOG.cjs.map +0 -1
- package/dist/chunk-HTEFBV7K.cjs.map +0 -1
- package/dist/chunk-WXXVCSCN.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas/dist/reducer/index.cjs","../../src/reducer/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,yDAA8B;AAC9B;AACE;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACF,yDAA8B;AAC9B;AACA;ACVA,oGAAwB;AAOjB,IAAM,eAAA,YAAN,MAAM,gBAAe;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAOA,MAAA,kBAAqB,IAAI,GAAA,CAAI,EAAA;AAAA;AAAA;AAAA;AAAA,kBAK7B,SAAA,kBAAwB,IAAI,GAAA,CAAI,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAQhC,kBAAA,kBAAgD,IAAI,GAAA,CAAI,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAQxD,qBAAA,kBAAmD,IAAI,GAAA,CAAI,EAAA;AAAA;AAAA;AAAA;AAAA,kBAK3D,eAAA,EAA2B,CAAC,EAAA;AAAA;AAAA;AAAA;AAAA,kBAK5B,gBAAA,EAAkD,CAAC,EAAA;AAAA;AAAA;AAAA;AAAA,kBAKnD,mBAAA,EAAqD,CAAC,EAAA;AAAA,kBAEtD,kBAAA,EAA6B,MAAA;AAAA,kBAC7B,mBAAA,EAA8B,MAAA;AAAA,mBAC9B,sBAAA,EAAiC,MAAA;AAAA,EAEjC,WAAA,CAAY,UAAA,EAAyB;AAC3C,IAAA,IAAA,CAAK,WAAA,EAAa,eAAA,CAAgB,UAAU,CAAA;AAAA,EAC9C;AAA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F;ADhMgE;AACA;AACA","file":"/Users/erunion/code/readme/oas/packages/oas/dist/reducer/index.cjs","sourcesContent":[null,"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 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 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"]}
|
|
1
|
+
{"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas/dist/reducer/index.cjs","../../src/reducer/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,yDAA8B;AAC9B;AACE;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACF,yDAA8B;AAC9B;AACA;ACVA,oGAAwB;AAOjB,IAAM,eAAA,YAAN,MAAM,gBAAe;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAOA,MAAA,kBAAqB,IAAI,GAAA,CAAI,EAAA;AAAA;AAAA;AAAA;AAAA,kBAK7B,SAAA,kBAAwB,IAAI,GAAA,CAAI,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAQhC,kBAAA,kBAAgD,IAAI,GAAA,CAAI,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAQxD,qBAAA,kBAAmD,IA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;AACF,QAAA;AACF,MAAA;AAEuB,MAAA;AACzB,IAAA;AACF,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAO+B,EAAA;AACM,IAAA;AACjC,MAAA;AACmD,IAAA;AACnD,MAAA;AACF,IAAA;AAEwB,IAAA;AAEuB,IAAA;AACN,MAAA;AACY,MAAA;AACX,QAAA;AACc,UAAA;AACpD,QAAA;AAEoB,QAAA;AACsB,UAAA;AACxC,UAAA;AACF,QAAA;AACF,MAAA;AAEiD,MAAA;AACJ,MAAA;AAC3C,QAAA;AACF,MAAA;AAMoB,MAAA;AAClB,QAAA;AACF,MAAA;AAEuC,MAAA;AACD,QAAA;AACa,QAAA;AAC/C,UAAA;AACF,QAAA;AAEuD,QAAA;AACL,QAAA;AACG,UAAA;AACG,UAAA;AAKH,YAAA;AAC/C,cAAA;AACF,YAAA;AAEiE,YAAA;AACnE,UAAA;AACF,QAAA;AACD,MAAA;AAEwD,MAAA;AACf,QAAA;AAC1C,MAAA;AACD,IAAA;AAE0D,IAAA;AACvC,MAAA;AACpB,IAAA;AACF,EAAA;AACF;ADxMgE;AACA;AACA","file":"/Users/erunion/code/readme/oas/packages/oas/dist/reducer/index.cjs","sourcesContent":[null,"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"]}
|
package/dist/reducer/index.js
CHANGED
|
@@ -4,12 +4,12 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
decodePointer,
|
|
6
6
|
supportedMethods
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-K5WNB3M7.js";
|
|
8
8
|
import "../chunk-S27IGTVG.js";
|
|
9
9
|
import {
|
|
10
10
|
isOpenAPI31,
|
|
11
11
|
isRef
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-PSNTODZL.js";
|
|
13
13
|
|
|
14
14
|
// src/reducer/index.ts
|
|
15
15
|
import jsonPointer from "jsonpointer";
|
|
@@ -341,6 +341,17 @@ var OpenAPIReducer = class _OpenAPIReducer {
|
|
|
341
341
|
(operation.tags || []).forEach((tag) => {
|
|
342
342
|
this.usedTags.add(tag);
|
|
343
343
|
});
|
|
344
|
+
const pathLevelParams = this.definition.paths?.[path]?.parameters;
|
|
345
|
+
if (pathLevelParams) {
|
|
346
|
+
this.queryForRefPointers(pathLevelParams).forEach(({ value: ref }) => {
|
|
347
|
+
const refStr = this.toRefString(ref);
|
|
348
|
+
if (!refStr) {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
this.$refs.add(refStr);
|
|
352
|
+
this.accumulateUsedRefs(this.definition, this.$refs, refStr);
|
|
353
|
+
});
|
|
354
|
+
}
|
|
344
355
|
this.queryForRefPointers(operation).forEach(({ value: ref }) => {
|
|
345
356
|
const refStr = this.toRefString(ref);
|
|
346
357
|
if (!refStr) {
|
|
@@ -408,6 +419,16 @@ var OpenAPIReducer = class _OpenAPIReducer {
|
|
|
408
419
|
(operation.tags || []).forEach((tag) => {
|
|
409
420
|
this.usedTags.add(tag);
|
|
410
421
|
});
|
|
422
|
+
if (webhook.parameters) {
|
|
423
|
+
this.queryForRefPointers(webhook.parameters).forEach(({ value: ref }) => {
|
|
424
|
+
const refStr = this.toRefString(ref);
|
|
425
|
+
if (!refStr) {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
this.$refs.add(refStr);
|
|
429
|
+
this.accumulateUsedRefs(definition, this.$refs, refStr);
|
|
430
|
+
});
|
|
431
|
+
}
|
|
411
432
|
this.queryForRefPointers(operation).forEach(({ value: ref }) => {
|
|
412
433
|
const refStr = this.toRefString(ref);
|
|
413
434
|
if (!refStr) {
|
|
@@ -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 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 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,UAAU;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,OAAO,KAAK,YAAyC;AACnD,WAAO,IAAI,gBAAe,UAAU;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,KAA6B;AACjC,SAAK,eAAe,KAAK,IAAI,YAAY,CAAC;AAC1C,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,MAA8B;AACnC,SAAK,gBAAgB,KAAK,YAAY,CAAC,IAAI;AAC3C,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;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M;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,UAAU;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,OAAO,KAAK,YAAyC;AACnD,WAAO,IAAI,gBAAe,UAAU;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,KAA6B;A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AA,IACF,CAAC;AAED,QAAI,WAAW,YAAY,CAAC,OAAO,KAAK,WAAW,QAAQ,EAAE,QAAQ;AACnE,aAAO,WAAW;AAAA,IACpB;AAAA,EACF;AACF;","names":[]}
|
package/dist/types.cjs
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunk3MTU2ESPcjs = require('./chunk-3MTU2ESP.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
exports.isOpenAPI30 =
|
|
14
|
+
exports.isOpenAPI30 = _chunk3MTU2ESPcjs.isOpenAPI30; exports.isOpenAPI31 = _chunk3MTU2ESPcjs.isOpenAPI31; exports.isRef = _chunk3MTU2ESPcjs.isRef; exports.isSchema = _chunk3MTU2ESPcjs.isSchema; exports.isSwagger = _chunk3MTU2ESPcjs.isSwagger;
|
|
15
15
|
//# sourceMappingURL=types.cjs.map
|
package/dist/types.d.cts
CHANGED
|
@@ -177,6 +177,9 @@ interface SchemaWrapper {
|
|
|
177
177
|
type: string;
|
|
178
178
|
}
|
|
179
179
|
/**
|
|
180
|
+
* Determine if a given JSON Schema object is a valid JSON Schema object and either has a declared
|
|
181
|
+
* `type` or is polymorphic in one form or another.
|
|
182
|
+
*
|
|
180
183
|
* @param check JSON Schema object to determine if it's a non-polymorphic schema.
|
|
181
184
|
* @param isPolymorphicAllOfChild If this JSON Schema object is the child of a polymorphic `allOf`.
|
|
182
185
|
* @returns If the JSON Schema object is a JSON Schema object.
|
package/dist/types.d.ts
CHANGED
|
@@ -177,6 +177,9 @@ interface SchemaWrapper {
|
|
|
177
177
|
type: string;
|
|
178
178
|
}
|
|
179
179
|
/**
|
|
180
|
+
* Determine if a given JSON Schema object is a valid JSON Schema object and either has a declared
|
|
181
|
+
* `type` or is polymorphic in one form or another.
|
|
182
|
+
*
|
|
180
183
|
* @param check JSON Schema object to determine if it's a non-polymorphic schema.
|
|
181
184
|
* @param isPolymorphicAllOfChild If this JSON Schema object is the child of a polymorphic `allOf`.
|
|
182
185
|
* @returns If the JSON Schema object is a JSON Schema object.
|
package/dist/types.js
CHANGED
package/dist/utils.cjs
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkSAB2PGCDcjs = require('./chunk-SAB2PGCD.cjs');
|
|
9
9
|
require('./chunk-AYA3UT4L.cjs');
|
|
10
|
-
require('./chunk-
|
|
10
|
+
require('./chunk-3MTU2ESP.cjs');
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
@@ -15,5 +15,5 @@ require('./chunk-YPR7YTHM.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
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
matches_mimetype_default,
|
|
6
6
|
supportedMethods,
|
|
7
7
|
types
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-K5WNB3M7.js";
|
|
9
9
|
import "./chunk-S27IGTVG.js";
|
|
10
|
-
import "./chunk-
|
|
10
|
+
import "./chunk-PSNTODZL.js";
|
|
11
11
|
export {
|
|
12
12
|
SERVER_VARIABLE_REGEX,
|
|
13
13
|
dereferenceRef,
|
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": "4703b7302019d896452a41470352a685b8c39766"
|
|
107
|
+
}
|
|
110
108
|
}
|