oas 38.5.2 → 38.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/analyzer/index.cjs +17 -17
  2. package/dist/analyzer/index.cjs.map +1 -1
  3. package/dist/analyzer/index.js +2 -2
  4. package/dist/analyzer/types.cjs.map +1 -1
  5. package/dist/{chunk-A7BAE2SN.js → chunk-3X7ZLPYE.js} +26 -19
  6. package/dist/chunk-3X7ZLPYE.js.map +1 -0
  7. package/dist/{chunk-EARDDQSB.cjs → chunk-47FD2BIN.cjs} +5 -2
  8. package/dist/chunk-47FD2BIN.cjs.map +1 -0
  9. package/dist/{chunk-7LQKUYC7.js → chunk-5745XRSJ.js} +3 -3
  10. package/dist/chunk-7PWF3F2W.cjs.map +1 -1
  11. package/dist/chunk-COHEPMUP.cjs.map +1 -1
  12. package/dist/{chunk-T4AJWZEL.cjs → chunk-HQEDOVWO.cjs} +47 -32
  13. package/dist/chunk-HQEDOVWO.cjs.map +1 -0
  14. package/dist/{chunk-DYHV2B4Z.js → chunk-JHDEAXSK.js} +4 -1
  15. package/dist/chunk-JHDEAXSK.js.map +1 -0
  16. package/dist/{chunk-MYFJ2GV3.cjs → chunk-OBYCSKPS.cjs} +28 -21
  17. package/dist/chunk-OBYCSKPS.cjs.map +1 -0
  18. package/dist/{chunk-IV2FDFXA.js → chunk-PZR3GKKO.js} +19 -4
  19. package/dist/chunk-PZR3GKKO.js.map +1 -0
  20. package/dist/{chunk-JQGHPVGV.cjs → chunk-RUHLHK66.cjs} +74 -74
  21. package/dist/chunk-RUHLHK66.cjs.map +1 -0
  22. package/dist/extensions.cjs +4 -2
  23. package/dist/extensions.cjs.map +1 -1
  24. package/dist/extensions.d.cts +1 -1
  25. package/dist/extensions.d.ts +1 -1
  26. package/dist/extensions.js +3 -1
  27. package/dist/{index-C6OzXwLp.d.ts → index-B097koLb.d.ts} +2 -0
  28. package/dist/{index-C4bupNyk.d.cts → index-BmHgGqbY.d.cts} +2 -0
  29. package/dist/index.cjs +53 -53
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.cts +19 -1
  32. package/dist/index.d.ts +19 -1
  33. package/dist/index.js +3 -3
  34. package/dist/operation/index.cjs +4 -4
  35. package/dist/operation/index.cjs.map +1 -1
  36. package/dist/operation/index.js +3 -3
  37. package/dist/pruner/index.cjs +5 -5
  38. package/dist/pruner/index.cjs.map +1 -1
  39. package/dist/pruner/index.d.cts +1 -1
  40. package/dist/pruner/index.d.ts +1 -1
  41. package/dist/pruner/index.js +4 -4
  42. package/dist/reducer/index.cjs +5 -5
  43. package/dist/reducer/index.cjs.map +1 -1
  44. package/dist/reducer/index.d.cts +1 -1
  45. package/dist/reducer/index.d.ts +1 -1
  46. package/dist/reducer/index.js +4 -4
  47. package/dist/types.cjs.map +1 -1
  48. package/dist/utils.cjs +3 -3
  49. package/dist/utils.cjs.map +1 -1
  50. package/dist/utils.js +2 -2
  51. package/package.json +1 -1
  52. package/dist/chunk-A7BAE2SN.js.map +0 -1
  53. package/dist/chunk-DYHV2B4Z.js.map +0 -1
  54. package/dist/chunk-EARDDQSB.cjs.map +0 -1
  55. package/dist/chunk-IV2FDFXA.js.map +0 -1
  56. package/dist/chunk-JQGHPVGV.cjs.map +0 -1
  57. package/dist/chunk-MYFJ2GV3.cjs.map +0 -1
  58. package/dist/chunk-T4AJWZEL.cjs.map +0 -1
  59. /package/dist/{chunk-7LQKUYC7.js.map → chunk-5745XRSJ.js.map} +0 -0
@@ -8,8 +8,8 @@ var _chunkCOHEPMUPcjs = require('../chunk-COHEPMUP.cjs');
8
8
 
9
9
 
10
10
 
11
- var _chunkMYFJ2GV3cjs = require('../chunk-MYFJ2GV3.cjs');
12
- require('../chunk-EARDDQSB.cjs');
11
+ var _chunkOBYCSKPScjs = require('../chunk-OBYCSKPS.cjs');
12
+ require('../chunk-47FD2BIN.cjs');
13
13
 
14
14
 
15
15
 
@@ -116,7 +116,7 @@ function queryCached(queries, definition) {
116
116
  // src/analyzer/scope.ts
117
117
  var _jsonpointer = require('jsonpointer'); var _jsonpointer2 = _interopRequireDefault(_jsonpointer);
118
118
  function canonicalizeRefPointer($ref) {
119
- const pointer = _chunkMYFJ2GV3cjs.toPointer.call(void 0, $ref);
119
+ const pointer = _chunkOBYCSKPScjs.toPointer.call(void 0, $ref);
120
120
  try {
121
121
  return decodeURIComponent(pointer);
122
122
  } catch (e) {
@@ -154,7 +154,7 @@ function resolveKey(keys, target) {
154
154
  return keys.find((key) => key === target) || keys.find((key) => key.toLowerCase() === target.toLowerCase());
155
155
  }
156
156
  function resolvePathItem(raw, definition) {
157
- const resolved = _chunkMYFJ2GV3cjs.dereferenceRef.call(void 0, raw, definition);
157
+ const resolved = _chunkOBYCSKPScjs.dereferenceRef.call(void 0, raw, definition);
158
158
  if (!resolved || typeof resolved !== "object" || _chunk7PWF3F2Wcjs.isRef.call(void 0, resolved)) {
159
159
  return void 0;
160
160
  }
@@ -162,7 +162,7 @@ function resolvePathItem(raw, definition) {
162
162
  }
163
163
  function resolveMethodKey(container, method) {
164
164
  const methodKey = resolveKey(Object.keys(container), method);
165
- if (!methodKey || !_chunkMYFJ2GV3cjs.supportedMethods.includes(methodKey.toLowerCase())) {
165
+ if (!methodKey || !_chunkOBYCSKPScjs.supportedMethods.includes(methodKey.toLowerCase())) {
166
166
  return void 0;
167
167
  }
168
168
  return methodKey;
@@ -178,14 +178,14 @@ function accumulateReachableRefs(definition, seeds) {
178
178
  reachable.add(ref);
179
179
  let resolved;
180
180
  try {
181
- resolved = _jsonpointer2.default.get(definition, _chunkMYFJ2GV3cjs.toPointer.call(void 0, ref));
181
+ resolved = _jsonpointer2.default.get(definition, _chunkOBYCSKPScjs.toPointer.call(void 0, ref));
182
182
  } catch (e3) {
183
183
  continue;
184
184
  }
185
185
  if (resolved === void 0) {
186
186
  continue;
187
187
  }
188
- _chunkMYFJ2GV3cjs.collectRefsInSchema.call(void 0, resolved).forEach((nestedRef) => {
188
+ _chunkOBYCSKPScjs.collectRefsInSchema.call(void 0, resolved).forEach((nestedRef) => {
189
189
  if (!reachable.has(nestedRef)) {
190
190
  queue.push(nestedRef);
191
191
  }
@@ -195,7 +195,7 @@ function accumulateReachableRefs(definition, seeds) {
195
195
  }
196
196
  function buildAnchors(rootPointer, extraPointers, reachableRefs) {
197
197
  const anchors = [rootPointer, ...extraPointers];
198
- reachableRefs.forEach((ref) => anchors.push(_chunkMYFJ2GV3cjs.toPointer.call(void 0, ref)));
198
+ reachableRefs.forEach((ref) => anchors.push(_chunkOBYCSKPScjs.toPointer.call(void 0, ref)));
199
199
  return { anchors, anchorPrefixes: anchors.map((anchor) => `${anchor}/`) };
200
200
  }
201
201
  function collectSecuritySchemeRefs(security) {
@@ -230,16 +230,16 @@ function computeOperationScope(definition, path, method) {
230
230
  if (!operation || typeof operation !== "object") {
231
231
  throw new Error(`Operation \`${method} ${path}\` not found.`);
232
232
  }
233
- const rootPointer = `/paths/${_chunkMYFJ2GV3cjs.encodePointer.call(void 0, pathKey)}/${methodKey}`;
233
+ const rootPointer = `/paths/${_chunkOBYCSKPScjs.encodePointer.call(void 0, pathKey)}/${methodKey}`;
234
234
  const extraPointers = [];
235
- const seeds = new Set(_chunkMYFJ2GV3cjs.collectRefsInSchema.call(void 0, operation));
235
+ const seeds = new Set(_chunkOBYCSKPScjs.collectRefsInSchema.call(void 0, operation));
236
236
  const targetPointer = resolvePathItemTargetPointer(rawPathItem, definition);
237
237
  if (targetPointer) {
238
238
  extraPointers.push(`${targetPointer}/${methodKey}`);
239
239
  }
240
240
  if (pathItem.parameters) {
241
- extraPointers.push(targetPointer ? `${targetPointer}/parameters` : `/paths/${_chunkMYFJ2GV3cjs.encodePointer.call(void 0, pathKey)}/parameters`);
242
- _chunkMYFJ2GV3cjs.collectRefsInSchema.call(void 0, pathItem.parameters).forEach((ref) => seeds.add(ref));
241
+ extraPointers.push(targetPointer ? `${targetPointer}/parameters` : `/paths/${_chunkOBYCSKPScjs.encodePointer.call(void 0, pathKey)}/parameters`);
242
+ _chunkOBYCSKPScjs.collectRefsInSchema.call(void 0, pathItem.parameters).forEach((ref) => seeds.add(ref));
243
243
  }
244
244
  const security = "security" in operation ? operation.security : definition.security;
245
245
  collectSecuritySchemeRefs(security).forEach((ref) => seeds.add(ref));
@@ -265,18 +265,18 @@ function computeWebhookScope(definition, webhookName, method) {
265
265
  if (!operation || typeof operation !== "object") {
266
266
  throw new Error(`Webhook operation \`${method} ${webhookName}\` not found.`);
267
267
  }
268
- const rootPointer = `/webhooks/${_chunkMYFJ2GV3cjs.encodePointer.call(void 0, webhookKey)}/${methodKey}`;
268
+ const rootPointer = `/webhooks/${_chunkOBYCSKPScjs.encodePointer.call(void 0, webhookKey)}/${methodKey}`;
269
269
  const extraPointers = [];
270
- const seeds = new Set(_chunkMYFJ2GV3cjs.collectRefsInSchema.call(void 0, operation));
270
+ const seeds = new Set(_chunkOBYCSKPScjs.collectRefsInSchema.call(void 0, operation));
271
271
  const targetPointer = resolvePathItemTargetPointer(rawWebhook, definition);
272
272
  if (targetPointer) {
273
273
  extraPointers.push(`${targetPointer}/${methodKey}`);
274
274
  }
275
275
  if (webhook.parameters) {
276
276
  extraPointers.push(
277
- targetPointer ? `${targetPointer}/parameters` : `/webhooks/${_chunkMYFJ2GV3cjs.encodePointer.call(void 0, webhookKey)}/parameters`
277
+ targetPointer ? `${targetPointer}/parameters` : `/webhooks/${_chunkOBYCSKPScjs.encodePointer.call(void 0, webhookKey)}/parameters`
278
278
  );
279
- _chunkMYFJ2GV3cjs.collectRefsInSchema.call(void 0, webhook.parameters).forEach((ref) => seeds.add(ref));
279
+ _chunkOBYCSKPScjs.collectRefsInSchema.call(void 0, webhook.parameters).forEach((ref) => seeds.add(ref));
280
280
  }
281
281
  const security = "security" in operation ? operation.security : definition.security;
282
282
  collectSecuritySchemeRefs(security).forEach((ref) => seeds.add(ref));
@@ -467,7 +467,7 @@ async function buildAnalysis(definition, query2, scope) {
467
467
  }
468
468
  if (!query2 || query2.includes("circularRefs")) {
469
469
  const { circularRefs: dereferencedCircularRefs } = await dereferenceOasShared(definition);
470
- const circularRefs = (scope ? dereferencedCircularRefs.filter((ref) => isPointerInScope(_chunkMYFJ2GV3cjs.toPointer.call(void 0, ref), scope)) : [...dereferencedCircularRefs]).toSorted();
470
+ const circularRefs = (scope ? dereferencedCircularRefs.filter((ref) => isPointerInScope(_chunkOBYCSKPScjs.toPointer.call(void 0, ref), scope)) : [...dereferencedCircularRefs]).toSorted();
471
471
  analysis.circularRefs = {
472
472
  present: !!circularRefs.length,
473
473
  locations: circularRefs
@@ -1 +1 @@
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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EuC,EAAA;AACO,IAAA;AAC3B,IAAA;AACE,MAAA;AACNC,MAAAA;AACb,IAAA;AACF,EAAA;AAEuC,EAAA;AACN,IAAA;AACd,IAAA;AACmB,MAAA;AACvBC,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;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
+ {"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;A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AAA;AACF,EAAA;AAEuC,EAAA;AACO,IAAA;AAC3B,IAAA;AACE,MAAA;AACNC,MAAAA;AACb,IAAA;AACF,EAAA;AAEuC,EAAA;AACN,IAAA;AACd,IAAA;AACmB,MAAA;AACvBC,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;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"]}
@@ -8,8 +8,8 @@ import {
8
8
  encodePointer,
9
9
  supportedMethods,
10
10
  toPointer
11
- } from "../chunk-A7BAE2SN.js";
12
- import "../chunk-DYHV2B4Z.js";
11
+ } from "../chunk-3X7ZLPYE.js";
12
+ import "../chunk-JHDEAXSK.js";
13
13
  import {
14
14
  isOpenAPI31,
15
15
  isRef
@@ -1 +1 @@
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
+ {"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,7 +1,7 @@
1
1
  import {
2
2
  PARAMETER_ORDERING,
3
3
  getExtension
4
- } from "./chunk-DYHV2B4Z.js";
4
+ } from "./chunk-JHDEAXSK.js";
5
5
  import {
6
6
  isOpenAPI30,
7
7
  isRef,
@@ -309,7 +309,7 @@ function allOfReferencesSchema(schema, targetSchemaName) {
309
309
  return schema.allOf.some((item) => {
310
310
  if (isRef(item)) {
311
311
  const refParts = item.$ref.split("/");
312
- const refSchemaName = refParts[refParts.length - 1];
312
+ const refSchemaName = decodePointer(refParts[refParts.length - 1]);
313
313
  return refSchemaName === targetSchemaName;
314
314
  }
315
315
  return false;
@@ -333,7 +333,13 @@ function findDiscriminatorChildren(definition) {
333
333
  if (discriminator.mapping && typeof discriminator.mapping === "object") {
334
334
  const mappingRefs = Object.values(discriminator.mapping);
335
335
  if (mappingRefs.length > 0) {
336
- childSchemaNames = mappingRefs.map((ref) => ref.split("/").pop()).filter((name) => {
336
+ childSchemaNames = mappingRefs.map((value) => {
337
+ if (Object.hasOwn(schemas, value)) {
338
+ return value;
339
+ }
340
+ const encodedName = value.split("/").pop() ?? "";
341
+ return decodePointer(encodedName);
342
+ }).filter((name) => {
337
343
  if (!name) return false;
338
344
  const childSchema = schemas[name];
339
345
  return !!childSchema && allOfReferencesSchema(childSchema, baseName);
@@ -348,10 +354,10 @@ function findDiscriminatorChildren(definition) {
348
354
  }
349
355
  if (childSchemaNames.length) {
350
356
  for (const childName of childSchemaNames) {
351
- childrenRefMap.set(childName, `#/components/schemas/${childName}`);
357
+ childrenRefMap.set(childName, `#/components/schemas/${encodePointer(childName)}`);
352
358
  }
353
359
  childrenMap.set(baseName, childSchemaNames);
354
- childrenRefMap.set(baseName, `#/components/schemas/${baseName}`);
360
+ childrenRefMap.set(baseName, `#/components/schemas/${encodePointer(baseName)}`);
355
361
  }
356
362
  }
357
363
  return { children: childrenMap, refs: childrenRefMap };
@@ -718,21 +724,21 @@ function searchForValueByPropAndPointer(property, pointer, schemas = []) {
718
724
  }
719
725
  let foundValue;
720
726
  const rev = [...schemas].toReversed();
721
- for (let i = 0; i < pointers.length; i += 1) {
722
- for (let ii = 0; ii < rev.length; ii += 1) {
723
- let schema = rev[ii];
724
- if (property === "example") {
725
- if ("example" in schema) {
726
- schema = schema.example;
727
- } else {
728
- if (!Array.isArray(schema.examples) || !schema.examples.length) {
729
- continue;
730
- }
731
- schema = [...schema.examples].shift();
732
- }
727
+ for (let ii = 0; ii < rev.length; ii += 1) {
728
+ let schema = rev[ii];
729
+ if (property === "example") {
730
+ if ("example" in schema) {
731
+ schema = schema.example;
733
732
  } else {
734
- schema = schema.default;
733
+ if (!Array.isArray(schema.examples) || !schema.examples.length) {
734
+ continue;
735
+ }
736
+ schema = [...schema.examples].shift();
735
737
  }
738
+ } else {
739
+ schema = schema.default;
740
+ }
741
+ for (let i = pointers.length - 1; i >= 0; i -= 1) {
736
742
  try {
737
743
  foundValue = jsonpointer2.get(schema, pointers[i]);
738
744
  } catch {
@@ -1595,6 +1601,7 @@ export {
1595
1601
  matches_mimetype_default,
1596
1602
  getParameterContentType,
1597
1603
  cloneObject,
1604
+ findDiscriminatorChildren,
1598
1605
  applyDiscriminatorOneOfToUsedSchemas,
1599
1606
  getSchemaVersionString,
1600
1607
  toJSONSchema,
@@ -1603,4 +1610,4 @@ export {
1603
1610
  supportedMethods,
1604
1611
  SERVER_VARIABLE_REGEX
1605
1612
  };
1606
- //# sourceMappingURL=chunk-A7BAE2SN.js.map
1613
+ //# sourceMappingURL=chunk-3X7ZLPYE.js.map