oas 38.6.0 → 38.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/darrenyong/Desktop/oas-stuff/oas/packages/oas/dist/analyzer/index.cjs","../../src/analyzer/dereference.ts","../../src/analyzer/query-cache.ts","../../src/analyzer/scope.ts","../../src/analyzer/queries/openapi.ts","../../src/analyzer/index.ts"],"names":["webhooks","query","additionalProperties","callbacks","commonParameters","discriminators","links","parameterSerialization","polymorphism","references","serverVariables","xmlRequests","xmlResponses","xmlSchemas"],"mappings":"AAAA;AACE;AACA;AACF,yDAA8B;AAC9B;AACE;AACA;AACA;AACA;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACF,yDAA8B;AAC9B;AACA;ACdA,uDAA4B;AAM5B,SAAS,uBAAA,CAAwB,YAAA,EAA2E;AAC1G,EAAA,OAAO;AAAA,IACL,OAAA,EAAS;AAAA;AAAA,MAEP,QAAA,EAAU;AAAA,IACZ,CAAA;AAAA,IACA,WAAA,EAAa;AAAA;AAAA;AAAA;AAAA,MAIX,QAAA,EAAU,QAAA;AAAA,MAEV,UAAA,EAAY,CAAC,IAAA,EAAA,GAAiB;AAK5B,QAAA,YAAA,CAAa,GAAA,CAAI,CAAA,CAAA,EAAI,IAAA,CAAK,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,CAAC,CAAA,CAAA;AACzC,MAAA;AACF,IAAA;AACF,EAAA;AACF;AAkB8B;AAE6C;AAC7B,EAAA;AAChC,EAAA;AACF,IAAA;AACM,MAAA;AACF,MAAA;AACK,MAAA;AACJ,MAAA;AACb,IAAA;AACuC,IAAA;AACzC,EAAA;AAEO,EAAA;AACT;AAkBiC;AACa,EAAA;AAER,EAAA;AACrB,IAAA;AACf,EAAA;AAEsB,EAAA;AACoB,IAAA;AACC,MAAA;AACxC,IAAA;AACH,EAAA;AAEmB,EAAA;AAEuB,EA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AA;AACO,IAAA;AAC3B,IAAA;AACE,MAAA;AACXC,MAAAA;AACb,IAAA;AACF,EAAA;AAE6B,EAAA;AACoB,IAAA;AACpB,IAAA;AACE,MAAA;AAChBC,MAAAA;AACb,IAAA;AACF,EAAA;AAE0C,EAAA;AACD,IAAA;AAChB,IAAA;AACE,MAAA;AACZC,MAAAA;AACb,IAAA;AACF,EAAA;AAE2C,EAAA;AACA,IAAA;AACjB,IAAA;AACE,MAAA;AACbC,MAAAA;AACb,IAAA;AACF,EAAA;AAE4C,EAAA;AACO,IAAA;AAC3B,IAAA;AACE,MAAA;AACXC,MAAAA;AACb,IAAA;AACF,EAAA;AAE0C,EAAA;AACU,IAAA;AAC9B,IAAA;AACE,MAAA;AACTb,MAAAA;AACb,IAAA;AACF,EAAA;AAEO,EAAA;AACT;AAOuG;AAC/D,EAAA;AACxC;AAaE;AACE,EAAA;AACA,EAAA;AACAC,EAAAA;AAMoB;AACc,EAAA;AACS,EAAA;AAC/C;AASE;AAEE,EAAA;AACA,EAAA;AACAA,EAAAA;AAMoB;AACQ,EAAA;AACR,IAAA;AACtB,EAAA;AAEsE,EAAA;AACzB,EAAA;AAC/C;ALyUgD;AACA;AACA;AACA;AACA","file":"/Users/darrenyong/Desktop/oas-stuff/oas/packages/oas/dist/analyzer/index.cjs","sourcesContent":[null,"import type { OASDocument } from '../types.js';\nimport type { ParserOptions } from '@readme/openapi-parser';\n\nimport { dereference } from '@readme/openapi-parser';\n\n/**\n * Retrive our dereferencing configuration for `@readme/openapi-parser`.\n *\n */\nfunction getDereferencingOptions(circularRefs: Set<string>): Pick<ParserOptions, 'resolve' | 'dereference'> {\n return {\n resolve: {\n // We shouldn't be resolving external pointers at this point so just ignore them.\n external: false,\n },\n dereference: {\n // If circular `$refs` are ignored they'll remain in the schema as `$ref: String`, otherwise\n // `$ref` just won't exist. This, in tandem with `onCircular`, allows us to do easy and\n // accumulate a list of circular references.\n circular: 'ignore',\n\n onCircular: (path: string) => {\n // The circular references that are coming out of `json-schema-ref-parser` are prefixed\n // with the schema path (file path, URL, whatever) that the schema exists in. Because we\n // don't care about this information for this reporting mechanism, and only the `$ref`\n // pointer, we're removing it.\n circularRefs.add(`#${path.split('#')[1]}`);\n },\n },\n };\n}\n\ninterface DereferenceOasResult {\n api: OASDocument;\n circularRefs: string[];\n}\n\ninterface DereferenceOasState {\n circularRefs: string[];\n complete: boolean;\n processing: boolean;\n promises: {\n reject: (err: unknown) => void;\n resolve: (result: DereferenceOasResult) => void;\n }[];\n result?: DereferenceOasResult;\n}\n\nconst dereferenceStates = new WeakMap<OASDocument, DereferenceOasState>();\n\nfunction getDereferenceState(definition: OASDocument): DereferenceOasState {\n let state = dereferenceStates.get(definition);\n if (!state) {\n state = {\n processing: false,\n complete: false,\n circularRefs: [],\n promises: [],\n };\n dereferenceStates.set(definition, state);\n }\n\n return state;\n}\n\n/**\n * Dereference a given OpenAPI definition so it can be parsed free from the hassle of resolving\n * `$ref` schemas and circular structures.\n *\n */\nexport async function dereferenceOas(\n definition: OASDocument,\n opts?: {\n /**\n * A callback method can be supplied to be called when dereferencing is complete. Used for\n * debugging that the multi-promise handling within this method works.\n *\n * @private\n */\n cb?: () => void;\n },\n): Promise<DereferenceOasResult> {\n const state = getDereferenceState(definition);\n\n if (state.complete && state.result) {\n return state.result;\n }\n\n if (state.processing) {\n return new Promise((resolve, reject) => {\n state.promises.push({ resolve, reject });\n });\n }\n\n state.processing = true;\n\n const circularRefs: Set<string> = new Set();\n const dereferencingOptions = getDereferencingOptions(circularRefs);\n const { promises } = state;\n\n return dereference<OASDocument>(definition, dereferencingOptions)\n .then((dereferenced: OASDocument) => {\n const result: DereferenceOasResult = {\n api: dereferenced,\n circularRefs: [...circularRefs],\n };\n\n state.result = result;\n state.circularRefs = result.circularRefs;\n state.processing = false;\n state.complete = true;\n\n // Used for debugging that dereferencing promise awaiting works.\n if (opts?.cb) {\n opts.cb();\n }\n\n return result;\n })\n .then(result => {\n promises.forEach(deferred => deferred.resolve(result));\n state.promises = [];\n return result;\n })\n .catch(err => {\n state.processing = false;\n promises.forEach(deferred => deferred.reject(err));\n state.promises = [];\n throw err;\n });\n}\n\n/**\n * `dereferenceOas()` caches its result against whatever object reference it's given, but callers\n * that care about not mutating their original definition (like the analyzer) have historically had\n * to pass in a fresh `structuredClone()` on every call — which means that cache is only ever a hit\n * within a single call, never across separate analyses of the same definition.\n *\n * This wraps that up: it clones the given definition exactly once and reuses that same clone (and\n * therefore `dereferenceOas()`'s cached result for it) for every subsequent call with the same\n * original definition reference. This is what lets the analyzer dereference a large API definition\n * a single time and reuse that work across an analysis of every operation within it, instead of\n * re-dereferencing the whole thing per-operation.\n *\n * @param definition An OpenAPI definition to dereference.\n */\nexport function dereferenceOasShared(definition: OASDocument): Promise<DereferenceOasResult> {\n let clone = sharedClones.get(definition);\n if (!clone) {\n clone = structuredClone(definition);\n sharedClones.set(definition, clone);\n }\n\n return dereferenceOas(clone);\n}\n\nconst sharedClones = new WeakMap<OASDocument, OASDocument>();\n","import type { JSONPathResult } from './util.js';\n\nimport { query } from './util.js';\n\nconst cache = new WeakMap<object, Map<string, JSONPathResult[]>>();\n\n/**\n * Every analyzer query in `queries/openapi.ts` runs one or more `$..`-style JSONPath scans across\n * the *entire* API definition, regardless of which operation (if any) we're ultimately interested\n * in. When analyzing a single operation that's cheap to do once, but when analyzing hundreds of\n * operations out of the same definition — which is the whole point of being able to scope analysis\n * to an operation instead of reducing the definition down first — re-running those same full-document\n * scans for every single operation throws away all of that shared work.\n *\n * This cache runs each unique set of JSONPath queries against a given definition exactly once and\n * hands back the same result array on every subsequent call, so callers can cheaply filter it down\n * per-operation instead of re-scanning the whole document each time.\n *\n * Cache entries are keyed by object identity (via `WeakMap`), so this is only effective when\n * callers reuse the same `definition` reference across calls — if you're handed a fresh clone every\n * time there's nothing to reuse. It also means definitions are never manually evicted from the\n * cache; they simply fall out of it once nothing else references them.\n *\n * @param queries JSONPath queries to run.\n * @param definition The object to run them against.\n */\nexport function queryCached(queries: string[], definition: object): JSONPathResult[] {\n let byQuery = cache.get(definition);\n if (!byQuery) {\n byQuery = new Map();\n cache.set(definition, byQuery);\n }\n\n // A space can't appear within a JSONPath query, so it's a safe delimiter to join on for a cache key.\n const cacheKey = queries.join(' ');\n\n let results = byQuery.get(cacheKey);\n if (!results) {\n results = query(queries, definition);\n byQuery.set(cacheKey, results);\n }\n\n return results;\n}\n","import type { OAS31Document, OASDocument, PathItemObject } from '../types.js';\n\nimport jsonPointer from 'jsonpointer';\n\nimport { collectRefsInSchema, dereferenceRef, encodePointer, toPointer } from '../lib/refs.js';\nimport { isRef } from '../types.js';\nimport { supportedMethods } from '../utils.js';\n\n/**\n * Convert a `$ref` into the same JSON pointer shape `jsonpath-plus` emits. Local refs may be\n * percent-encoded (`#/components/pathItems/pet%20ById`); `findRef` decodes that before lookup, so\n * query results live under the decoded key, not the authored encoding.\n */\nfunction canonicalizeRefPointer($ref: string): string {\n const pointer = toPointer($ref);\n try {\n return decodeURIComponent(pointer);\n } catch {\n return pointer;\n }\n}\n\n/**\n * Follow a Path Item `$ref` chain to the last local pointer that actually holds the Path Item.\n * Intermediate aliases and percent-encoded fragments must not become scope anchors — analysis\n * queries report locations under the terminal, decoded target.\n */\nfunction resolvePathItemTargetPointer(raw: unknown, definition: OASDocument): string | undefined {\n if (!isRef(raw)) {\n return undefined;\n }\n\n let current: unknown = raw;\n let lastRef = raw.$ref;\n const seen = new Set<string>();\n\n while (isRef(current)) {\n const ref = current.$ref;\n if (seen.has(ref)) {\n break;\n }\n seen.add(ref);\n lastRef = ref;\n\n let next: unknown;\n try {\n next = jsonPointer.get(definition, canonicalizeRefPointer(ref));\n } catch {\n break;\n }\n\n if (next === undefined || !isRef(next)) {\n break;\n }\n\n current = next;\n }\n\n return canonicalizeRefPointer(lastRef);\n}\n\n/**\n * The set of JSON pointers (in plain `/foo/bar` form, without the leading `#`) that describe\n * everything an operation or webhook touches: itself, any path-level (or webhook-level) common\n * parameters, and every `$ref` pointer that's reachable from either of those.\n *\n * This is what allows the analyzer to be run against a full, undreduced API definition and still\n * only report on what a single operation actually uses.\n */\nexport interface OperationScope {\n /**\n * `anchors`, each with a trailing `/` appended, precomputed once so `isPointerInScope()` isn't\n * concatenating a new string per anchor on every single pointer it checks. Analyzing an\n * operation can mean checking thousands of result pointers against this list, so avoiding a\n * string allocation per comparison meaningfully adds up.\n */\n anchorPrefixes: string[];\n\n /**\n * A flattened, precomputed list of every pointer prefix that's considered \"in scope\". This is\n * derived from `rootPointer`, `extraPointers`, and `reachableRefs` and exists purely so we don't\n * have to rebuild it for every pointer comparison we do.\n */\n anchors: string[];\n\n /**\n * Pointers, beyond `rootPointer`, that should be treated as belonging to this operation (e.g. a\n * path item's common `parameters`).\n */\n extraPointers: string[];\n\n /**\n * Every `$ref` pointer (in `#/...` form) that's transitively reachable from this operation.\n */\n reachableRefs: Set<string>;\n\n /**\n * The pointer to the operation (or webhook operation) itself, e.g. `/paths/~1pet/get` or\n * `/webhooks/newBooking/post`.\n */\n rootPointer: string;\n}\n\n/**\n * Case-insensitively find the real key for a given target within a list of keys. OpenAPI paths and\n * HTTP methods aren't case-sensitive as far as most tooling (including this) is concerned, but the\n * pointers we build need to match the casing that's actually in the document.\n *\n */\nfunction resolveKey(keys: string[], target: string): string | undefined {\n return keys.find(key => key === target) || keys.find(key => key.toLowerCase() === target.toLowerCase());\n}\n\n/**\n * Resolve a Path Item that may be a `$ref` (including OpenAPI 3.1 `components.pathItems`) without\n * mutating the authored definition. Returns `undefined` when the pointer cannot be followed.\n */\nfunction resolvePathItem(raw: unknown, definition: OASDocument): PathItemObject | undefined {\n const resolved = dereferenceRef(raw, definition);\n if (!resolved || typeof resolved !== 'object' || isRef(resolved)) {\n return undefined;\n }\n\n return resolved as PathItemObject;\n}\n\nfunction resolveMethodKey(container: object, method: string): string | undefined {\n const methodKey = resolveKey(Object.keys(container), method);\n if (!methodKey || !supportedMethods.includes(methodKey.toLowerCase() as (typeof supportedMethods)[number])) {\n return undefined;\n }\n\n return methodKey;\n}\n\n/**\n * Starting from a seed set of `$ref` pointers, recursively follow every `$ref` that they, or\n * anything they point to, contain and return the full set of pointers that are reachable.\n *\n * This intentionally mirrors the ref-walking that `OpenAPIReducer` does, but is read-only (no\n * cloning, no mutation) and resolves each `$ref` lazily against the original definition instead of\n * requiring a prebuilt map of every possible reference.\n *\n */\nfunction accumulateReachableRefs(definition: OASDocument, seeds: Iterable<string>): Set<string> {\n const reachable = new Set<string>();\n const queue = [...seeds];\n\n while (queue.length) {\n const ref = queue.shift() as string;\n if (reachable.has(ref)) {\n continue;\n }\n\n reachable.add(ref);\n\n let resolved: unknown;\n try {\n resolved = jsonPointer.get(definition, toPointer(ref));\n } catch {\n // If the `$ref` doesn't resolve to anything (a malformed pointer, an external ref we didn't\n // bundle, etc.) there's nothing further to walk from it.\n continue;\n }\n\n if (resolved === undefined) {\n continue;\n }\n\n collectRefsInSchema(resolved).forEach(nestedRef => {\n if (!reachable.has(nestedRef)) {\n queue.push(nestedRef);\n }\n });\n }\n\n return reachable;\n}\n\nfunction buildAnchors(\n rootPointer: string,\n extraPointers: string[],\n reachableRefs: Set<string>,\n): Pick<OperationScope, 'anchorPrefixes' | 'anchors'> {\n const anchors = [rootPointer, ...extraPointers];\n reachableRefs.forEach(ref => anchors.push(toPointer(ref)));\n\n return { anchors, anchorPrefixes: anchors.map(anchor => `${anchor}/`) };\n}\n\n/**\n * Accumulate the `#/components/securitySchemes/*` refs that a given set of security requirements\n * make use of.\n *\n */\nfunction collectSecuritySchemeRefs(security: unknown): string[] {\n if (!Array.isArray(security)) {\n return [];\n }\n\n const refs: string[] = [];\n security.forEach(requirement => {\n if (requirement && typeof requirement === 'object') {\n Object.keys(requirement).forEach(scheme => {\n refs.push(`#/components/securitySchemes/${scheme}`);\n });\n }\n });\n\n return refs;\n}\n\n/**\n * Compute the `OperationScope` for a single operation within an API definition, so that the\n * analyzer can report only on what that operation (and anything it references) actually uses,\n * without requiring the definition to be reduced down first.\n *\n */\nexport function computeOperationScope(definition: OASDocument, path: string, method: string): OperationScope {\n const pathKey = resolveKey(Object.keys(definition.paths || {}), path);\n if (!pathKey) {\n throw new Error(`Path \\`${path}\\` not found.`);\n }\n\n const rawPathItem = (definition.paths as Record<string, unknown>)[pathKey];\n const pathItem = resolvePathItem(rawPathItem, definition);\n if (!pathItem) {\n throw new Error(`Operation \\`${method} ${path}\\` not found.`);\n }\n\n const methodKey = resolveMethodKey(pathItem, method);\n if (!methodKey) {\n throw new Error(`Operation \\`${method} ${path}\\` not found.`);\n }\n\n const operation = pathItem[methodKey as keyof PathItemObject];\n if (!operation || typeof operation !== 'object') {\n throw new Error(`Operation \\`${method} ${path}\\` not found.`);\n }\n\n const rootPointer = `/paths/${encodePointer(pathKey)}/${methodKey}`;\n const extraPointers: string[] = [];\n const seeds = new Set<string>(collectRefsInSchema(operation));\n\n // Features on a referenced Path Item live at the *terminal* `$ref` target, not under\n // `/paths/{path}/{method}` and not under an intermediate alias or percent-encoded pointer.\n // Scope only this method (and its common parameters) so sibling operations stay out.\n const targetPointer = resolvePathItemTargetPointer(rawPathItem, definition);\n if (targetPointer) {\n extraPointers.push(`${targetPointer}/${methodKey}`);\n }\n\n if (pathItem.parameters) {\n extraPointers.push(targetPointer ? `${targetPointer}/parameters` : `/paths/${encodePointer(pathKey)}/parameters`);\n collectRefsInSchema(pathItem.parameters).forEach(ref => seeds.add(ref));\n }\n\n const security = 'security' in operation ? operation.security : definition.security;\n collectSecuritySchemeRefs(security).forEach(ref => seeds.add(ref));\n\n const reachableRefs = accumulateReachableRefs(definition, seeds);\n\n return { rootPointer, extraPointers, reachableRefs, ...buildAnchors(rootPointer, extraPointers, reachableRefs) };\n}\n\n/**\n * Compute the `OperationScope` for a single webhook operation within an OpenAPI 3.1 definition.\n *\n */\nexport function computeWebhookScope(definition: OAS31Document, webhookName: string, method: string): OperationScope {\n const webhooks = ('webhooks' in definition ? definition.webhooks : {}) as NonNullable<OAS31Document['webhooks']>;\n const webhookKey = resolveKey(Object.keys(webhooks || {}), webhookName);\n if (!webhookKey) {\n throw new Error(`Webhook \\`${webhookName}\\` not found.`);\n }\n\n const rawWebhook = (webhooks as Record<string, unknown>)[webhookKey];\n const webhook = resolvePathItem(rawWebhook, definition);\n if (!webhook) {\n throw new Error(`Webhook operation \\`${method} ${webhookName}\\` not found.`);\n }\n\n const methodKey = resolveMethodKey(webhook, method);\n if (!methodKey) {\n throw new Error(`Webhook operation \\`${method} ${webhookName}\\` not found.`);\n }\n\n const operation = webhook[methodKey as keyof PathItemObject];\n if (!operation || typeof operation !== 'object') {\n throw new Error(`Webhook operation \\`${method} ${webhookName}\\` not found.`);\n }\n\n const rootPointer = `/webhooks/${encodePointer(webhookKey)}/${methodKey}`;\n const extraPointers: string[] = [];\n const seeds = new Set<string>(collectRefsInSchema(operation));\n\n const targetPointer = resolvePathItemTargetPointer(rawWebhook, definition);\n if (targetPointer) {\n extraPointers.push(`${targetPointer}/${methodKey}`);\n }\n\n if (webhook.parameters) {\n extraPointers.push(\n targetPointer ? `${targetPointer}/parameters` : `/webhooks/${encodePointer(webhookKey)}/parameters`,\n );\n collectRefsInSchema(webhook.parameters).forEach(ref => seeds.add(ref));\n }\n\n const security = 'security' in operation ? operation.security : definition.security;\n collectSecuritySchemeRefs(security).forEach(ref => seeds.add(ref));\n\n const reachableRefs = accumulateReachableRefs(definition, seeds);\n\n return { rootPointer, extraPointers, reachableRefs, ...buildAnchors(rootPointer, extraPointers, reachableRefs) };\n}\n\n/**\n * Determine if a given JSON pointer (as returned by `jsonpath-plus`, without a leading `#`) falls\n * within a given `OperationScope`.\n *\n */\nexport function isPointerInScope(pointer: string, scope: OperationScope): boolean {\n const { anchors, anchorPrefixes } = scope;\n for (let i = 0; i < anchors.length; i += 1) {\n if (pointer === anchors[i] || pointer.startsWith(anchorPrefixes[i])) {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Determine if a given `OperationScope`'s root is nested *within* a given pointer. This is the\n * inverse of `isPointerInScope()` and exists for the handful of queries (like our `webhooks` one)\n * that report on a coarser pointer than the specific operation we're scoped to, e.g. reporting on\n * `/webhooks/newBooking` as a whole when we're scoped to `/webhooks/newBooking/post`.\n *\n */\nexport function isAncestorOfScope(pointer: string, scope: OperationScope): boolean {\n return scope.rootPointer === pointer || scope.rootPointer.startsWith(`${pointer}/`);\n}\n","import type { OASDocument } from '../../types.js';\nimport type { OperationScope } from '../scope.js';\nimport type { JSONPathResult } from '../util.js';\n\nimport { toPointer } from '../../lib/refs.js';\nimport { dereferenceOas } from '../dereference.js';\nimport { queryCached } from '../query-cache.js';\nimport { isAncestorOfScope, isPointerInScope } from '../scope.js';\nimport { refizePointer } from '../util.js';\n\n/**\n * Narrow a set of JSONPath results down to only the ones that fall within a given operation's\n * scope. When no scope is supplied every result is considered in scope, which preserves the\n * whole-document behavior these queries have always had.\n *\n */\nfunction filterByScope(results: JSONPathResult[], scope?: OperationScope): JSONPathResult[] {\n if (!scope) {\n return results;\n }\n\n return results.filter(res => isPointerInScope(res.pointer, scope));\n}\n\n/**\n * Determine if a given API definition uses the `additionalProperties` schema property.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport function additionalProperties(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(queryCached(['$..additionalProperties'], definition), scope).map(res =>\n refizePointer(res.pointer),\n );\n}\n\n/**\n * Determine if a given API definition utilizes `callbacks`.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callback-object}\n */\nexport function callbacks(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(\n queryCached(['$.components.callbacks', '$.paths.*[?(@.callbacks)].callbacks'], definition),\n scope,\n ).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition has circular refs.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport async function circularRefs(definition: OASDocument, scope?: OperationScope): Promise<string[]> {\n // Dereferencing will update the passed in variable, which we don't want to do, so we\n // instantiated `Oas` with a clone.\n const { circularRefs: refs } = await dereferenceOas(structuredClone(definition));\n\n const results = scope ? refs.filter(ref => isPointerInScope(toPointer(ref), scope)) : [...refs];\n results.sort();\n return results;\n}\n\n/**\n * Determine if a given API definition utilizes common parameters.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#path-item-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#path-item-object}\n */\nexport function commonParameters(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(queryCached(['$..paths[*].parameters'], definition), scope).map(res =>\n refizePointer(res.pointer),\n );\n}\n\n/**\n * Determine if a given API definition utilizes discriminators.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminator-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#discriminator-object}\n */\nexport function discriminators(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(queryCached(['$..discriminator'], definition), scope).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilizes `links`.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#link-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#link-object}\n */\nexport function links(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(queryCached(['$.components.links', '$.paths..responses.*.links'], definition), scope).map(res =>\n refizePointer(res.pointer),\n );\n}\n\n/**\n * Determine all of the available media types used within an API definition.\n *\n * @todo This query currently picks up false positives if there is an object named `content`.\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#request-body-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#request-body-object}\n */\nexport function mediaTypes(definition: OASDocument, scope?: OperationScope): string[] {\n const results = Array.from(\n new Set(\n filterByScope(\n queryCached(\n [\n '$..paths..content',\n '$.components.requestBodies..content',\n '$.components.responses..content',\n '$.webhooks..content',\n ],\n definition,\n ),\n scope,\n ).flatMap(res => {\n // This'll transform `results`, which looks like `[['application/json'], ['text/xml']]`\n // into `['application/json', 'text/xml']`.\n return Object.keys(res.value);\n }),\n ),\n );\n\n results.sort();\n return results;\n}\n\n/**\n * Determine if a given API definition uses parameter serialization.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameter-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object}\n */\nexport function parameterSerialization(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(queryCached(['$..parameters[*].style^'], definition), scope).map(res =>\n refizePointer(res.pointer),\n );\n}\n\n/**\n * Determine if a given API definition utilizes schema polymorphism and/of interitance.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport function polymorphism(definition: OASDocument, scope?: OperationScope): string[] {\n const results = Array.from(\n new Set(\n filterByScope(queryCached(['$..allOf^', '$..anyOf^', '$..oneOf^'], definition), scope).map(res =>\n refizePointer(res.pointer),\n ),\n ),\n );\n\n results.sort();\n return results;\n}\n\n/**\n * Determine if a given API definition utilizes `$ref` pointers.\n *\n */\nexport function references(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(queryCached(['$..$ref^'], definition), scope).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine every kind of security type that a given API definition has documented.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#security-scheme-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#security-scheme-object}\n */\nexport function securityTypes(definition: OASDocument, scope?: OperationScope): string[] {\n return Array.from(\n new Set(\n filterByScope(queryCached(['$.components.securitySchemes..type'], definition), scope).map(\n res => res.value as string,\n ),\n ),\n );\n}\n\n/**\n * Determine if a given API definition utilizes server variables.\n *\n * Root-level `servers` apply to every operation unless a path or operation overrides them, so\n * these are always considered in scope regardless of which operation is being analyzed.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#server-variable-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#server-variable-object}\n */\nexport function serverVariables(definition: OASDocument): string[] {\n return queryCached(['$.servers..variables^'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine how many operations are defined in a given API definition.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operation-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operation-object}\n */\nexport function totalOperations(definition: OASDocument): number {\n return queryCached(['$..paths[*]'], definition).flatMap(res => Object.keys(res.value)).length;\n}\n\n/**\n * Determine if a given API definition utilizes `webhooks` support in OpenAPI 3.1.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#oasWebhooks}\n */\nexport function webhooks(definition: OASDocument, scope?: OperationScope): string[] {\n const results = queryCached(['$.webhooks[*]'], definition);\n if (!scope) {\n return results.map(res => refizePointer(res.pointer));\n }\n\n // This query reports on an entire webhook (`/webhooks/newBooking`) rather than a specific\n // method on it, so a scope's root pointer (`/webhooks/newBooking/post`) is a *descendant* of a\n // matching result rather than the other way around. We still want to catch the normal case too,\n // where an operation reaches into a webhook by way of a `$ref`.\n return results\n .filter(res => isPointerInScope(res.pointer, scope) || isAncestorOfScope(res.pointer, scope))\n .map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition uses XML in a request body payload.\n *\n * @todo detect `+xml` media types\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n */\nexport function xmlRequests(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(\n queryCached(\n [\n \"$..requestBody..['application/xml']\",\n \"$..requestBody..['application/xml-external-parsed-entity']\",\n \"$..requestBody..['application/xml-dtd']\",\n \"$..requestBody..['text/xml']\",\n \"$..requestBody..['text/xml-external-parsed-entity']\",\n '$..requestBody.content[?(@property.match(/\\\\+xml$/i))]',\n ],\n definition,\n ),\n scope,\n ).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition uses XML in a response body.\n *\n * @todo detect `+xml` media types\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n */\nexport function xmlResponses(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(\n queryCached(\n [\n \"$..responses..['application/xml']\",\n \"$..responses..['application/xml-external-parsed-entity']\",\n \"$..responses..['application/xml-dtd']\",\n \"$..responses..['text/xml']\",\n \"$..responses..['text/xml-external-parsed-entity']\",\n '$..responses[*].content[?(@property.match(/\\\\+xml$/i))]',\n ],\n definition,\n ),\n scope,\n ).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilises the XML object for defining XML schemas.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#xml-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#xml-object}\n */\nexport function xmlSchemas(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(\n queryCached(['$.components.schemas..xml^', '$..parameters..xml^', '$..requestBody..xml^'], definition),\n scope,\n ).map(res => refizePointer(res.pointer));\n}\n","import type { OAS31Document, OASDocument } from '../types.js';\nimport type { OperationScope } from './scope.js';\nimport type { AnalyzerQuery, OASAnalysis } from './types.js';\n\nimport { toPointer } from '../lib/refs.js';\nimport { isOpenAPI31 } from '../types.js';\n\nimport { dereferenceOasShared } from './dereference.js';\nimport {\n additionalProperties as analyzeAdditionalProperties,\n callbacks as analyzeCallbacks,\n commonParameters as analyzeCommonParameters,\n discriminators as analyzeDiscriminators,\n links as analyzeLinks,\n mediaTypes as analyzeMediaTypes,\n parameterSerialization as analyzeParameterSerialization,\n polymorphism as analyzePolymorphism,\n references as analyzeReferences,\n securityTypes as analyzeSecurityTypes,\n serverVariables as analyzeServerVariables,\n totalOperations as analyzeTotalOperations,\n webhooks as analyzeWebhooks,\n xmlRequests as analyzeXMLRequests,\n xmlResponses as analyzeXMLResponses,\n xmlSchemas as analyzeXMLSchemas,\n} from './queries/openapi.js';\nimport { computeOperationScope, computeWebhookScope, isPointerInScope } from './scope.js';\n\n/**\n * Run every analyzer query against a definition, optionally narrowed down to a single operation or\n * webhook's `OperationScope`.\n *\n * This is the shared implementation behind `analyzer()`, `analyzeOperation()`, and\n * `analyzeWebhookOperation()`. Dereferencing (the most expensive step here) is cached against the\n * original `definition` reference via `dereferenceOasShared()`, and every JSONPath scan that the\n * individual queries run is cached against it as well, so calling this repeatedly for many\n * operations out of the same definition only pays the full-document cost once.\n *\n */\nasync function buildAnalysis(\n definition: OASDocument,\n query?: AnalyzerQuery[],\n scope?: OperationScope,\n): Promise<OASAnalysis> {\n const analysis: OASAnalysis = {};\n\n if (!query || query.includes('mediaTypes')) {\n analysis.mediaTypes = {\n name: 'Media Type',\n found: analyzeMediaTypes(definition, scope),\n };\n }\n\n if (!query || query.includes('operationTotal')) {\n analysis.operationTotal = {\n name: 'Operation',\n // A scoped analysis is, by definition, looking at exactly one operation.\n found: scope ? 1 : analyzeTotalOperations(definition),\n };\n }\n\n if (!query || query.includes('securityTypes')) {\n analysis.securityTypes = {\n name: 'Security Type',\n found: analyzeSecurityTypes(definition, scope),\n };\n }\n\n if (!query || query.includes('additionalProperties')) {\n const additionalProperties = analyzeAdditionalProperties(definition, scope);\n analysis.additionalProperties = {\n present: !!additionalProperties.length,\n locations: additionalProperties,\n };\n }\n\n if (!query || query.includes('callbacks')) {\n const callbacks = analyzeCallbacks(definition, scope);\n analysis.callbacks = {\n present: !!callbacks.length,\n locations: callbacks,\n };\n }\n\n if (!query || query.includes('circularRefs')) {\n const { circularRefs: dereferencedCircularRefs } = await dereferenceOasShared(definition);\n const circularRefs = (\n scope\n ? dereferencedCircularRefs.filter(ref => isPointerInScope(toPointer(ref), scope))\n : [...dereferencedCircularRefs]\n ).toSorted();\n\n analysis.circularRefs = {\n present: !!circularRefs.length,\n locations: circularRefs,\n };\n }\n\n if (!query || query.includes('commonParameters')) {\n const commonParameters = analyzeCommonParameters(definition, scope);\n analysis.commonParameters = {\n present: !!commonParameters.length,\n locations: commonParameters,\n };\n }\n\n if (!query || query.includes('discriminators')) {\n const discriminators = analyzeDiscriminators(definition, scope);\n analysis.discriminators = {\n present: !!discriminators.length,\n locations: discriminators,\n };\n }\n\n if (!query || query.includes('links')) {\n const links = analyzeLinks(definition, scope);\n analysis.links = {\n present: !!links.length,\n locations: links,\n };\n }\n\n if (!query || query.includes('style')) {\n const parameterSerialization = analyzeParameterSerialization(definition, scope);\n analysis.style = {\n present: !!parameterSerialization.length,\n locations: parameterSerialization,\n };\n }\n\n if (!query || query.includes('polymorphism')) {\n const polymorphism = analyzePolymorphism(definition, scope);\n analysis.polymorphism = {\n present: !!polymorphism.length,\n locations: polymorphism,\n };\n }\n\n if (!query || query.includes('references')) {\n const references = analyzeReferences(definition, scope);\n analysis.references = {\n present: !!references.length,\n locations: references,\n };\n }\n\n if (!query || query.includes('serverVariables')) {\n const serverVariables = analyzeServerVariables(definition);\n analysis.serverVariables = {\n present: !!serverVariables.length,\n locations: serverVariables,\n };\n }\n\n if (!query || query.includes('xmlRequests')) {\n const xmlRequests = analyzeXMLRequests(definition, scope);\n analysis.xmlRequests = {\n present: !!xmlRequests.length,\n locations: xmlRequests,\n };\n }\n\n if (!query || query.includes('xmlResponses')) {\n const xmlResponses = analyzeXMLResponses(definition, scope);\n analysis.xmlResponses = {\n present: !!xmlResponses.length,\n locations: xmlResponses,\n };\n }\n\n if (!query || query.includes('xmlSchemas')) {\n const xmlSchemas = analyzeXMLSchemas(definition, scope);\n analysis.xmlSchemas = {\n present: !!xmlSchemas.length,\n locations: xmlSchemas,\n };\n }\n\n if (!query || query.includes('webhooks')) {\n const webhooks = analyzeWebhooks(definition, scope);\n analysis.webhooks = {\n present: !!webhooks.length,\n locations: webhooks,\n };\n }\n\n return analysis;\n}\n\n/**\n * Analyze a given OpenAPI or Swagger definition for any, or a specific, OpenAPI or JSON Schema\n * feature uses it may contain or utilize.\n *\n */\nexport async function analyzer(definition: OASDocument, query?: AnalyzerQuery[]): Promise<OASAnalysis> {\n return buildAnalysis(definition, query);\n}\n\n/**\n * Analyze a single operation within a given OpenAPI definition for any, or a specific, OpenAPI or\n * JSON Schema feature uses that it, or anything it references, may contain or utilize.\n *\n * When analyzing many operations out of the same definition, pass the *same* `definition`\n * reference to every call — the expensive dereferencing and document-wide JSONPath scans that this\n * relies on are cached against that reference, so only the first call pays for them.\n *\n */\nexport async function analyzeOperation(\n definition: OASDocument,\n {\n path,\n method,\n query,\n }: {\n path: string;\n method: string;\n query?: AnalyzerQuery[];\n },\n): Promise<OASAnalysis> {\n const scope = computeOperationScope(definition, path, method);\n return buildAnalysis(definition, query, scope);\n}\n\n/**\n * Analyze a single webhook operation within a given OpenAPI 3.1 definition for any, or a specific,\n * OpenAPI or JSON Schema feature uses that it, or anything it references, may contain or utilize.\n *\n * @see {@link analyzeOperation}\n */\nexport async function analyzeWebhookOperation(\n definition: OASDocument,\n {\n webhookName,\n method,\n query,\n }: {\n webhookName: string;\n method: string;\n query?: AnalyzerQuery[];\n },\n): Promise<OASAnalysis> {\n if (!isOpenAPI31(definition)) {\n throw new TypeError('The supplied definition is not a OpenAPI 3.1 definition.');\n }\n\n const scope = computeWebhookScope(definition satisfies OAS31Document, webhookName, method);\n return buildAnalysis(definition, query, scope);\n}\n"]}
1
+ {"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas/dist/analyzer/index.cjs","../../src/analyzer/dereference.ts","../../src/analyzer/query-cache.ts","../../src/analyzer/scope.ts","../../src/analyzer/queries/openapi.ts","../../src/analyzer/index.ts"],"names":["webhooks","query","additionalProperties","callbacks","commonParameters","discriminators","links","parameterSerialization","polymorphism","references","serverVariables","xmlRequests","xmlResponses","xmlSchemas"],"mappings":"AAAA;AACE;AACA;AACF,yDAA8B;AAC9B;AACE;AACA;AACA;AACA;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACF,yDAA8B;AAC9B;AACA;ACdA,uDAA4B;AAM5B,SAAS,uBAAA,CAAwB,YAAA,EAA2E;AAC1G,EAAA,OAAO;AAAA,IACL,OAAA,EAAS;AAAA;AAAA,MAEP,QAAA,EAAU;AAAA,IACZ,CAAA;AAAA,IACA,WAAA,EAAa;AAAA;AAAA;AAAA;AAAA,MAIX,QAAA,EAAU,QAAA;AAAA,MAEV,UAAA,EAAY,CAAC,IAAA,EAAA,GAAiB;AAK5B,QAAA,YAAA,CAAa,GAAA,CAAI,CAAA,CAAA,EAAI,IAAA,CAAK,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,CAAC,CAAA,CAAA;AACzC,MAAA;AACF,IAAA;AACF,EAAA;AACF;AAkB8B;AAE6C;AAC7B,EAAA;AAChC,EAAA;AACF,IAAA;AACM,MAAA;AACF,MAAA;AACK,MAAA;AACJ,MAAA;AACb,IAAA;AACuC,IAAA;AACzC,EAAA;AAEO,EAAA;AACT;AAkBiC;AACa,EAAA;AAER,EAAA;AACrB,IAAA;AACf,EAAA;AAEsB,EAAA;AACoB,IAAA;AACC,MAAA;AACxC,IAAA;AACH,EAAA;AAEm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F,EAAA;AAE4C,EAAA;AACO,IAAA;AAC3B,IAAA;AACE,MAAA;AACXC,MAAAA;AACb,IAAA;AACF,EAAA;AAE6B,EAAA;AACoB,IAAA;AACpB,IAAA;AACE,MAAA;AAChBC,MAAAA;AACb,IAAA;AACF,EAAA;AAE0C,EAAA;AACD,IAAA;AAChB,IAAA;AACE,MAAA;AACZC,MAAAA;AACb,IAAA;AACF,EAAA;AAE2C,EAAA;AACA,IAAA;AACjB,IAAA;AACE,MAAA;AACbC,MAAAA;AACb,IAAA;AACF,EAAA;AAE4C,EAAA;AACO,IAAA;AAC3B,IAAA;AACE,MAAA;AACXC,MAAAA;AACb,IAAA;AACF,EAAA;AAE0C,EAAA;AACU,IAAA;AAC9B,IAAA;AACE,MAAA;AACTb,MAAAA;AACb,IAAA;AACF,EAAA;AAEO,EAAA;AACT;AAOuG;AAC/D,EAAA;AACxC;AAaE;AACE,EAAA;AACA,EAAA;AACAC,EAAAA;AAMoB;AACc,EAAA;AACS,EAAA;AAC/C;AASE;AAEE,EAAA;AACA,EAAA;AACAA,EAAAA;AAMoB;AACQ,EAAA;AACR,IAAA;AACtB,EAAA;AAEsE,EAAA;AACzB,EAAA;AAC/C;ALyUgD;AACA;AACA;AACA;AACA","file":"/Users/erunion/code/readme/oas/packages/oas/dist/analyzer/index.cjs","sourcesContent":[null,"import type { OASDocument } from '../types.js';\nimport type { ParserOptions } from '@readme/openapi-parser';\n\nimport { dereference } from '@readme/openapi-parser';\n\n/**\n * Retrive our dereferencing configuration for `@readme/openapi-parser`.\n *\n */\nfunction getDereferencingOptions(circularRefs: Set<string>): Pick<ParserOptions, 'resolve' | 'dereference'> {\n return {\n resolve: {\n // We shouldn't be resolving external pointers at this point so just ignore them.\n external: false,\n },\n dereference: {\n // If circular `$refs` are ignored they'll remain in the schema as `$ref: String`, otherwise\n // `$ref` just won't exist. This, in tandem with `onCircular`, allows us to do easy and\n // accumulate a list of circular references.\n circular: 'ignore',\n\n onCircular: (path: string) => {\n // The circular references that are coming out of `json-schema-ref-parser` are prefixed\n // with the schema path (file path, URL, whatever) that the schema exists in. Because we\n // don't care about this information for this reporting mechanism, and only the `$ref`\n // pointer, we're removing it.\n circularRefs.add(`#${path.split('#')[1]}`);\n },\n },\n };\n}\n\ninterface DereferenceOasResult {\n api: OASDocument;\n circularRefs: string[];\n}\n\ninterface DereferenceOasState {\n circularRefs: string[];\n complete: boolean;\n processing: boolean;\n promises: {\n reject: (err: unknown) => void;\n resolve: (result: DereferenceOasResult) => void;\n }[];\n result?: DereferenceOasResult;\n}\n\nconst dereferenceStates = new WeakMap<OASDocument, DereferenceOasState>();\n\nfunction getDereferenceState(definition: OASDocument): DereferenceOasState {\n let state = dereferenceStates.get(definition);\n if (!state) {\n state = {\n processing: false,\n complete: false,\n circularRefs: [],\n promises: [],\n };\n dereferenceStates.set(definition, state);\n }\n\n return state;\n}\n\n/**\n * Dereference a given OpenAPI definition so it can be parsed free from the hassle of resolving\n * `$ref` schemas and circular structures.\n *\n */\nexport async function dereferenceOas(\n definition: OASDocument,\n opts?: {\n /**\n * A callback method can be supplied to be called when dereferencing is complete. Used for\n * debugging that the multi-promise handling within this method works.\n *\n * @private\n */\n cb?: () => void;\n },\n): Promise<DereferenceOasResult> {\n const state = getDereferenceState(definition);\n\n if (state.complete && state.result) {\n return state.result;\n }\n\n if (state.processing) {\n return new Promise((resolve, reject) => {\n state.promises.push({ resolve, reject });\n });\n }\n\n state.processing = true;\n\n const circularRefs: Set<string> = new Set();\n const dereferencingOptions = getDereferencingOptions(circularRefs);\n const { promises } = state;\n\n return dereference<OASDocument>(definition, dereferencingOptions)\n .then((dereferenced: OASDocument) => {\n const result: DereferenceOasResult = {\n api: dereferenced,\n circularRefs: [...circularRefs],\n };\n\n state.result = result;\n state.circularRefs = result.circularRefs;\n state.processing = false;\n state.complete = true;\n\n // Used for debugging that dereferencing promise awaiting works.\n if (opts?.cb) {\n opts.cb();\n }\n\n return result;\n })\n .then(result => {\n promises.forEach(deferred => deferred.resolve(result));\n state.promises = [];\n return result;\n })\n .catch(err => {\n state.processing = false;\n promises.forEach(deferred => deferred.reject(err));\n state.promises = [];\n throw err;\n });\n}\n\n/**\n * `dereferenceOas()` caches its result against whatever object reference it's given, but callers\n * that care about not mutating their original definition (like the analyzer) have historically had\n * to pass in a fresh `structuredClone()` on every call — which means that cache is only ever a hit\n * within a single call, never across separate analyses of the same definition.\n *\n * This wraps that up: it clones the given definition exactly once and reuses that same clone (and\n * therefore `dereferenceOas()`'s cached result for it) for every subsequent call with the same\n * original definition reference. This is what lets the analyzer dereference a large API definition\n * a single time and reuse that work across an analysis of every operation within it, instead of\n * re-dereferencing the whole thing per-operation.\n *\n * @param definition An OpenAPI definition to dereference.\n */\nexport function dereferenceOasShared(definition: OASDocument): Promise<DereferenceOasResult> {\n let clone = sharedClones.get(definition);\n if (!clone) {\n clone = structuredClone(definition);\n sharedClones.set(definition, clone);\n }\n\n return dereferenceOas(clone);\n}\n\nconst sharedClones = new WeakMap<OASDocument, OASDocument>();\n","import type { JSONPathResult } from './util.js';\n\nimport { query } from './util.js';\n\nconst cache = new WeakMap<object, Map<string, JSONPathResult[]>>();\n\n/**\n * Every analyzer query in `queries/openapi.ts` runs one or more `$..`-style JSONPath scans across\n * the *entire* API definition, regardless of which operation (if any) we're ultimately interested\n * in. When analyzing a single operation that's cheap to do once, but when analyzing hundreds of\n * operations out of the same definition — which is the whole point of being able to scope analysis\n * to an operation instead of reducing the definition down first — re-running those same full-document\n * scans for every single operation throws away all of that shared work.\n *\n * This cache runs each unique set of JSONPath queries against a given definition exactly once and\n * hands back the same result array on every subsequent call, so callers can cheaply filter it down\n * per-operation instead of re-scanning the whole document each time.\n *\n * Cache entries are keyed by object identity (via `WeakMap`), so this is only effective when\n * callers reuse the same `definition` reference across calls — if you're handed a fresh clone every\n * time there's nothing to reuse. It also means definitions are never manually evicted from the\n * cache; they simply fall out of it once nothing else references them.\n *\n * @param queries JSONPath queries to run.\n * @param definition The object to run them against.\n */\nexport function queryCached(queries: string[], definition: object): JSONPathResult[] {\n let byQuery = cache.get(definition);\n if (!byQuery) {\n byQuery = new Map();\n cache.set(definition, byQuery);\n }\n\n // A space can't appear within a JSONPath query, so it's a safe delimiter to join on for a cache key.\n const cacheKey = queries.join(' ');\n\n let results = byQuery.get(cacheKey);\n if (!results) {\n results = query(queries, definition);\n byQuery.set(cacheKey, results);\n }\n\n return results;\n}\n","import type { OAS31Document, OASDocument, PathItemObject } from '../types.js';\n\nimport jsonPointer from 'jsonpointer';\n\nimport { collectRefsInSchema, dereferenceRef, encodePointer, toPointer } from '../lib/refs.js';\nimport { isRef } from '../types.js';\nimport { supportedMethods } from '../utils.js';\n\n/**\n * Convert a `$ref` into the same JSON pointer shape `jsonpath-plus` emits. Local refs may be\n * percent-encoded (`#/components/pathItems/pet%20ById`); `findRef` decodes that before lookup, so\n * query results live under the decoded key, not the authored encoding.\n */\nfunction canonicalizeRefPointer($ref: string): string {\n const pointer = toPointer($ref);\n try {\n return decodeURIComponent(pointer);\n } catch {\n return pointer;\n }\n}\n\n/**\n * Follow a Path Item `$ref` chain to the last local pointer that actually holds the Path Item.\n * Intermediate aliases and percent-encoded fragments must not become scope anchors — analysis\n * queries report locations under the terminal, decoded target.\n */\nfunction resolvePathItemTargetPointer(raw: unknown, definition: OASDocument): string | undefined {\n if (!isRef(raw)) {\n return undefined;\n }\n\n let current: unknown = raw;\n let lastRef = raw.$ref;\n const seen = new Set<string>();\n\n while (isRef(current)) {\n const ref = current.$ref;\n if (seen.has(ref)) {\n break;\n }\n seen.add(ref);\n lastRef = ref;\n\n let next: unknown;\n try {\n next = jsonPointer.get(definition, canonicalizeRefPointer(ref));\n } catch {\n break;\n }\n\n if (next === undefined || !isRef(next)) {\n break;\n }\n\n current = next;\n }\n\n return canonicalizeRefPointer(lastRef);\n}\n\n/**\n * The set of JSON pointers (in plain `/foo/bar` form, without the leading `#`) that describe\n * everything an operation or webhook touches: itself, any path-level (or webhook-level) common\n * parameters, and every `$ref` pointer that's reachable from either of those.\n *\n * This is what allows the analyzer to be run against a full, undreduced API definition and still\n * only report on what a single operation actually uses.\n */\nexport interface OperationScope {\n /**\n * `anchors`, each with a trailing `/` appended, precomputed once so `isPointerInScope()` isn't\n * concatenating a new string per anchor on every single pointer it checks. Analyzing an\n * operation can mean checking thousands of result pointers against this list, so avoiding a\n * string allocation per comparison meaningfully adds up.\n */\n anchorPrefixes: string[];\n\n /**\n * A flattened, precomputed list of every pointer prefix that's considered \"in scope\". This is\n * derived from `rootPointer`, `extraPointers`, and `reachableRefs` and exists purely so we don't\n * have to rebuild it for every pointer comparison we do.\n */\n anchors: string[];\n\n /**\n * Pointers, beyond `rootPointer`, that should be treated as belonging to this operation (e.g. a\n * path item's common `parameters`).\n */\n extraPointers: string[];\n\n /**\n * Every `$ref` pointer (in `#/...` form) that's transitively reachable from this operation.\n */\n reachableRefs: Set<string>;\n\n /**\n * The pointer to the operation (or webhook operation) itself, e.g. `/paths/~1pet/get` or\n * `/webhooks/newBooking/post`.\n */\n rootPointer: string;\n}\n\n/**\n * Case-insensitively find the real key for a given target within a list of keys. OpenAPI paths and\n * HTTP methods aren't case-sensitive as far as most tooling (including this) is concerned, but the\n * pointers we build need to match the casing that's actually in the document.\n *\n */\nfunction resolveKey(keys: string[], target: string): string | undefined {\n return keys.find(key => key === target) || keys.find(key => key.toLowerCase() === target.toLowerCase());\n}\n\n/**\n * Resolve a Path Item that may be a `$ref` (including OpenAPI 3.1 `components.pathItems`) without\n * mutating the authored definition. Returns `undefined` when the pointer cannot be followed.\n */\nfunction resolvePathItem(raw: unknown, definition: OASDocument): PathItemObject | undefined {\n const resolved = dereferenceRef(raw, definition);\n if (!resolved || typeof resolved !== 'object' || isRef(resolved)) {\n return undefined;\n }\n\n return resolved as PathItemObject;\n}\n\nfunction resolveMethodKey(container: object, method: string): string | undefined {\n const methodKey = resolveKey(Object.keys(container), method);\n if (!methodKey || !supportedMethods.includes(methodKey.toLowerCase() as (typeof supportedMethods)[number])) {\n return undefined;\n }\n\n return methodKey;\n}\n\n/**\n * Starting from a seed set of `$ref` pointers, recursively follow every `$ref` that they, or\n * anything they point to, contain and return the full set of pointers that are reachable.\n *\n * This intentionally mirrors the ref-walking that `OpenAPIReducer` does, but is read-only (no\n * cloning, no mutation) and resolves each `$ref` lazily against the original definition instead of\n * requiring a prebuilt map of every possible reference.\n *\n */\nfunction accumulateReachableRefs(definition: OASDocument, seeds: Iterable<string>): Set<string> {\n const reachable = new Set<string>();\n const queue = [...seeds];\n\n while (queue.length) {\n const ref = queue.shift() as string;\n if (reachable.has(ref)) {\n continue;\n }\n\n reachable.add(ref);\n\n let resolved: unknown;\n try {\n resolved = jsonPointer.get(definition, toPointer(ref));\n } catch {\n // If the `$ref` doesn't resolve to anything (a malformed pointer, an external ref we didn't\n // bundle, etc.) there's nothing further to walk from it.\n continue;\n }\n\n if (resolved === undefined) {\n continue;\n }\n\n collectRefsInSchema(resolved).forEach(nestedRef => {\n if (!reachable.has(nestedRef)) {\n queue.push(nestedRef);\n }\n });\n }\n\n return reachable;\n}\n\nfunction buildAnchors(\n rootPointer: string,\n extraPointers: string[],\n reachableRefs: Set<string>,\n): Pick<OperationScope, 'anchorPrefixes' | 'anchors'> {\n const anchors = [rootPointer, ...extraPointers];\n reachableRefs.forEach(ref => anchors.push(toPointer(ref)));\n\n return { anchors, anchorPrefixes: anchors.map(anchor => `${anchor}/`) };\n}\n\n/**\n * Accumulate the `#/components/securitySchemes/*` refs that a given set of security requirements\n * make use of.\n *\n */\nfunction collectSecuritySchemeRefs(security: unknown): string[] {\n if (!Array.isArray(security)) {\n return [];\n }\n\n const refs: string[] = [];\n security.forEach(requirement => {\n if (requirement && typeof requirement === 'object') {\n Object.keys(requirement).forEach(scheme => {\n refs.push(`#/components/securitySchemes/${scheme}`);\n });\n }\n });\n\n return refs;\n}\n\n/**\n * Compute the `OperationScope` for a single operation within an API definition, so that the\n * analyzer can report only on what that operation (and anything it references) actually uses,\n * without requiring the definition to be reduced down first.\n *\n */\nexport function computeOperationScope(definition: OASDocument, path: string, method: string): OperationScope {\n const pathKey = resolveKey(Object.keys(definition.paths || {}), path);\n if (!pathKey) {\n throw new Error(`Path \\`${path}\\` not found.`);\n }\n\n const rawPathItem = (definition.paths as Record<string, unknown>)[pathKey];\n const pathItem = resolvePathItem(rawPathItem, definition);\n if (!pathItem) {\n throw new Error(`Operation \\`${method} ${path}\\` not found.`);\n }\n\n const methodKey = resolveMethodKey(pathItem, method);\n if (!methodKey) {\n throw new Error(`Operation \\`${method} ${path}\\` not found.`);\n }\n\n const operation = pathItem[methodKey as keyof PathItemObject];\n if (!operation || typeof operation !== 'object') {\n throw new Error(`Operation \\`${method} ${path}\\` not found.`);\n }\n\n const rootPointer = `/paths/${encodePointer(pathKey)}/${methodKey}`;\n const extraPointers: string[] = [];\n const seeds = new Set<string>(collectRefsInSchema(operation));\n\n // Features on a referenced Path Item live at the *terminal* `$ref` target, not under\n // `/paths/{path}/{method}` and not under an intermediate alias or percent-encoded pointer.\n // Scope only this method (and its common parameters) so sibling operations stay out.\n const targetPointer = resolvePathItemTargetPointer(rawPathItem, definition);\n if (targetPointer) {\n extraPointers.push(`${targetPointer}/${methodKey}`);\n }\n\n if (pathItem.parameters) {\n extraPointers.push(targetPointer ? `${targetPointer}/parameters` : `/paths/${encodePointer(pathKey)}/parameters`);\n collectRefsInSchema(pathItem.parameters).forEach(ref => seeds.add(ref));\n }\n\n const security = 'security' in operation ? operation.security : definition.security;\n collectSecuritySchemeRefs(security).forEach(ref => seeds.add(ref));\n\n const reachableRefs = accumulateReachableRefs(definition, seeds);\n\n return { rootPointer, extraPointers, reachableRefs, ...buildAnchors(rootPointer, extraPointers, reachableRefs) };\n}\n\n/**\n * Compute the `OperationScope` for a single webhook operation within an OpenAPI 3.1 definition.\n *\n */\nexport function computeWebhookScope(definition: OAS31Document, webhookName: string, method: string): OperationScope {\n const webhooks = ('webhooks' in definition ? definition.webhooks : {}) as NonNullable<OAS31Document['webhooks']>;\n const webhookKey = resolveKey(Object.keys(webhooks || {}), webhookName);\n if (!webhookKey) {\n throw new Error(`Webhook \\`${webhookName}\\` not found.`);\n }\n\n const rawWebhook = (webhooks as Record<string, unknown>)[webhookKey];\n const webhook = resolvePathItem(rawWebhook, definition);\n if (!webhook) {\n throw new Error(`Webhook operation \\`${method} ${webhookName}\\` not found.`);\n }\n\n const methodKey = resolveMethodKey(webhook, method);\n if (!methodKey) {\n throw new Error(`Webhook operation \\`${method} ${webhookName}\\` not found.`);\n }\n\n const operation = webhook[methodKey as keyof PathItemObject];\n if (!operation || typeof operation !== 'object') {\n throw new Error(`Webhook operation \\`${method} ${webhookName}\\` not found.`);\n }\n\n const rootPointer = `/webhooks/${encodePointer(webhookKey)}/${methodKey}`;\n const extraPointers: string[] = [];\n const seeds = new Set<string>(collectRefsInSchema(operation));\n\n const targetPointer = resolvePathItemTargetPointer(rawWebhook, definition);\n if (targetPointer) {\n extraPointers.push(`${targetPointer}/${methodKey}`);\n }\n\n if (webhook.parameters) {\n extraPointers.push(\n targetPointer ? `${targetPointer}/parameters` : `/webhooks/${encodePointer(webhookKey)}/parameters`,\n );\n collectRefsInSchema(webhook.parameters).forEach(ref => seeds.add(ref));\n }\n\n const security = 'security' in operation ? operation.security : definition.security;\n collectSecuritySchemeRefs(security).forEach(ref => seeds.add(ref));\n\n const reachableRefs = accumulateReachableRefs(definition, seeds);\n\n return { rootPointer, extraPointers, reachableRefs, ...buildAnchors(rootPointer, extraPointers, reachableRefs) };\n}\n\n/**\n * Determine if a given JSON pointer (as returned by `jsonpath-plus`, without a leading `#`) falls\n * within a given `OperationScope`.\n *\n */\nexport function isPointerInScope(pointer: string, scope: OperationScope): boolean {\n const { anchors, anchorPrefixes } = scope;\n for (let i = 0; i < anchors.length; i += 1) {\n if (pointer === anchors[i] || pointer.startsWith(anchorPrefixes[i])) {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Determine if a given `OperationScope`'s root is nested *within* a given pointer. This is the\n * inverse of `isPointerInScope()` and exists for the handful of queries (like our `webhooks` one)\n * that report on a coarser pointer than the specific operation we're scoped to, e.g. reporting on\n * `/webhooks/newBooking` as a whole when we're scoped to `/webhooks/newBooking/post`.\n *\n */\nexport function isAncestorOfScope(pointer: string, scope: OperationScope): boolean {\n return scope.rootPointer === pointer || scope.rootPointer.startsWith(`${pointer}/`);\n}\n","import type { OASDocument } from '../../types.js';\nimport type { OperationScope } from '../scope.js';\nimport type { JSONPathResult } from '../util.js';\n\nimport { toPointer } from '../../lib/refs.js';\nimport { dereferenceOas } from '../dereference.js';\nimport { queryCached } from '../query-cache.js';\nimport { isAncestorOfScope, isPointerInScope } from '../scope.js';\nimport { refizePointer } from '../util.js';\n\n/**\n * Narrow a set of JSONPath results down to only the ones that fall within a given operation's\n * scope. When no scope is supplied every result is considered in scope, which preserves the\n * whole-document behavior these queries have always had.\n *\n */\nfunction filterByScope(results: JSONPathResult[], scope?: OperationScope): JSONPathResult[] {\n if (!scope) {\n return results;\n }\n\n return results.filter(res => isPointerInScope(res.pointer, scope));\n}\n\n/**\n * Determine if a given API definition uses the `additionalProperties` schema property.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport function additionalProperties(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(queryCached(['$..additionalProperties'], definition), scope).map(res =>\n refizePointer(res.pointer),\n );\n}\n\n/**\n * Determine if a given API definition utilizes `callbacks`.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callback-object}\n */\nexport function callbacks(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(\n queryCached(['$.components.callbacks', '$.paths.*[?(@.callbacks)].callbacks'], definition),\n scope,\n ).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition has circular refs.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport async function circularRefs(definition: OASDocument, scope?: OperationScope): Promise<string[]> {\n // Dereferencing will update the passed in variable, which we don't want to do, so we\n // instantiated `Oas` with a clone.\n const { circularRefs: refs } = await dereferenceOas(structuredClone(definition));\n\n const results = scope ? refs.filter(ref => isPointerInScope(toPointer(ref), scope)) : [...refs];\n results.sort();\n return results;\n}\n\n/**\n * Determine if a given API definition utilizes common parameters.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#path-item-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#path-item-object}\n */\nexport function commonParameters(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(queryCached(['$..paths[*].parameters'], definition), scope).map(res =>\n refizePointer(res.pointer),\n );\n}\n\n/**\n * Determine if a given API definition utilizes discriminators.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminator-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#discriminator-object}\n */\nexport function discriminators(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(queryCached(['$..discriminator'], definition), scope).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilizes `links`.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#link-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#link-object}\n */\nexport function links(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(queryCached(['$.components.links', '$.paths..responses.*.links'], definition), scope).map(res =>\n refizePointer(res.pointer),\n );\n}\n\n/**\n * Determine all of the available media types used within an API definition.\n *\n * @todo This query currently picks up false positives if there is an object named `content`.\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#request-body-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#request-body-object}\n */\nexport function mediaTypes(definition: OASDocument, scope?: OperationScope): string[] {\n const results = Array.from(\n new Set(\n filterByScope(\n queryCached(\n [\n '$..paths..content',\n '$.components.requestBodies..content',\n '$.components.responses..content',\n '$.webhooks..content',\n ],\n definition,\n ),\n scope,\n ).flatMap(res => {\n // This'll transform `results`, which looks like `[['application/json'], ['text/xml']]`\n // into `['application/json', 'text/xml']`.\n return Object.keys(res.value);\n }),\n ),\n );\n\n results.sort();\n return results;\n}\n\n/**\n * Determine if a given API definition uses parameter serialization.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameter-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object}\n */\nexport function parameterSerialization(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(queryCached(['$..parameters[*].style^'], definition), scope).map(res =>\n refizePointer(res.pointer),\n );\n}\n\n/**\n * Determine if a given API definition utilizes schema polymorphism and/of interitance.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport function polymorphism(definition: OASDocument, scope?: OperationScope): string[] {\n const results = Array.from(\n new Set(\n filterByScope(queryCached(['$..allOf^', '$..anyOf^', '$..oneOf^'], definition), scope).map(res =>\n refizePointer(res.pointer),\n ),\n ),\n );\n\n results.sort();\n return results;\n}\n\n/**\n * Determine if a given API definition utilizes `$ref` pointers.\n *\n */\nexport function references(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(queryCached(['$..$ref^'], definition), scope).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine every kind of security type that a given API definition has documented.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#security-scheme-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#security-scheme-object}\n */\nexport function securityTypes(definition: OASDocument, scope?: OperationScope): string[] {\n return Array.from(\n new Set(\n filterByScope(queryCached(['$.components.securitySchemes..type'], definition), scope).map(\n res => res.value as string,\n ),\n ),\n );\n}\n\n/**\n * Determine if a given API definition utilizes server variables.\n *\n * Root-level `servers` apply to every operation unless a path or operation overrides them, so\n * these are always considered in scope regardless of which operation is being analyzed.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#server-variable-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#server-variable-object}\n */\nexport function serverVariables(definition: OASDocument): string[] {\n return queryCached(['$.servers..variables^'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine how many operations are defined in a given API definition.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operation-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operation-object}\n */\nexport function totalOperations(definition: OASDocument): number {\n return queryCached(['$..paths[*]'], definition).flatMap(res => Object.keys(res.value)).length;\n}\n\n/**\n * Determine if a given API definition utilizes `webhooks` support in OpenAPI 3.1.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#oasWebhooks}\n */\nexport function webhooks(definition: OASDocument, scope?: OperationScope): string[] {\n const results = queryCached(['$.webhooks[*]'], definition);\n if (!scope) {\n return results.map(res => refizePointer(res.pointer));\n }\n\n // This query reports on an entire webhook (`/webhooks/newBooking`) rather than a specific\n // method on it, so a scope's root pointer (`/webhooks/newBooking/post`) is a *descendant* of a\n // matching result rather than the other way around. We still want to catch the normal case too,\n // where an operation reaches into a webhook by way of a `$ref`.\n return results\n .filter(res => isPointerInScope(res.pointer, scope) || isAncestorOfScope(res.pointer, scope))\n .map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition uses XML in a request body payload.\n *\n * @todo detect `+xml` media types\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n */\nexport function xmlRequests(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(\n queryCached(\n [\n \"$..requestBody..['application/xml']\",\n \"$..requestBody..['application/xml-external-parsed-entity']\",\n \"$..requestBody..['application/xml-dtd']\",\n \"$..requestBody..['text/xml']\",\n \"$..requestBody..['text/xml-external-parsed-entity']\",\n '$..requestBody.content[?(@property.match(/\\\\+xml$/i))]',\n ],\n definition,\n ),\n scope,\n ).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition uses XML in a response body.\n *\n * @todo detect `+xml` media types\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n */\nexport function xmlResponses(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(\n queryCached(\n [\n \"$..responses..['application/xml']\",\n \"$..responses..['application/xml-external-parsed-entity']\",\n \"$..responses..['application/xml-dtd']\",\n \"$..responses..['text/xml']\",\n \"$..responses..['text/xml-external-parsed-entity']\",\n '$..responses[*].content[?(@property.match(/\\\\+xml$/i))]',\n ],\n definition,\n ),\n scope,\n ).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilises the XML object for defining XML schemas.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#xml-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#xml-object}\n */\nexport function xmlSchemas(definition: OASDocument, scope?: OperationScope): string[] {\n return filterByScope(\n queryCached(['$.components.schemas..xml^', '$..parameters..xml^', '$..requestBody..xml^'], definition),\n scope,\n ).map(res => refizePointer(res.pointer));\n}\n","import type { OAS31Document, OASDocument } from '../types.js';\nimport type { OperationScope } from './scope.js';\nimport type { AnalyzerQuery, OASAnalysis } from './types.js';\n\nimport { toPointer } from '../lib/refs.js';\nimport { isOpenAPI31 } from '../types.js';\n\nimport { dereferenceOasShared } from './dereference.js';\nimport {\n additionalProperties as analyzeAdditionalProperties,\n callbacks as analyzeCallbacks,\n commonParameters as analyzeCommonParameters,\n discriminators as analyzeDiscriminators,\n links as analyzeLinks,\n mediaTypes as analyzeMediaTypes,\n parameterSerialization as analyzeParameterSerialization,\n polymorphism as analyzePolymorphism,\n references as analyzeReferences,\n securityTypes as analyzeSecurityTypes,\n serverVariables as analyzeServerVariables,\n totalOperations as analyzeTotalOperations,\n webhooks as analyzeWebhooks,\n xmlRequests as analyzeXMLRequests,\n xmlResponses as analyzeXMLResponses,\n xmlSchemas as analyzeXMLSchemas,\n} from './queries/openapi.js';\nimport { computeOperationScope, computeWebhookScope, isPointerInScope } from './scope.js';\n\n/**\n * Run every analyzer query against a definition, optionally narrowed down to a single operation or\n * webhook's `OperationScope`.\n *\n * This is the shared implementation behind `analyzer()`, `analyzeOperation()`, and\n * `analyzeWebhookOperation()`. Dereferencing (the most expensive step here) is cached against the\n * original `definition` reference via `dereferenceOasShared()`, and every JSONPath scan that the\n * individual queries run is cached against it as well, so calling this repeatedly for many\n * operations out of the same definition only pays the full-document cost once.\n *\n */\nasync function buildAnalysis(\n definition: OASDocument,\n query?: AnalyzerQuery[],\n scope?: OperationScope,\n): Promise<OASAnalysis> {\n const analysis: OASAnalysis = {};\n\n if (!query || query.includes('mediaTypes')) {\n analysis.mediaTypes = {\n name: 'Media Type',\n found: analyzeMediaTypes(definition, scope),\n };\n }\n\n if (!query || query.includes('operationTotal')) {\n analysis.operationTotal = {\n name: 'Operation',\n // A scoped analysis is, by definition, looking at exactly one operation.\n found: scope ? 1 : analyzeTotalOperations(definition),\n };\n }\n\n if (!query || query.includes('securityTypes')) {\n analysis.securityTypes = {\n name: 'Security Type',\n found: analyzeSecurityTypes(definition, scope),\n };\n }\n\n if (!query || query.includes('additionalProperties')) {\n const additionalProperties = analyzeAdditionalProperties(definition, scope);\n analysis.additionalProperties = {\n present: !!additionalProperties.length,\n locations: additionalProperties,\n };\n }\n\n if (!query || query.includes('callbacks')) {\n const callbacks = analyzeCallbacks(definition, scope);\n analysis.callbacks = {\n present: !!callbacks.length,\n locations: callbacks,\n };\n }\n\n if (!query || query.includes('circularRefs')) {\n const { circularRefs: dereferencedCircularRefs } = await dereferenceOasShared(definition);\n const circularRefs = (\n scope\n ? dereferencedCircularRefs.filter(ref => isPointerInScope(toPointer(ref), scope))\n : [...dereferencedCircularRefs]\n ).toSorted();\n\n analysis.circularRefs = {\n present: !!circularRefs.length,\n locations: circularRefs,\n };\n }\n\n if (!query || query.includes('commonParameters')) {\n const commonParameters = analyzeCommonParameters(definition, scope);\n analysis.commonParameters = {\n present: !!commonParameters.length,\n locations: commonParameters,\n };\n }\n\n if (!query || query.includes('discriminators')) {\n const discriminators = analyzeDiscriminators(definition, scope);\n analysis.discriminators = {\n present: !!discriminators.length,\n locations: discriminators,\n };\n }\n\n if (!query || query.includes('links')) {\n const links = analyzeLinks(definition, scope);\n analysis.links = {\n present: !!links.length,\n locations: links,\n };\n }\n\n if (!query || query.includes('style')) {\n const parameterSerialization = analyzeParameterSerialization(definition, scope);\n analysis.style = {\n present: !!parameterSerialization.length,\n locations: parameterSerialization,\n };\n }\n\n if (!query || query.includes('polymorphism')) {\n const polymorphism = analyzePolymorphism(definition, scope);\n analysis.polymorphism = {\n present: !!polymorphism.length,\n locations: polymorphism,\n };\n }\n\n if (!query || query.includes('references')) {\n const references = analyzeReferences(definition, scope);\n analysis.references = {\n present: !!references.length,\n locations: references,\n };\n }\n\n if (!query || query.includes('serverVariables')) {\n const serverVariables = analyzeServerVariables(definition);\n analysis.serverVariables = {\n present: !!serverVariables.length,\n locations: serverVariables,\n };\n }\n\n if (!query || query.includes('xmlRequests')) {\n const xmlRequests = analyzeXMLRequests(definition, scope);\n analysis.xmlRequests = {\n present: !!xmlRequests.length,\n locations: xmlRequests,\n };\n }\n\n if (!query || query.includes('xmlResponses')) {\n const xmlResponses = analyzeXMLResponses(definition, scope);\n analysis.xmlResponses = {\n present: !!xmlResponses.length,\n locations: xmlResponses,\n };\n }\n\n if (!query || query.includes('xmlSchemas')) {\n const xmlSchemas = analyzeXMLSchemas(definition, scope);\n analysis.xmlSchemas = {\n present: !!xmlSchemas.length,\n locations: xmlSchemas,\n };\n }\n\n if (!query || query.includes('webhooks')) {\n const webhooks = analyzeWebhooks(definition, scope);\n analysis.webhooks = {\n present: !!webhooks.length,\n locations: webhooks,\n };\n }\n\n return analysis;\n}\n\n/**\n * Analyze a given OpenAPI or Swagger definition for any, or a specific, OpenAPI or JSON Schema\n * feature uses it may contain or utilize.\n *\n */\nexport async function analyzer(definition: OASDocument, query?: AnalyzerQuery[]): Promise<OASAnalysis> {\n return buildAnalysis(definition, query);\n}\n\n/**\n * Analyze a single operation within a given OpenAPI definition for any, or a specific, OpenAPI or\n * JSON Schema feature uses that it, or anything it references, may contain or utilize.\n *\n * When analyzing many operations out of the same definition, pass the *same* `definition`\n * reference to every call — the expensive dereferencing and document-wide JSONPath scans that this\n * relies on are cached against that reference, so only the first call pays for them.\n *\n */\nexport async function analyzeOperation(\n definition: OASDocument,\n {\n path,\n method,\n query,\n }: {\n path: string;\n method: string;\n query?: AnalyzerQuery[];\n },\n): Promise<OASAnalysis> {\n const scope = computeOperationScope(definition, path, method);\n return buildAnalysis(definition, query, scope);\n}\n\n/**\n * Analyze a single webhook operation within a given OpenAPI 3.1 definition for any, or a specific,\n * OpenAPI or JSON Schema feature uses that it, or anything it references, may contain or utilize.\n *\n * @see {@link analyzeOperation}\n */\nexport async function analyzeWebhookOperation(\n definition: OASDocument,\n {\n webhookName,\n method,\n query,\n }: {\n webhookName: string;\n method: string;\n query?: AnalyzerQuery[];\n },\n): Promise<OASAnalysis> {\n if (!isOpenAPI31(definition)) {\n throw new TypeError('The supplied definition is not a OpenAPI 3.1 definition.');\n }\n\n const scope = computeWebhookScope(definition satisfies OAS31Document, webhookName, method);\n return buildAnalysis(definition, query, scope);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/darrenyong/Desktop/oas-stuff/oas/packages/oas/dist/analyzer/types.cjs","../../src/analyzer/types.ts"],"names":[],"mappings":"AAAA;ACCO,IAAM,gBAAA,EAAkB;AAAA;AAAA,EAE7B,YAAA;AAAA,EACA,gBAAA;AAAA,EACA,eAAA;AAAA;AAAA,EAGA,sBAAA;AAAA,EACA,WAAA;AAAA,EACA,cAAA;AAAA,EACA,kBAAA;AAAA,EACA,gBAAA;AAAA,EACA,OAAA;AAAA,EACA,OAAA;AAAA,EACA,cAAA;AAAA,EACA,YAAA;AAAA,EACA,iBAAA;AAAA,EACA,aAAA;AAAA,EACA,cAAA;AAAA,EACA,YAAA;AAAA,EACA;AACF,CAAA;ADAA;AACE;AACF,0CAAC","file":"/Users/darrenyong/Desktop/oas-stuff/oas/packages/oas/dist/analyzer/types.cjs","sourcesContent":[null,"// oxlint-disable perfectionist/sort-interfaces\nexport const AnalyzerQueries = [\n // General\n 'mediaTypes',\n 'operationTotal',\n 'securityTypes',\n\n // OpenAPI\n 'additionalProperties',\n 'callbacks',\n 'circularRefs',\n 'commonParameters',\n 'discriminators',\n 'links',\n 'style',\n 'polymorphism',\n 'references',\n 'serverVariables',\n 'xmlRequests',\n 'xmlResponses',\n 'xmlSchemas',\n 'webhooks',\n] as const;\n\nexport type AnalyzerQuery = (typeof AnalyzerQueries)[number];\n\nexport interface OASAnalysisFeature {\n locations: string[];\n present: boolean;\n}\n\nexport interface OASAnalysisGeneral {\n found: string[] | number;\n name: string;\n}\n\nexport interface OASAnalysis {\n // General\n mediaTypes?: OASAnalysisGeneral;\n operationTotal?: OASAnalysisGeneral;\n securityTypes?: OASAnalysisGeneral;\n\n // OpenAPI\n additionalProperties?: OASAnalysisFeature;\n callbacks?: OASAnalysisFeature;\n circularRefs?: OASAnalysisFeature;\n commonParameters?: OASAnalysisFeature;\n discriminators?: OASAnalysisFeature;\n links?: OASAnalysisFeature;\n polymorphism?: OASAnalysisFeature;\n references?: OASAnalysisFeature;\n serverVariables?: OASAnalysisFeature;\n style?: OASAnalysisFeature;\n xmlRequests?: OASAnalysisFeature;\n xmlResponses?: OASAnalysisFeature;\n xmlSchemas?: OASAnalysisFeature;\n webhooks?: OASAnalysisFeature;\n}\n"]}
1
+ {"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas/dist/analyzer/types.cjs","../../src/analyzer/types.ts"],"names":[],"mappings":"AAAA;ACCO,IAAM,gBAAA,EAAkB;AAAA;AAAA,EAE7B,YAAA;AAAA,EACA,gBAAA;AAAA,EACA,eAAA;AAAA;AAAA,EAGA,sBAAA;AAAA,EACA,WAAA;AAAA,EACA,cAAA;AAAA,EACA,kBAAA;AAAA,EACA,gBAAA;AAAA,EACA,OAAA;AAAA,EACA,OAAA;AAAA,EACA,cAAA;AAAA,EACA,YAAA;AAAA,EACA,iBAAA;AAAA,EACA,aAAA;AAAA,EACA,cAAA;AAAA,EACA,YAAA;AAAA,EACA;AACF,CAAA;ADAA;AACE;AACF,0CAAC","file":"/Users/erunion/code/readme/oas/packages/oas/dist/analyzer/types.cjs","sourcesContent":[null,"// oxlint-disable perfectionist/sort-interfaces\nexport const AnalyzerQueries = [\n // General\n 'mediaTypes',\n 'operationTotal',\n 'securityTypes',\n\n // OpenAPI\n 'additionalProperties',\n 'callbacks',\n 'circularRefs',\n 'commonParameters',\n 'discriminators',\n 'links',\n 'style',\n 'polymorphism',\n 'references',\n 'serverVariables',\n 'xmlRequests',\n 'xmlResponses',\n 'xmlSchemas',\n 'webhooks',\n] as const;\n\nexport type AnalyzerQuery = (typeof AnalyzerQueries)[number];\n\nexport interface OASAnalysisFeature {\n locations: string[];\n present: boolean;\n}\n\nexport interface OASAnalysisGeneral {\n found: string[] | number;\n name: string;\n}\n\nexport interface OASAnalysis {\n // General\n mediaTypes?: OASAnalysisGeneral;\n operationTotal?: OASAnalysisGeneral;\n securityTypes?: OASAnalysisGeneral;\n\n // OpenAPI\n additionalProperties?: OASAnalysisFeature;\n callbacks?: OASAnalysisFeature;\n circularRefs?: OASAnalysisFeature;\n commonParameters?: OASAnalysisFeature;\n discriminators?: OASAnalysisFeature;\n links?: OASAnalysisFeature;\n polymorphism?: OASAnalysisFeature;\n references?: OASAnalysisFeature;\n serverVariables?: OASAnalysisFeature;\n style?: OASAnalysisFeature;\n xmlRequests?: OASAnalysisFeature;\n xmlResponses?: OASAnalysisFeature;\n xmlSchemas?: OASAnalysisFeature;\n webhooks?: OASAnalysisFeature;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/darrenyong/Desktop/oas-stuff/oas/packages/oas/dist/chunk-47FD2BIN.cjs","../src/extensions.ts"],"names":[],"mappings":"AAAA;AC+BO,IAAM,aAAA,EAAe,cAAA;AAoBrB,IAAM,iBAAA,EAAmB,kBAAA;AAwBzB,IAAM,QAAA,EAAU,SAAA;AAmBhB,IAAM,SAAA,EAAW,UAAA;AAmBjB,IAAM,gBAAA,EAAkB,iBAAA;AAkBxB,IAAM,cAAA,EAAgB,eAAA;AAuBtB,IAAM,mBAAA,EAAqB,oBAAA;AAoB3B,IAAM,cAAA,EAAgB,eAAA;AAiBtB,IAAM,kBAAA,EAAoB,mBAAA;AAc1B,IAAM,YAAA,EAAc,aAAA;AAkBpB,IAAM,qBAAA,EAAuB,sBAAA;AAkB7B,IAAM,kBAAA,EAAoB,mBAAA;AAe1B,IAAM,oBAAA,EAAsB,qBAAA;AAe5B,IAAM,WAAA,EAAa,YAAA;AAqFnB,IAAM,kBAAA,EAAgC;AAAA,EAC3C,CAAC,oBAAoB,CAAA,EAAG,KAAA;AAAA,EACxB,CAAC,iBAAiB,CAAA,EAAG,KAAA;AAAA,EACrB,CAAC,YAAY,CAAA,EAAG,KAAA,CAAA;AAA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EAAA,EAAK,SAAS,CAAA,CAAA;AACJ,MAAA;AACH,IAAA;AACO,MAAA;AACzC,IAAA;AACF,EAAA;AAIgC,EAAA;AACI,IAAA;AACpC,EAAA;AAEuC,EAAA;AACR,IAAA;AACW,IAAA;AACG,MAAA;AAC3C,IAAA;AACF,EAAA;AAE0C,EAAA;AACX,IAAA;AACW,EAAA;AAClB,IAAA;AACxB,EAAA;AAGoC,EAAA;AACoB,IAAA;AACxD,EAAA;AAEO,EAAA;AACT;AAUE;AAEe,EAAA;AACb,IAAA;AACF,EAAA;AAEuC,EAAA;AACH,EAAA;AACQ,EAAA;AAEJ,EAAA;AACL,IAAA;AACnC,EAAA;AAEqC,EAAA;AACO,EAAA;AACT,IAAA;AACnC,EAAA;AACF;ADpX8C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/darrenyong/Desktop/oas-stuff/oas/packages/oas/dist/chunk-47FD2BIN.cjs","sourcesContent":[null,"import type { Operation } from './operation/index.js';\nimport type { OASDocument } from './types.js';\n\n/**\n * Enables custom-written code samples to be set for your operations. Use this if you have specific\n * formatting that may not be followed by the auto-generated code samples. Custom code samples are\n * treated as static content.\n *\n * This extension only be placed at the operation level.\n *\n * @defaultValue []\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#custom-code-samples}\n * @example\n * {\n * \"x-readme\": {\n * \"code-samples\": [\n * {\n * \"language\": \"curl\",\n * \"code\": \"curl -X POST https://api.example.com/v2/alert\",\n * \"name\": \"Custom cURL snippet\",\n * \"install\": \"brew install curl\"\n * },\n * {\n * \"language\": \"php\",\n * \"code\": \"<?php echo \\\"This is our custom PHP code snippet.\\\"; ?>\",\n * \"name\": \"Custom PHP snippet\"\n * }\n * ]\n * }\n * }\n */\nexport const CODE_SAMPLES = 'code-samples';\n\n/**\n * Disables the API Explorer's \"Try It\" button, preventing users from making API requests from\n * within your docs. Users will still be able to fill out any entry fields (path or query\n * parameters, etc.), and code snippets will be auto-generated based on the user's input, however\n * to interact with your API the user will need to copy the code snippet and execute it outside of\n * your docs.\n *\n * This **does not** disable your API Reference documentation.\n *\n * @defaultValue true\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#disable-the-api-explorer}\n * @example\n * {\n * \"x-readme\": {\n * \"explorer-enabled\": true\n * }\n * }\n */\nexport const EXPLORER_ENABLED = 'explorer-enabled';\n\n/**\n * Adds static headers to add to each request. Use this when there are specific headers unique to\n * your API.\n *\n * @defaultValue []\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#static-headers}\n * @example\n * {\n * \"x-readme\": {\n * \"headers\": [\n * {\n * \"key\": \"X-Static-Header-One\",\n * \"value\": \"owlbert\"\n * },\n * {\n * \"key\": \"X-Static-Header-Two\",\n * \"value\": \"owlivia\"\n * }\n * ]\n * }\n * }\n */\nexport const HEADERS = 'headers';\n\n/**\n * Allows you to mark an API endpoint, or _every_ API endpoint if defined in the root, as being\n * internal and hidden from your public API reference.\n *\n * @defaultValue false\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#internal}\n * @example\n * {\n * \"x-internal\": true\n * }\n * @example\n * {\n * \"x-readme\": {\n * \"internal\": true\n * }\n * }\n */\nexport const INTERNAL = 'internal';\n\n/**\n * Disables API requests from the API Explorer's \"Try It\" button from being sent into our [API\n * Metrics](https://readme.com/metrics) for you and your users. Additionally on any API endpoint\n * that this is disabled on your users will not see lists or graphs of previous requests they've\n * made against that API endpoint — either through the API Explorer's interactivity or through one\n * of our [Metrics SDKs](https://docs.readme.com/main/docs/api-metrics-setup) (if you have those\n * installed on your API).\n *\n * @defaultValue true\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#disable-api-metrics}\n * @example\n * {\n * \"x-readme\": {\n * \"metrics-defaults\": false\n * }\n * }\n */\nexport const METRICS_ENABLED = 'metrics-enabled';\n\n/**\n * Configuration options for OAuth flows in the API Explorer.\n *\n * @defaultValue {}\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#oauth-configuration-options}\n * @example\n * {\n * \"x-readme\": {\n * \"oauth-options\": {\n * \"scopeSeparator\": \",\",\n * \"useInsecureClientAuthentication\": true,\n * \"usePkce\": false\n * }\n * }\n * }\n */\nexport const OAUTH_OPTIONS = 'oauth-options';\n\n/**\n * Controls the order of parameters on your API Reference pages.\n *\n * Your custom ordering **must** contain all of our available parameter types:\n *\n * - `path`: Path parameters\n * - `query`: Query parameters\n * - `body`: Non-`application/x-www-form-urlencoded` request body payloads\n * - `cookie`: Cookie parameters\n * - `form`: `application/x-www-form-urlencoded` request body payloads\n * - `header`: Header parameters\n *\n * @defaultValue ['path', 'query', 'body', 'cookie', 'form', 'header']\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#parameter-ordering}\n * @example\n * {\n * \"x-readme\": {\n * \"parameter-ordering\": ['path', 'query', 'header', 'cookie', 'body', 'form']\n * }\n * }\n */\nexport const PARAMETER_ORDERING = 'parameter-ordering';\n\n/**\n * Toggles the CORS proxy used when making API requests from within your docs (via the \"Try It\"\n * button). If your API is already set up to return CORS headers, you can safely disable this\n * feature.\n *\n * Disabling the CORS proxy will make the request directly from the user's browser and will prevent\n * [Metrics](https://docs.readme.com/main/docs/getting-started-with-metrics) data from being logged\n * by us unless [Metrics have already set up on your backend](https://docs.readme.com/main/docs/api-metrics-setup).\n *\n * @defaultValue true\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#cors-proxy-enabled}\n * @example\n * {\n * \"x-readme\": {\n * \"proxy-enabled\": true\n * }\n * }\n */\nexport const PROXY_ENABLED = 'proxy-enabled';\n\n/**\n * Toggles what languages are shown by default for code samples in the API Explorer. This only\n * affects what languages are initially shown to the user; if the user picks another language from\n * the three-dot menu, that language and the respective auto-generated code snippet will also appear\n * as an option in the API Explorer.\n *\n * @defaultValue ['shell', 'node', 'ruby', 'php', 'python', 'java', 'csharp']\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#code-sample-languages}\n * @example\n * {\n * \"x-readme\": {\n * \"samples-languages\": [\"shell\", \"node\", \"ruby\", \"javascript\", \"python\"]\n * }\n * }\n */\nexport const SAMPLES_LANGUAGES = 'samples-languages';\n\n/**\n * Toggles if you will see code snippets for ReadMe's SDK code generator tool `api`.\n *\n * @defaultValue true\n * @see {@link https://api.readme.dev}\n * @example\n * {\n * \"x-readme\": {\n * \"simple-mode\": false\n * }\n * }\n */\nexport const SIMPLE_MODE = 'simple-mode';\n\n/**\n * Reorders API operation pages within their current parent to match the order in the API definition\n * when it is updated. Operation pages retain any manual nesting, and operations that have been\n * moved to another category are not affected.\n *\n * This extension may only be placed at the API definition root level.\n *\n * @defaultValue false\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions}\n * @example\n * {\n * \"x-readme\": {\n * \"apply-endpoint-order\": true\n * }\n * }\n */\nexport const APPLY_ENDPOINT_ORDER = 'apply-endpoint-order';\n\n/**\n * Moves existing API operation pages within their current API category to match their tags when\n * the API definition is updated. Operations that have been moved to another category are not\n * affected.\n *\n * This extension may only be placed at the API definition root level.\n *\n * @defaultValue false\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions}\n * @example\n * {\n * \"x-readme\": {\n * \"apply-tag-changes\": true\n * }\n * }\n */\nexport const APPLY_TAG_CHANGES = 'apply-tag-changes';\n\n/**\n * If `true`, tags are generated from the file top-down. If `false`, we sort the tags\n * based off the `tags` array in the OAS file.\n *\n * @defaultValue false\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#disable-tag-sorting}\n * @example\n * {\n * \"x-readme\": {\n * \"disable-tag-sorting\": true\n * }\n * }\n */\nexport const DISABLE_TAG_SORTING = 'disable-tag-sorting';\n\n/**\n * A customer-declared health/status URL for the API. When present, it's surfaced to AI agents as\n * the RFC 9727 `status` link relation in the project's `/.well-known/api-catalog`.\n *\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions}\n * @see {@link https://www.rfc-editor.org/rfc/rfc9727}\n * @example\n * {\n * \"x-readme\": {\n * \"status-url\": \"https://status.example.com\"\n * }\n * }\n */\nexport const STATUS_URL = 'status-url';\n\nexport interface Extensions {\n [APPLY_ENDPOINT_ORDER]: boolean;\n [APPLY_TAG_CHANGES]: boolean;\n [CODE_SAMPLES]:\n | {\n /**\n * Custom code snippet\n * @example \"curl -X POST https://api.example.com/v2/alert\"\n */\n code: string;\n /**\n * Corresponding response example\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#corresponding-response-examples}\n */\n correspondingExample?: string;\n /**\n * Library installation instructions\n * @example \"brew install httpie\"\n * @example \"npm install node-fetch@2 --save\"\n */\n install?: string;\n /**\n * Language for syntax highlighting\n * @example shell\n */\n language: string;\n /**\n * Optional title for code sample\n * @example \"Custom cURL snippet\"\n */\n name?: string;\n }[]\n | undefined;\n [DISABLE_TAG_SORTING]: boolean;\n [EXPLORER_ENABLED]: boolean;\n [HEADERS]: Record<string, number | string>[] | undefined;\n [INTERNAL]: boolean;\n [METRICS_ENABLED]: boolean;\n [OAUTH_OPTIONS]: {\n /**\n * Scope separator for passing scopes. This value will be URL-encoded.\n *\n * @example \",\"\n * @example \"+\"\n * @default \" \"\n * @see {@link https://datatracker.ietf.org/doc/html/rfc6749#section-3.3} Scope separators information from OAuth 2.0 specification\n */\n scopeSeparator?: string;\n\n /**\n * When enabled, the client credentials (i.e., `client_id` and `client_secret`) are sent in the request body (NOT recommended).\n * When disabled (the default), client credentials are sent using the HTTP Basic Authentication scheme.\n *\n * This is applicable for all requests to the token endpoint.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc6749#section-2.3.1}\n * @see {@link https://datatracker.ietf.org/doc/html/rfc6749#section-3.2}\n *\n * @example true\n * @default false\n */\n useInsecureClientAuthentication?: boolean;\n\n /**\n * When enabled, uses PKCE (Proof Key for Code Exchange) for the authorization code flow.\n * The client secret is replaced with an auto-generated code verifier and code challenge.\n * When disabled, uses the standard OAuth 2.0 authorization code flow with client credentials.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc7636#section-4.1}\n * @see {@link https://datatracker.ietf.org/doc/html/rfc7636#section-4.2}\n *\n * @example true\n * @default false\n */\n usePkce?: boolean;\n };\n [PARAMETER_ORDERING]: ('body' | 'cookie' | 'form' | 'header' | 'path' | 'query')[];\n [PROXY_ENABLED]: boolean;\n [SAMPLES_LANGUAGES]: string[];\n [SIMPLE_MODE]: boolean;\n [STATUS_URL]: string | undefined;\n}\n\nexport const extensionDefaults: Extensions = {\n [APPLY_ENDPOINT_ORDER]: false,\n [APPLY_TAG_CHANGES]: false,\n [CODE_SAMPLES]: undefined,\n [DISABLE_TAG_SORTING]: false,\n [EXPLORER_ENABLED]: true,\n [HEADERS]: undefined,\n [INTERNAL]: false,\n [METRICS_ENABLED]: true,\n [OAUTH_OPTIONS]: {},\n [PARAMETER_ORDERING]: ['path', 'query', 'body', 'cookie', 'form', 'header'],\n [PROXY_ENABLED]: true,\n [SAMPLES_LANGUAGES]: ['shell', 'node', 'ruby', 'php', 'python', 'java', 'csharp'],\n [SIMPLE_MODE]: true,\n [STATUS_URL]: undefined,\n};\n\n/**\n * Determing if an OpenAPI definition has an extension set in its root schema.\n *\n */\nexport function hasRootExtension(extension: string | keyof Extensions, api: OASDocument): boolean {\n return Boolean(api && extension in api);\n}\n\n/**\n * Retrieve a custom specification extension off of the API definition.\n *\n */\nexport function getExtension(extension: string | keyof Extensions, api: OASDocument, operation?: Operation): any {\n if (operation) {\n if (operation.hasExtension('x-readme')) {\n const data = operation.getExtension('x-readme') as Extensions;\n if (data && typeof data === 'object' && extension in data) {\n return data[extension as keyof Extensions];\n }\n }\n\n if (operation.hasExtension(`x-${extension}`)) {\n return operation.getExtension(`x-${extension}`);\n } else if (operation.hasExtension(extension)) {\n return operation.getExtension(extension);\n }\n }\n\n // Because our `code-samples` extension is intended for operation-level use, if it's instead\n // placed at the API definition root level then we should ignore it and return our set defaults.\n if (extension === CODE_SAMPLES) {\n return extensionDefaults[extension];\n }\n\n if (hasRootExtension('x-readme', api)) {\n const data = api?.['x-readme'] as Extensions;\n if (data && typeof data === 'object' && extension in data) {\n return data[extension as keyof Extensions];\n }\n }\n\n if (hasRootExtension(`x-${extension}`, api)) {\n return api?.[`x-${extension}`];\n } else if (hasRootExtension(extension, api)) {\n return api?.[extension];\n }\n\n // If this is otherwise an extension of our own then we should return the default value for it.\n if (extension in extensionDefaults) {\n return extensionDefaults[extension as keyof Extensions];\n }\n\n return undefined;\n}\n\n/**\n * Validate that the data for an instanceof our `PARAMETER_ORDERING` extension is properly\n * configured.\n *\n * @private\n */\nexport function validateParameterOrdering(\n ordering: (typeof extensionDefaults)[typeof PARAMETER_ORDERING] | undefined,\n extension: string,\n): void {\n if (!ordering) {\n return;\n }\n\n const defaultValue = extensionDefaults[PARAMETER_ORDERING];\n const requiredLength = defaultValue.length;\n const defaultsHuman = `${defaultValue.slice(0, -1).join(', ')}, and ${defaultValue.slice(-1)}`;\n\n if (ordering.length !== requiredLength) {\n throw new TypeError(`\"${extension}\" must contain ${requiredLength} items comprised of: ${defaultsHuman}`);\n }\n\n const intersection = ordering.filter(value => defaultValue.includes(value.toLowerCase() as any));\n if (intersection.length !== requiredLength) {\n throw new TypeError(`\"${extension}\" must contain ${requiredLength} items comprised of: ${defaultsHuman}`);\n }\n}\n"]}
1
+ {"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas/dist/chunk-47FD2BIN.cjs","../src/extensions.ts"],"names":[],"mappings":"AAAA;AC+BO,IAAM,aAAA,EAAe,cAAA;AAoBrB,IAAM,iBAAA,EAAmB,kBAAA;AAwBzB,IAAM,QAAA,EAAU,SAAA;AAmBhB,IAAM,SAAA,EAAW,UAAA;AAmBjB,IAAM,gBAAA,EAAkB,iBAAA;AAkBxB,IAAM,cAAA,EAAgB,eAAA;AAuBtB,IAAM,mBAAA,EAAqB,oBAAA;AAoB3B,IAAM,cAAA,EAAgB,eAAA;AAiBtB,IAAM,kBAAA,EAAoB,mBAAA;AAc1B,IAAM,YAAA,EAAc,aAAA;AAkBpB,IAAM,qBAAA,EAAuB,s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ACtC,MAAA,MAAM,KAAA,EAAO,SAAA,CAAU,YAAA,CAAa,UAAU,CAAA;AAC9C,MAAA,GAAA,CAAI,KAAA,GAAQ,OAAO,KAAA,IAAS,SAAA,GAAY,UAAA,GAAa,IAAA,EAAM;AACzD,QAAA,OAAO,IAAA,CAAK,SAA6B,CAAA;AAAA,MAC3C;AAAA,IACF;AAEA,IAAA,GAAA,CAAI,SAAA,CAAU,YAAA,CAAa,CAAA,EAAA,EAAK,SAAS,CAAA,CAAA;AACJ,MAAA;AACH,IAAA;AACO,MAAA;AACzC,IAAA;AACF,EAAA;AAIgC,EAAA;AACI,IAAA;AACpC,EAAA;AAEuC,EAAA;AACR,IAAA;AACW,IAAA;AACG,MAAA;AAC3C,IAAA;AACF,EAAA;AAE0C,EAAA;AACX,IAAA;AACW,EAAA;AAClB,IAAA;AACxB,EAAA;AAGoC,EAAA;AACoB,IAAA;AACxD,EAAA;AAEO,EAAA;AACT;AAUE;AAEe,EAAA;AACb,IAAA;AACF,EAAA;AAEuC,EAAA;AACH,EAAA;AACQ,EAAA;AAEJ,EAAA;AACL,IAAA;AACnC,EAAA;AAEqC,EAAA;AACO,EAAA;AACT,IAAA;AACnC,EAAA;AACF;ADpX8C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/erunion/code/readme/oas/packages/oas/dist/chunk-47FD2BIN.cjs","sourcesContent":[null,"import type { Operation } from './operation/index.js';\nimport type { OASDocument } from './types.js';\n\n/**\n * Enables custom-written code samples to be set for your operations. Use this if you have specific\n * formatting that may not be followed by the auto-generated code samples. Custom code samples are\n * treated as static content.\n *\n * This extension only be placed at the operation level.\n *\n * @defaultValue []\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#custom-code-samples}\n * @example\n * {\n * \"x-readme\": {\n * \"code-samples\": [\n * {\n * \"language\": \"curl\",\n * \"code\": \"curl -X POST https://api.example.com/v2/alert\",\n * \"name\": \"Custom cURL snippet\",\n * \"install\": \"brew install curl\"\n * },\n * {\n * \"language\": \"php\",\n * \"code\": \"<?php echo \\\"This is our custom PHP code snippet.\\\"; ?>\",\n * \"name\": \"Custom PHP snippet\"\n * }\n * ]\n * }\n * }\n */\nexport const CODE_SAMPLES = 'code-samples';\n\n/**\n * Disables the API Explorer's \"Try It\" button, preventing users from making API requests from\n * within your docs. Users will still be able to fill out any entry fields (path or query\n * parameters, etc.), and code snippets will be auto-generated based on the user's input, however\n * to interact with your API the user will need to copy the code snippet and execute it outside of\n * your docs.\n *\n * This **does not** disable your API Reference documentation.\n *\n * @defaultValue true\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#disable-the-api-explorer}\n * @example\n * {\n * \"x-readme\": {\n * \"explorer-enabled\": true\n * }\n * }\n */\nexport const EXPLORER_ENABLED = 'explorer-enabled';\n\n/**\n * Adds static headers to add to each request. Use this when there are specific headers unique to\n * your API.\n *\n * @defaultValue []\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#static-headers}\n * @example\n * {\n * \"x-readme\": {\n * \"headers\": [\n * {\n * \"key\": \"X-Static-Header-One\",\n * \"value\": \"owlbert\"\n * },\n * {\n * \"key\": \"X-Static-Header-Two\",\n * \"value\": \"owlivia\"\n * }\n * ]\n * }\n * }\n */\nexport const HEADERS = 'headers';\n\n/**\n * Allows you to mark an API endpoint, or _every_ API endpoint if defined in the root, as being\n * internal and hidden from your public API reference.\n *\n * @defaultValue false\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#internal}\n * @example\n * {\n * \"x-internal\": true\n * }\n * @example\n * {\n * \"x-readme\": {\n * \"internal\": true\n * }\n * }\n */\nexport const INTERNAL = 'internal';\n\n/**\n * Disables API requests from the API Explorer's \"Try It\" button from being sent into our [API\n * Metrics](https://readme.com/metrics) for you and your users. Additionally on any API endpoint\n * that this is disabled on your users will not see lists or graphs of previous requests they've\n * made against that API endpoint — either through the API Explorer's interactivity or through one\n * of our [Metrics SDKs](https://docs.readme.com/main/docs/api-metrics-setup) (if you have those\n * installed on your API).\n *\n * @defaultValue true\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#disable-api-metrics}\n * @example\n * {\n * \"x-readme\": {\n * \"metrics-defaults\": false\n * }\n * }\n */\nexport const METRICS_ENABLED = 'metrics-enabled';\n\n/**\n * Configuration options for OAuth flows in the API Explorer.\n *\n * @defaultValue {}\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#oauth-configuration-options}\n * @example\n * {\n * \"x-readme\": {\n * \"oauth-options\": {\n * \"scopeSeparator\": \",\",\n * \"useInsecureClientAuthentication\": true,\n * \"usePkce\": false\n * }\n * }\n * }\n */\nexport const OAUTH_OPTIONS = 'oauth-options';\n\n/**\n * Controls the order of parameters on your API Reference pages.\n *\n * Your custom ordering **must** contain all of our available parameter types:\n *\n * - `path`: Path parameters\n * - `query`: Query parameters\n * - `body`: Non-`application/x-www-form-urlencoded` request body payloads\n * - `cookie`: Cookie parameters\n * - `form`: `application/x-www-form-urlencoded` request body payloads\n * - `header`: Header parameters\n *\n * @defaultValue ['path', 'query', 'body', 'cookie', 'form', 'header']\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#parameter-ordering}\n * @example\n * {\n * \"x-readme\": {\n * \"parameter-ordering\": ['path', 'query', 'header', 'cookie', 'body', 'form']\n * }\n * }\n */\nexport const PARAMETER_ORDERING = 'parameter-ordering';\n\n/**\n * Toggles the CORS proxy used when making API requests from within your docs (via the \"Try It\"\n * button). If your API is already set up to return CORS headers, you can safely disable this\n * feature.\n *\n * Disabling the CORS proxy will make the request directly from the user's browser and will prevent\n * [Metrics](https://docs.readme.com/main/docs/getting-started-with-metrics) data from being logged\n * by us unless [Metrics have already set up on your backend](https://docs.readme.com/main/docs/api-metrics-setup).\n *\n * @defaultValue true\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#cors-proxy-enabled}\n * @example\n * {\n * \"x-readme\": {\n * \"proxy-enabled\": true\n * }\n * }\n */\nexport const PROXY_ENABLED = 'proxy-enabled';\n\n/**\n * Toggles what languages are shown by default for code samples in the API Explorer. This only\n * affects what languages are initially shown to the user; if the user picks another language from\n * the three-dot menu, that language and the respective auto-generated code snippet will also appear\n * as an option in the API Explorer.\n *\n * @defaultValue ['shell', 'node', 'ruby', 'php', 'python', 'java', 'csharp']\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#code-sample-languages}\n * @example\n * {\n * \"x-readme\": {\n * \"samples-languages\": [\"shell\", \"node\", \"ruby\", \"javascript\", \"python\"]\n * }\n * }\n */\nexport const SAMPLES_LANGUAGES = 'samples-languages';\n\n/**\n * Toggles if you will see code snippets for ReadMe's SDK code generator tool `api`.\n *\n * @defaultValue true\n * @see {@link https://api.readme.dev}\n * @example\n * {\n * \"x-readme\": {\n * \"simple-mode\": false\n * }\n * }\n */\nexport const SIMPLE_MODE = 'simple-mode';\n\n/**\n * Reorders API operation pages within their current parent to match the order in the API definition\n * when it is updated. Operation pages retain any manual nesting, and operations that have been\n * moved to another category are not affected.\n *\n * This extension may only be placed at the API definition root level.\n *\n * @defaultValue false\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions}\n * @example\n * {\n * \"x-readme\": {\n * \"apply-endpoint-order\": true\n * }\n * }\n */\nexport const APPLY_ENDPOINT_ORDER = 'apply-endpoint-order';\n\n/**\n * Moves existing API operation pages within their current API category to match their tags when\n * the API definition is updated. Operations that have been moved to another category are not\n * affected.\n *\n * This extension may only be placed at the API definition root level.\n *\n * @defaultValue false\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions}\n * @example\n * {\n * \"x-readme\": {\n * \"apply-tag-changes\": true\n * }\n * }\n */\nexport const APPLY_TAG_CHANGES = 'apply-tag-changes';\n\n/**\n * If `true`, tags are generated from the file top-down. If `false`, we sort the tags\n * based off the `tags` array in the OAS file.\n *\n * @defaultValue false\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#disable-tag-sorting}\n * @example\n * {\n * \"x-readme\": {\n * \"disable-tag-sorting\": true\n * }\n * }\n */\nexport const DISABLE_TAG_SORTING = 'disable-tag-sorting';\n\n/**\n * A customer-declared health/status URL for the API. When present, it's surfaced to AI agents as\n * the RFC 9727 `status` link relation in the project's `/.well-known/api-catalog`.\n *\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions}\n * @see {@link https://www.rfc-editor.org/rfc/rfc9727}\n * @example\n * {\n * \"x-readme\": {\n * \"status-url\": \"https://status.example.com\"\n * }\n * }\n */\nexport const STATUS_URL = 'status-url';\n\nexport interface Extensions {\n [APPLY_ENDPOINT_ORDER]: boolean;\n [APPLY_TAG_CHANGES]: boolean;\n [CODE_SAMPLES]:\n | {\n /**\n * Custom code snippet\n * @example \"curl -X POST https://api.example.com/v2/alert\"\n */\n code: string;\n /**\n * Corresponding response example\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#corresponding-response-examples}\n */\n correspondingExample?: string;\n /**\n * Library installation instructions\n * @example \"brew install httpie\"\n * @example \"npm install node-fetch@2 --save\"\n */\n install?: string;\n /**\n * Language for syntax highlighting\n * @example shell\n */\n language: string;\n /**\n * Optional title for code sample\n * @example \"Custom cURL snippet\"\n */\n name?: string;\n }[]\n | undefined;\n [DISABLE_TAG_SORTING]: boolean;\n [EXPLORER_ENABLED]: boolean;\n [HEADERS]: Record<string, number | string>[] | undefined;\n [INTERNAL]: boolean;\n [METRICS_ENABLED]: boolean;\n [OAUTH_OPTIONS]: {\n /**\n * Scope separator for passing scopes. This value will be URL-encoded.\n *\n * @example \",\"\n * @example \"+\"\n * @default \" \"\n * @see {@link https://datatracker.ietf.org/doc/html/rfc6749#section-3.3} Scope separators information from OAuth 2.0 specification\n */\n scopeSeparator?: string;\n\n /**\n * When enabled, the client credentials (i.e., `client_id` and `client_secret`) are sent in the request body (NOT recommended).\n * When disabled (the default), client credentials are sent using the HTTP Basic Authentication scheme.\n *\n * This is applicable for all requests to the token endpoint.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc6749#section-2.3.1}\n * @see {@link https://datatracker.ietf.org/doc/html/rfc6749#section-3.2}\n *\n * @example true\n * @default false\n */\n useInsecureClientAuthentication?: boolean;\n\n /**\n * When enabled, uses PKCE (Proof Key for Code Exchange) for the authorization code flow.\n * The client secret is replaced with an auto-generated code verifier and code challenge.\n * When disabled, uses the standard OAuth 2.0 authorization code flow with client credentials.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc7636#section-4.1}\n * @see {@link https://datatracker.ietf.org/doc/html/rfc7636#section-4.2}\n *\n * @example true\n * @default false\n */\n usePkce?: boolean;\n };\n [PARAMETER_ORDERING]: ('body' | 'cookie' | 'form' | 'header' | 'path' | 'query')[];\n [PROXY_ENABLED]: boolean;\n [SAMPLES_LANGUAGES]: string[];\n [SIMPLE_MODE]: boolean;\n [STATUS_URL]: string | undefined;\n}\n\nexport const extensionDefaults: Extensions = {\n [APPLY_ENDPOINT_ORDER]: false,\n [APPLY_TAG_CHANGES]: false,\n [CODE_SAMPLES]: undefined,\n [DISABLE_TAG_SORTING]: false,\n [EXPLORER_ENABLED]: true,\n [HEADERS]: undefined,\n [INTERNAL]: false,\n [METRICS_ENABLED]: true,\n [OAUTH_OPTIONS]: {},\n [PARAMETER_ORDERING]: ['path', 'query', 'body', 'cookie', 'form', 'header'],\n [PROXY_ENABLED]: true,\n [SAMPLES_LANGUAGES]: ['shell', 'node', 'ruby', 'php', 'python', 'java', 'csharp'],\n [SIMPLE_MODE]: true,\n [STATUS_URL]: undefined,\n};\n\n/**\n * Determing if an OpenAPI definition has an extension set in its root schema.\n *\n */\nexport function hasRootExtension(extension: string | keyof Extensions, api: OASDocument): boolean {\n return Boolean(api && extension in api);\n}\n\n/**\n * Retrieve a custom specification extension off of the API definition.\n *\n */\nexport function getExtension(extension: string | keyof Extensions, api: OASDocument, operation?: Operation): any {\n if (operation) {\n if (operation.hasExtension('x-readme')) {\n const data = operation.getExtension('x-readme') as Extensions;\n if (data && typeof data === 'object' && extension in data) {\n return data[extension as keyof Extensions];\n }\n }\n\n if (operation.hasExtension(`x-${extension}`)) {\n return operation.getExtension(`x-${extension}`);\n } else if (operation.hasExtension(extension)) {\n return operation.getExtension(extension);\n }\n }\n\n // Because our `code-samples` extension is intended for operation-level use, if it's instead\n // placed at the API definition root level then we should ignore it and return our set defaults.\n if (extension === CODE_SAMPLES) {\n return extensionDefaults[extension];\n }\n\n if (hasRootExtension('x-readme', api)) {\n const data = api?.['x-readme'] as Extensions;\n if (data && typeof data === 'object' && extension in data) {\n return data[extension as keyof Extensions];\n }\n }\n\n if (hasRootExtension(`x-${extension}`, api)) {\n return api?.[`x-${extension}`];\n } else if (hasRootExtension(extension, api)) {\n return api?.[extension];\n }\n\n // If this is otherwise an extension of our own then we should return the default value for it.\n if (extension in extensionDefaults) {\n return extensionDefaults[extension as keyof Extensions];\n }\n\n return undefined;\n}\n\n/**\n * Validate that the data for an instanceof our `PARAMETER_ORDERING` extension is properly\n * configured.\n *\n * @private\n */\nexport function validateParameterOrdering(\n ordering: (typeof extensionDefaults)[typeof PARAMETER_ORDERING] | undefined,\n extension: string,\n): void {\n if (!ordering) {\n return;\n }\n\n const defaultValue = extensionDefaults[PARAMETER_ORDERING];\n const requiredLength = defaultValue.length;\n const defaultsHuman = `${defaultValue.slice(0, -1).join(', ')}, and ${defaultValue.slice(-1)}`;\n\n if (ordering.length !== requiredLength) {\n throw new TypeError(`\"${extension}\" must contain ${requiredLength} items comprised of: ${defaultsHuman}`);\n }\n\n const intersection = ordering.filter(value => defaultValue.includes(value.toLowerCase() as any));\n if (intersection.length !== requiredLength) {\n throw new TypeError(`\"${extension}\" must contain ${requiredLength} items comprised of: ${defaultsHuman}`);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/darrenyong/Desktop/oas-stuff/oas/packages/oas/dist/chunk-7PWF3F2W.cjs","../src/types.ts"],"names":[],"mappings":"AAAA;ACGA;AACE;AACA;AACA;AAAa,mEACR;AAQA,SAAS,KAAA,CAAM,KAAA,EAAkF;AACtG,EAAA,OAAO,uBAAQ,KAAA,2BAAmE,OAAA,IAAS,QAAA;AAC7F;AAMO,IAAM,UAAA,EAA2D,qBAAA;AAMjE,IAAM,YAAA,EAA6D,uBAAA;AAMnE,IAAM,YAAA,EAA+D,uBAAA;AAkPrE,SAAS,QAAA,CAAS,KAAA,EAAgB,wBAAA,EAA0B,KAAA,EAA8B;AAC/F,EAAA,OACG,KAAA,CAAuB,KAAA,IAAS,KAAA,EAAA,GAChC,KAAA,CAAuB,MAAA,IAAU,KAAA,EAAA,GACjC,KAAA,CAAuB,MAAA,IAAU,KAAA,EAAA,GACjC,KAAA,CAAuB,MAAA,IAAU,KAAA,EAAA,GAClC,uBAAA;AAEJ;AD9QA;AACA;AACE;AACA;AACA;AACA;AACA;AACF,wJAAC","file":"/Users/darrenyong/Desktop/oas-stuff/oas/packages/oas/dist/chunk-7PWF3F2W.cjs","sourcesContent":[null,"import type { JSONSchema4, JSONSchema6, JSONSchema7 } from 'json-schema';\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';\n\nimport {\n isOpenAPI30 as assertOpenAPI30,\n isOpenAPI31 as assertOpenAPI31,\n isSwagger as assertSwagger,\n} from '@readme/openapi-parser/lib/assertions';\n\nexport type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;\n\n/**\n * @param check Data to determine if it contains a ReferenceObject (`$ref` pointer`).\n * @returns If the supplied data has a `$ref` pointer.\n */\nexport function isRef(check: unknown): check is OpenAPIV3_1.ReferenceObject | OpenAPIV3.ReferenceObject {\n return typeof (check as OpenAPIV3_1.ReferenceObject | OpenAPIV3.ReferenceObject)?.$ref === 'string';\n}\n\n/**\n * Is a given object a Swagger API definition?\n *\n */\nexport const isSwagger: (schema: any) => schema is OpenAPIV2.Document = assertSwagger;\n\n/**\n * Is a given object an OpenAPI 3.0 API definition?\n *\n */\nexport const isOpenAPI30: (schema: any) => schema is OpenAPIV3.Document = assertOpenAPI30;\n\n/**\n * Is a given object an OpenAPI 3.1 API definition?\n *\n */\nexport const isOpenAPI31: (schema: any) => schema is OpenAPIV3_1.Document = assertOpenAPI31;\n\n/**\n * Data shape for taking OpenAPI operation data and converting it into HAR.\n *\n * @see {@link https://github.com/readmeio/oas/tree/main/packages/oas-to-har}\n */\nexport interface DataForHAR {\n body?: any;\n cookie?: Record<string, any>;\n formData?: Record<string, any>; // `application/x-www-form-urlencoded` requests payloads.\n header?: Record<string, any>;\n path?: Record<string, any>;\n query?: Record<string, any>;\n server?: {\n selected: number;\n variables?: ServerVariable;\n };\n}\n\nexport type AuthForHAR = Record<string, number | string | { pass?: string; user?: string }>;\n\nexport type SecuritySchemeDefaultAuthPrimitive = number | string;\n\nexport interface BasicAuthDefault {\n pass?: SecuritySchemeDefaultAuthPrimitive;\n user?: SecuritySchemeDefaultAuthPrimitive;\n}\n\nexport interface OAuthClientCredentialsDefault {\n client_id?: SecuritySchemeDefaultAuthPrimitive;\n client_secret?: SecuritySchemeDefaultAuthPrimitive;\n clientId?: SecuritySchemeDefaultAuthPrimitive;\n clientSecret?: SecuritySchemeDefaultAuthPrimitive;\n}\n\nexport type SecuritySchemeDefaultAuth =\n | SecuritySchemeDefaultAuthPrimitive\n | BasicAuthDefault\n | OAuthClientCredentialsDefault;\n\nexport interface User {\n [key: string]: unknown;\n keys?: {\n [key: string]: unknown;\n name: number | string;\n pass?: number | string;\n user?: number | string;\n }[];\n}\n\n/**\n * The type of security scheme. Used by `operation.getSecurityWithTypes()` and `operation.prepareSecurity()`.\n */\nexport type SecurityType = 'apiKey' | 'Basic' | 'Bearer' | 'Cookie' | 'Header' | 'http' | 'OAuth2' | 'Query';\n\nexport type HttpMethods =\n | OpenAPIV3_1.HttpMethods\n | OpenAPIV3.HttpMethods\n | 'delete'\n | 'get'\n | 'head'\n | 'options'\n | 'patch'\n | 'post'\n | 'put'\n | 'trace';\n\n// The following are custom OpenAPI types that we use throughout this library, sans\n// `ReferenceObject` because we assume that the API definition has been dereferenced.\n//\n// These are organized by how they're defined in the OpenAPI Specification.\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#openapi-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-object}\n */\nexport type OASDocument = (OpenAPIV3_1.Document | OpenAPIV3.Document) &\n // `x-*` extensions\n Record<string, unknown>;\n\nexport type OAS31Document = OpenAPIV3_1.Document &\n // `x-*` extensions\n Record<string, unknown>;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#server-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#server-object}\n */\nexport type ServerObject = OpenAPIV3_1.ServerObject | OpenAPIV3.ServerObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#server-variable-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#server-variable-object}\n */\nexport type ServerVariableObject = OpenAPIV3_1.ServerVariableObject | OpenAPIV3.ServerVariableObject;\nexport type ServerVariablesObject = Record<string, ServerVariableObject>;\nexport type ServerVariable = Record<\n string,\n { default?: number | string }[] | Record<string, never> | number | string | { default?: number | string }\n>;\n\nexport interface Servers {\n selected: number;\n variables: ServerVariable;\n}\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#components-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#components-object}\n */\nexport type ComponentsObject = OpenAPIV3_1.ComponentsObject | OpenAPIV3.ComponentsObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#reference-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#reference-object}\n */\nexport type ReferenceObject = OpenAPIV3_1.ReferenceObject | OpenAPIV3.ReferenceObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#paths-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#paths-object}\n */\nexport type PathsObject = OpenAPIV3_1.PathsObject | OpenAPIV3.PathsObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#path-item-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#path-item-object}\n */\nexport type PathItemObject = OpenAPIV3_1.PathItemObject | OpenAPIV3.PathItemObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operation-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operation-object}\n */\nexport type OperationObject = (OpenAPIV3_1.OperationObject | OpenAPIV3.OperationObject) &\n // `x-*` extensions\n Record<string, unknown>;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameter-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object}\n */\nexport type ParameterObject = {\n in: 'cookie' | 'header' | 'path' | 'query';\n} & (OpenAPIV3_1.ParameterObject | OpenAPIV3.ParameterObject);\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#request-body-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#request-body-object}\n */\nexport type RequestBodyObject = OpenAPIV3_1.RequestBodyObject | OpenAPIV3.RequestBodyObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#media-type-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n */\nexport type MediaTypeObject = OpenAPIV3_1.MediaTypeObject | OpenAPIV3.MediaTypeObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#response-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#response-object}\n */\nexport type ResponseObject = OpenAPIV3_1.ResponseObject | OpenAPIV3.ResponseObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callback-object}\n */\nexport type CallbackObject = OpenAPIV3_1.CallbackObject | OpenAPIV3.CallbackObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#example-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.3.md#example-object}\n */\nexport type ExampleObject = OpenAPIV3_1.ExampleObject | OpenAPIV3.ExampleObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#tag-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#tag-object}\n */\nexport type TagObject = OpenAPIV3_1.TagObject | OpenAPIV3.TagObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#header-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#header-object}\n */\nexport type HeaderObject = OpenAPIV3_1.HeaderObject | OpenAPIV3.HeaderObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport type SchemaObject = {\n // OpenAPI-specific properties\n externalDocs?: unknown;\n xml?: unknown;\n} & {\n // TODO: We should split this into one type for v3 and one type for v3.1 to ensure type accuracy.\n $schema?: string;\n\n // We add this to the schema to help out with circular refs\n components?: OpenAPIV3_1.ComponentsObject;\n\n deprecated?: boolean;\n example?: unknown;\n examples?: unknown[];\n nullable?: boolean;\n readOnly?: boolean;\n writeOnly?: boolean;\n\n // `discriminator` comes through in `OpenAPIV3.SchemaObject` but because we also union this type\n // to `JSONSchema` TS gets confused when we narrow types everywhere and doens't pick up valid\n // `discriminator` types when we need them.\n discriminator?: DiscriminatorObject;\n\n // We add this extension within our dereferencing work to preserve the origin dereferenced\n // schemas.\n 'x-readme-ref-name'?: string;\n} & (\n | OpenAPIV3.SchemaObject\n | OpenAPIV3_1.SchemaObject\n // Adding `JSONSchema` to this because `json-schema-merge-allof` expects those.\n | JSONSchema\n );\n\nexport interface SchemaWrapper {\n $schema?: string;\n description?: string;\n label?: string;\n schema: SchemaObject;\n type: string;\n}\n\n/**\n * Determine if a given JSON Schema object is a valid JSON Schema object and either has a declared\n * `type` or is polymorphic in one form or another.\n *\n * @param check JSON Schema object to determine if it's a non-polymorphic schema.\n * @param isPolymorphicAllOfChild If this JSON Schema object is the child of a polymorphic `allOf`.\n * @returns If the JSON Schema object is a JSON Schema object.\n */\nexport function isSchema(check: unknown, isPolymorphicAllOfChild = false): check is SchemaObject {\n return (\n (check as SchemaObject).type !== undefined ||\n (check as SchemaObject).allOf !== undefined ||\n (check as SchemaObject).anyOf !== undefined ||\n (check as SchemaObject).oneOf !== undefined ||\n isPolymorphicAllOfChild\n );\n}\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#security-scheme-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#security-scheme-object}\n */\nexport type SecuritySchemeObject = OpenAPIV3_1.SecuritySchemeObject | OpenAPIV3.SecuritySchemeObject;\n\nexport type SecuritySchemesObject = Record<string, SecuritySchemeObject>;\n\nexport type KeyedSecuritySchemeObject = SecuritySchemeObject & {\n /**\n * The key for the given security scheme object\n */\n _key: string;\n\n /**\n * An array of required scopes for the given security scheme object.\n * Used for `oauth2` security scheme types.\n */\n _requirements?: string[];\n\n // `x-default` is our custom extension for specifying auth defaults.\n // https://docs.readme.com/docs/openapi-extensions#authentication-defaults\n 'x-default'?: SecuritySchemeDefaultAuth;\n};\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#security-requirement-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#security-requirement-object}\n */\nexport type SecurityRequirementObject = OpenAPIV3_1.SecurityRequirementObject | OpenAPIV3.SecurityRequirementObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminator-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#discriminator-object}\n */\nexport type DiscriminatorObject = OpenAPIV3.DiscriminatorObject | OpenAPIV3_1.DiscriminatorObject;\n\n/**\n * Mapping of discriminator schema names to their child schema names.\n * Used to pass information between the pre-dereference and post-dereference phases.\n */\nexport type DiscriminatorChildrenMap = Map<string, string[]>;\n"]}
1
+ {"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas/dist/chunk-7PWF3F2W.cjs","../src/types.ts"],"names":[],"mappings":"AAAA;ACGA;AACE;AACA;AACA;AAAa,mEACR;AAQA,SAAS,KAAA,CAAM,KAAA,EAAkF;AACtG,EAAA,OAAO,uBAAQ,KAAA,2BAAmE,OAAA,IAAS,QAAA;AAC7F;AAMO,IAAM,UAAA,EAA2D,qBAAA;AAMjE,IAAM,YAAA,EAA6D,uBAAA;AAMnE,IAAM,YAAA,EAA+D,uBAAA;AAkPrE,SAAS,QAAA,CAAS,KAAA,EAAgB,wBAAA,EAA0B,KAAA,EAA8B;AAC/F,EAAA,OACG,KAAA,CAAuB,KAAA,IAAS,KAAA,EAAA,GAChC,KAAA,CAAuB,MAAA,IAAU,KAAA,EAAA,GACjC,KAAA,CAAuB,MAAA,IAAU,KAAA,EAAA,GACjC,KAAA,CAAuB,MAAA,IAAU,KAAA,EAAA,GAClC,uBAAA;AAEJ;AD9QA;AACA;AACE;AACA;AACA;AACA;AACA;AACF,wJAAC","file":"/Users/erunion/code/readme/oas/packages/oas/dist/chunk-7PWF3F2W.cjs","sourcesContent":[null,"import type { JSONSchema4, JSONSchema6, JSONSchema7 } from 'json-schema';\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';\n\nimport {\n isOpenAPI30 as assertOpenAPI30,\n isOpenAPI31 as assertOpenAPI31,\n isSwagger as assertSwagger,\n} from '@readme/openapi-parser/lib/assertions';\n\nexport type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;\n\n/**\n * @param check Data to determine if it contains a ReferenceObject (`$ref` pointer`).\n * @returns If the supplied data has a `$ref` pointer.\n */\nexport function isRef(check: unknown): check is OpenAPIV3_1.ReferenceObject | OpenAPIV3.ReferenceObject {\n return typeof (check as OpenAPIV3_1.ReferenceObject | OpenAPIV3.ReferenceObject)?.$ref === 'string';\n}\n\n/**\n * Is a given object a Swagger API definition?\n *\n */\nexport const isSwagger: (schema: any) => schema is OpenAPIV2.Document = assertSwagger;\n\n/**\n * Is a given object an OpenAPI 3.0 API definition?\n *\n */\nexport const isOpenAPI30: (schema: any) => schema is OpenAPIV3.Document = assertOpenAPI30;\n\n/**\n * Is a given object an OpenAPI 3.1 API definition?\n *\n */\nexport const isOpenAPI31: (schema: any) => schema is OpenAPIV3_1.Document = assertOpenAPI31;\n\n/**\n * Data shape for taking OpenAPI operation data and converting it into HAR.\n *\n * @see {@link https://github.com/readmeio/oas/tree/main/packages/oas-to-har}\n */\nexport interface DataForHAR {\n body?: any;\n cookie?: Record<string, any>;\n formData?: Record<string, any>; // `application/x-www-form-urlencoded` requests payloads.\n header?: Record<string, any>;\n path?: Record<string, any>;\n query?: Record<string, any>;\n server?: {\n selected: number;\n variables?: ServerVariable;\n };\n}\n\nexport type AuthForHAR = Record<string, number | string | { pass?: string; user?: string }>;\n\nexport type SecuritySchemeDefaultAuthPrimitive = number | string;\n\nexport interface BasicAuthDefault {\n pass?: SecuritySchemeDefaultAuthPrimitive;\n user?: SecuritySchemeDefaultAuthPrimitive;\n}\n\nexport interface OAuthClientCredentialsDefault {\n client_id?: SecuritySchemeDefaultAuthPrimitive;\n client_secret?: SecuritySchemeDefaultAuthPrimitive;\n clientId?: SecuritySchemeDefaultAuthPrimitive;\n clientSecret?: SecuritySchemeDefaultAuthPrimitive;\n}\n\nexport type SecuritySchemeDefaultAuth =\n | SecuritySchemeDefaultAuthPrimitive\n | BasicAuthDefault\n | OAuthClientCredentialsDefault;\n\nexport interface User {\n [key: string]: unknown;\n keys?: {\n [key: string]: unknown;\n name: number | string;\n pass?: number | string;\n user?: number | string;\n }[];\n}\n\n/**\n * The type of security scheme. Used by `operation.getSecurityWithTypes()` and `operation.prepareSecurity()`.\n */\nexport type SecurityType = 'apiKey' | 'Basic' | 'Bearer' | 'Cookie' | 'Header' | 'http' | 'OAuth2' | 'Query';\n\nexport type HttpMethods =\n | OpenAPIV3_1.HttpMethods\n | OpenAPIV3.HttpMethods\n | 'delete'\n | 'get'\n | 'head'\n | 'options'\n | 'patch'\n | 'post'\n | 'put'\n | 'trace';\n\n// The following are custom OpenAPI types that we use throughout this library, sans\n// `ReferenceObject` because we assume that the API definition has been dereferenced.\n//\n// These are organized by how they're defined in the OpenAPI Specification.\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#openapi-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-object}\n */\nexport type OASDocument = (OpenAPIV3_1.Document | OpenAPIV3.Document) &\n // `x-*` extensions\n Record<string, unknown>;\n\nexport type OAS31Document = OpenAPIV3_1.Document &\n // `x-*` extensions\n Record<string, unknown>;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#server-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#server-object}\n */\nexport type ServerObject = OpenAPIV3_1.ServerObject | OpenAPIV3.ServerObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#server-variable-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#server-variable-object}\n */\nexport type ServerVariableObject = OpenAPIV3_1.ServerVariableObject | OpenAPIV3.ServerVariableObject;\nexport type ServerVariablesObject = Record<string, ServerVariableObject>;\nexport type ServerVariable = Record<\n string,\n { default?: number | string }[] | Record<string, never> | number | string | { default?: number | string }\n>;\n\nexport interface Servers {\n selected: number;\n variables: ServerVariable;\n}\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#components-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#components-object}\n */\nexport type ComponentsObject = OpenAPIV3_1.ComponentsObject | OpenAPIV3.ComponentsObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#reference-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#reference-object}\n */\nexport type ReferenceObject = OpenAPIV3_1.ReferenceObject | OpenAPIV3.ReferenceObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#paths-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#paths-object}\n */\nexport type PathsObject = OpenAPIV3_1.PathsObject | OpenAPIV3.PathsObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#path-item-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#path-item-object}\n */\nexport type PathItemObject = OpenAPIV3_1.PathItemObject | OpenAPIV3.PathItemObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operation-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operation-object}\n */\nexport type OperationObject = (OpenAPIV3_1.OperationObject | OpenAPIV3.OperationObject) &\n // `x-*` extensions\n Record<string, unknown>;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameter-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object}\n */\nexport type ParameterObject = {\n in: 'cookie' | 'header' | 'path' | 'query';\n} & (OpenAPIV3_1.ParameterObject | OpenAPIV3.ParameterObject);\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#request-body-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#request-body-object}\n */\nexport type RequestBodyObject = OpenAPIV3_1.RequestBodyObject | OpenAPIV3.RequestBodyObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#media-type-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n */\nexport type MediaTypeObject = OpenAPIV3_1.MediaTypeObject | OpenAPIV3.MediaTypeObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#response-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#response-object}\n */\nexport type ResponseObject = OpenAPIV3_1.ResponseObject | OpenAPIV3.ResponseObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callback-object}\n */\nexport type CallbackObject = OpenAPIV3_1.CallbackObject | OpenAPIV3.CallbackObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#example-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.3.md#example-object}\n */\nexport type ExampleObject = OpenAPIV3_1.ExampleObject | OpenAPIV3.ExampleObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#tag-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#tag-object}\n */\nexport type TagObject = OpenAPIV3_1.TagObject | OpenAPIV3.TagObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#header-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#header-object}\n */\nexport type HeaderObject = OpenAPIV3_1.HeaderObject | OpenAPIV3.HeaderObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport type SchemaObject = {\n // OpenAPI-specific properties\n externalDocs?: unknown;\n xml?: unknown;\n} & {\n // TODO: We should split this into one type for v3 and one type for v3.1 to ensure type accuracy.\n $schema?: string;\n\n // We add this to the schema to help out with circular refs\n components?: OpenAPIV3_1.ComponentsObject;\n\n deprecated?: boolean;\n example?: unknown;\n examples?: unknown[];\n nullable?: boolean;\n readOnly?: boolean;\n writeOnly?: boolean;\n\n // `discriminator` comes through in `OpenAPIV3.SchemaObject` but because we also union this type\n // to `JSONSchema` TS gets confused when we narrow types everywhere and doens't pick up valid\n // `discriminator` types when we need them.\n discriminator?: DiscriminatorObject;\n\n // We add this extension within our dereferencing work to preserve the origin dereferenced\n // schemas.\n 'x-readme-ref-name'?: string;\n} & (\n | OpenAPIV3.SchemaObject\n | OpenAPIV3_1.SchemaObject\n // Adding `JSONSchema` to this because `json-schema-merge-allof` expects those.\n | JSONSchema\n );\n\nexport interface SchemaWrapper {\n $schema?: string;\n description?: string;\n label?: string;\n schema: SchemaObject;\n type: string;\n}\n\n/**\n * Determine if a given JSON Schema object is a valid JSON Schema object and either has a declared\n * `type` or is polymorphic in one form or another.\n *\n * @param check JSON Schema object to determine if it's a non-polymorphic schema.\n * @param isPolymorphicAllOfChild If this JSON Schema object is the child of a polymorphic `allOf`.\n * @returns If the JSON Schema object is a JSON Schema object.\n */\nexport function isSchema(check: unknown, isPolymorphicAllOfChild = false): check is SchemaObject {\n return (\n (check as SchemaObject).type !== undefined ||\n (check as SchemaObject).allOf !== undefined ||\n (check as SchemaObject).anyOf !== undefined ||\n (check as SchemaObject).oneOf !== undefined ||\n isPolymorphicAllOfChild\n );\n}\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#security-scheme-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#security-scheme-object}\n */\nexport type SecuritySchemeObject = OpenAPIV3_1.SecuritySchemeObject | OpenAPIV3.SecuritySchemeObject;\n\nexport type SecuritySchemesObject = Record<string, SecuritySchemeObject>;\n\nexport type KeyedSecuritySchemeObject = SecuritySchemeObject & {\n /**\n * The key for the given security scheme object\n */\n _key: string;\n\n /**\n * An array of required scopes for the given security scheme object.\n * Used for `oauth2` security scheme types.\n */\n _requirements?: string[];\n\n // `x-default` is our custom extension for specifying auth defaults.\n // https://docs.readme.com/docs/openapi-extensions#authentication-defaults\n 'x-default'?: SecuritySchemeDefaultAuth;\n};\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#security-requirement-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#security-requirement-object}\n */\nexport type SecurityRequirementObject = OpenAPIV3_1.SecurityRequirementObject | OpenAPIV3.SecurityRequirementObject;\n\n/**\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminator-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#discriminator-object}\n */\nexport type DiscriminatorObject = OpenAPIV3.DiscriminatorObject | OpenAPIV3_1.DiscriminatorObject;\n\n/**\n * Mapping of discriminator schema names to their child schema names.\n * Used to pass information between the pre-dereference and post-dereference phases.\n */\nexport type DiscriminatorChildrenMap = Map<string, string[]>;\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/darrenyong/Desktop/oas-stuff/oas/packages/oas/dist/chunk-COHEPMUP.cjs","../src/analyzer/util.ts"],"names":[],"mappings":"AAAA;ACAA,6CAAyB;AAiBlB,SAAS,KAAA,CAAM,OAAA,EAAmB,UAAA,EAAmC;AAC1E,EAAA,MAAM,QAAA,EAAU,OAAA,CACb,GAAA,CAAI,CAAA,CAAA,EAAA,GAAK,oCAAA,EAAW,IAAA,EAAM,CAAA,EAAG,IAAA,EAAM,UAAA,EAAY,UAAA,EAAY,MAAM,CAAC,CAAC,CAAA,CACnE,MAAA,CAAO,CAAA,GAAA,EAAA,GAAQ,GAAA,CAAI,OAAA,EAAS,IAAA,EAAM,KAAM,CAAA,CACxC,MAAA,CAAO,CAAC,IAAA,EAAM,IAAA,EAAA,GAAS,IAAA,CAAK,MAAA,CAAO,IAAI,CAAA,EAAG,CAAC,CAAC,CAAA;AAG/C,EAAA,OAAA,CAAQ,IAAA,CAAK,CAAC,CAAA,EAAmB,CAAA,EAAA,GAAsB;AACrD,IAAA,GAAA,CAAI,CAAA,CAAE,QAAA,EAAU,CAAA,CAAE,OAAA,EAAS;AACzB,MAAA,OAAO,CAAA,CAAA;AAAA,IACT,EAAA,KAAA,GAAA,CAAW,CAAA,CAAE,QAAA,EAAU,CAAA,CAAE,OAAA,EAAS;AAChC,MAAA,OAAO,CAAA;AAAA,IACT;AAEA,IAAA,OAAO,CAAA;AAAA,EACT,CAAC,CAAA;AAED,EAAA,OAAO,OAAA;AACT;AAOO,SAAS,aAAA,CAAc,OAAA,EAAiB;AAC7C,EAAA,OAAO,CAAA,CAAA,EAAI,OAAO,CAAA,CAAA;AACpB;AD3BqB;AACA;AACA;AACA;AACA","file":"/Users/darrenyong/Desktop/oas-stuff/oas/packages/oas/dist/chunk-COHEPMUP.cjs","sourcesContent":[null,"import { JSONPath } from 'jsonpath-plus';\n\nexport interface JSONPathResult {\n hasArrExpr?: boolean;\n parent: any;\n parentProperty: string;\n path: string;\n pointer: string;\n value: any;\n}\n\n/**\n * Run a set of JSONPath queries against an API definition.\n *\n * @see {@link https://jsonpath.com/}\n * @see {@link https://npm.im/jsonpath-plus}\n */\nexport function query(queries: string[], definition: any): JSONPathResult[] {\n const results = queries\n .map(q => JSONPath({ path: q, json: definition, resultType: 'all' }))\n .filter(res => (res.length ? res : false))\n .reduce((prev, next) => prev.concat(next), []);\n\n // Always alphabetize our results by the JSON pointer.\n results.sort((a: JSONPathResult, b: JSONPathResult) => {\n if (a.pointer < b.pointer) {\n return -1;\n } else if (a.pointer > b.pointer) {\n return 1;\n }\n\n return 0;\n });\n\n return results;\n}\n\n/**\n * Transform a JSON pointer into a JSON Schema `$ref`-compatible pointer.\n *\n * @example `/paths/~1streams/post/callbacks` -> `#/paths/~1streams/post/callbacks`\n */\nexport function refizePointer(pointer: string) {\n return `#${pointer}`;\n}\n"]}
1
+ {"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas/dist/chunk-COHEPMUP.cjs","../src/analyzer/util.ts"],"names":[],"mappings":"AAAA;ACAA,6CAAyB;AAiBlB,SAAS,KAAA,CAAM,OAAA,EAAmB,UAAA,EAAmC;AAC1E,EAAA,MAAM,QAAA,EAAU,OAAA,CACb,GAAA,CAAI,CAAA,CAAA,EAAA,GAAK,oCAAA,EAAW,IAAA,EAAM,CAAA,EAAG,IAAA,EAAM,UAAA,EAAY,UAAA,EAAY,MAAM,CAAC,CAAC,CAAA,CACnE,MAAA,CAAO,CAAA,GAAA,EAAA,GAAQ,GAAA,CAAI,OAAA,EAAS,IAAA,EAAM,KAAM,CAAA,CACxC,MAAA,CAAO,CAAC,IAAA,EAAM,IAAA,EAAA,GAAS,IAAA,CAAK,MAAA,CAAO,IAAI,CAAA,EAAG,CAAC,CAAC,CAAA;AAG/C,EAAA,OAAA,CAAQ,IAAA,CAAK,CAAC,CAAA,EAAmB,CAAA,EAAA,GAAsB;AACrD,IAAA,GAAA,CAAI,CAAA,CAAE,QAAA,EAAU,CAAA,CAAE,OAAA,EAAS;AACzB,MAAA,OAAO,CAAA,CAAA;AAAA,IACT,EAAA,KAAA,GAAA,CAAW,CAAA,CAAE,QAAA,EAAU,CAAA,CAAE,OAAA,EAAS;AAChC,MAAA,OAAO,CAAA;AAAA,IACT;AAEA,IAAA,OAAO,CAAA;AAAA,EACT,CAAC,CAAA;AAED,EAAA,OAAO,OAAA;AACT;AAOO,SAAS,aAAA,CAAc,OAAA,EAAiB;AAC7C,EAAA,OAAO,CAAA,CAAA,EAAI,OAAO,CAAA,CAAA;AACpB;AD3BqB;AACA;AACA;AACA;AACA","file":"/Users/erunion/code/readme/oas/packages/oas/dist/chunk-COHEPMUP.cjs","sourcesContent":[null,"import { JSONPath } from 'jsonpath-plus';\n\nexport interface JSONPathResult {\n hasArrExpr?: boolean;\n parent: any;\n parentProperty: string;\n path: string;\n pointer: string;\n value: any;\n}\n\n/**\n * Run a set of JSONPath queries against an API definition.\n *\n * @see {@link https://jsonpath.com/}\n * @see {@link https://npm.im/jsonpath-plus}\n */\nexport function query(queries: string[], definition: any): JSONPathResult[] {\n const results = queries\n .map(q => JSONPath({ path: q, json: definition, resultType: 'all' }))\n .filter(res => (res.length ? res : false))\n .reduce((prev, next) => prev.concat(next), []);\n\n // Always alphabetize our results by the JSON pointer.\n results.sort((a: JSONPathResult, b: JSONPathResult) => {\n if (a.pointer < b.pointer) {\n return -1;\n } else if (a.pointer > b.pointer) {\n return 1;\n }\n\n return 0;\n });\n\n return results;\n}\n\n/**\n * Transform a JSON pointer into a JSON Schema `$ref`-compatible pointer.\n *\n * @example `/paths/~1streams/post/callbacks` -> `#/paths/~1streams/post/callbacks`\n */\nexport function refizePointer(pointer: string) {\n return `#${pointer}`;\n}\n"]}