schema-components 1.22.0 → 1.23.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 (82) hide show
  1. package/README.md +3 -1
  2. package/dist/core/adapter.d.mts +97 -3
  3. package/dist/core/adapter.mjs +260 -111
  4. package/dist/core/constraints.d.mts +2 -2
  5. package/dist/core/constraints.mjs +0 -7
  6. package/dist/core/cssClasses.d.mts +52 -0
  7. package/dist/core/cssClasses.mjs +51 -0
  8. package/dist/core/diagnostics.d.mts +1 -1
  9. package/dist/core/errors.d.mts +1 -1
  10. package/dist/core/errors.mjs +5 -13
  11. package/dist/core/fieldOrder.d.mts +1 -1
  12. package/dist/core/formats.d.mts +9 -2
  13. package/dist/core/formats.mjs +12 -1
  14. package/dist/core/idPath.d.mts +54 -0
  15. package/dist/core/idPath.mjs +66 -0
  16. package/dist/core/merge.d.mts +10 -1
  17. package/dist/core/merge.mjs +49 -10
  18. package/dist/core/normalise.d.mts +14 -3
  19. package/dist/core/normalise.mjs +2 -2
  20. package/dist/core/openapi30.d.mts +15 -1
  21. package/dist/core/openapi30.mjs +2 -2
  22. package/dist/core/openapiConstants.d.mts +67 -0
  23. package/dist/core/openapiConstants.mjs +90 -0
  24. package/dist/core/ref.d.mts +2 -2
  25. package/dist/core/ref.mjs +84 -6
  26. package/dist/core/refChain.d.mts +70 -0
  27. package/dist/core/refChain.mjs +44 -0
  28. package/dist/core/renderer.d.mts +1 -1
  29. package/dist/core/swagger2.d.mts +1 -1
  30. package/dist/core/swagger2.mjs +1 -1
  31. package/dist/core/typeInference.d.mts +982 -2
  32. package/dist/core/types.d.mts +1 -1
  33. package/dist/core/unionMatch.d.mts +36 -0
  34. package/dist/core/unionMatch.mjs +53 -0
  35. package/dist/core/version.d.mts +1 -1
  36. package/dist/core/version.mjs +29 -17
  37. package/dist/core/walkBuilders.d.mts +23 -4
  38. package/dist/core/walkBuilders.mjs +27 -7
  39. package/dist/core/walker.d.mts +1 -1
  40. package/dist/core/walker.mjs +44 -45
  41. package/dist/{diagnostics-D0QCYGv0.d.mts → diagnostics-BS2kaUyE.d.mts} +1 -1
  42. package/dist/{errors-DpFwqs5C.d.mts → errors-g_MCTQel.d.mts} +9 -15
  43. package/dist/html/a11y.d.mts +9 -4
  44. package/dist/html/a11y.mjs +10 -19
  45. package/dist/html/renderToHtml.d.mts +2 -2
  46. package/dist/html/renderToHtmlStream.d.mts +2 -2
  47. package/dist/html/renderToHtmlStream.mjs +12 -1
  48. package/dist/html/renderers.d.mts +43 -8
  49. package/dist/html/renderers.mjs +136 -111
  50. package/dist/html/streamRenderers.d.mts +4 -5
  51. package/dist/html/streamRenderers.mjs +40 -61
  52. package/dist/{normalise-DVEJQmF7.mjs → normalise-DCYp06Sr.mjs} +352 -162
  53. package/dist/openapi/ApiCallbacks.d.mts +1 -1
  54. package/dist/openapi/ApiLinks.d.mts +1 -1
  55. package/dist/openapi/ApiResponseHeaders.d.mts +1 -1
  56. package/dist/openapi/ApiSecurity.d.mts +1 -1
  57. package/dist/openapi/components.d.mts +116 -37
  58. package/dist/openapi/components.mjs +54 -37
  59. package/dist/openapi/parser.d.mts +9 -8
  60. package/dist/openapi/parser.mjs +234 -84
  61. package/dist/openapi/resolve.d.mts +20 -11
  62. package/dist/openapi/resolve.mjs +133 -73
  63. package/dist/react/SchemaComponent.d.mts +32 -7
  64. package/dist/react/SchemaComponent.mjs +45 -21
  65. package/dist/react/SchemaView.d.mts +30 -10
  66. package/dist/react/a11y.d.mts +21 -0
  67. package/dist/react/a11y.mjs +24 -0
  68. package/dist/react/fieldPath.d.mts +1 -1
  69. package/dist/react/headless.d.mts +1 -1
  70. package/dist/react/headlessRenderers.d.mts +8 -9
  71. package/dist/react/headlessRenderers.mjs +41 -72
  72. package/dist/{ref-D-_JBZkF.d.mts → ref-DjLEKa_E.d.mts} +38 -3
  73. package/dist/{renderer-BaRlQIuN.d.mts → renderer-CXJ8y0qw.d.mts} +1 -1
  74. package/dist/themes/mantine.d.mts +1 -1
  75. package/dist/themes/mui.d.mts +1 -1
  76. package/dist/themes/radix.d.mts +1 -1
  77. package/dist/themes/shadcn.d.mts +1 -1
  78. package/dist/themes/shadcn.mjs +2 -1
  79. package/dist/{types-BrRMV0en.d.mts → types-BTB73MB8.d.mts} +32 -4
  80. package/dist/{version-D2jfdX6E.d.mts → version-BFTVLsdb.d.mts} +7 -1
  81. package/package.json +1 -1
  82. package/dist/typeInference-DkcUHfaM.d.mts +0 -982
@@ -1,14 +1,37 @@
1
1
  import { getProperty, isObject } from "../core/guards.mjs";
2
2
  import "../core/limits.mjs";
3
+ import { emitDiagnostic } from "../core/diagnostics.mjs";
3
4
  import { isPrototypePollutingKey } from "../core/uri.mjs";
5
+ import { detectOpenApiVersion } from "../core/version.mjs";
6
+ import { HTTP_METHODS } from "../core/openapiConstants.mjs";
7
+ import { resolveRefChain } from "../core/refChain.mjs";
4
8
  //#region src/openapi/parser.ts
5
9
  function getString(value, key) {
6
10
  const result = isObject(value) ? value[key] : void 0;
7
11
  return typeof result === "string" ? result : void 0;
8
12
  }
9
- function toParameterLocation(value) {
13
+ /**
14
+ * Narrow an OpenAPI parameter `in` value to the canonical four-value
15
+ * `ParameterLocation` union. Returns `undefined` for any other value
16
+ * (including the Swagger 2.0 `body`/`formData` locations, which the
17
+ * Swagger 2.0 → OpenAPI 3.x normaliser is expected to have already
18
+ * lifted out of the parameter array). When `diagnostics` is supplied,
19
+ * emits an `unknown-parameter-location` diagnostic so the caller can
20
+ * audit silent drops; without a sink the function still returns
21
+ * `undefined` rather than coercing the value, so the parameter is
22
+ * excluded from the operation's parameter list either way.
23
+ */
24
+ function toParameterLocation(value, parameterName, pointer, diagnostics) {
10
25
  if (value === "query" || value === "path" || value === "header" || value === "cookie") return value;
11
- return "query";
26
+ emitDiagnostic(diagnostics, {
27
+ code: "unknown-parameter-location",
28
+ message: parameterName !== void 0 ? `Parameter "${parameterName}" declares unknown \`in\` value ${JSON.stringify(value)}; expected one of query, path, header, cookie` : `Parameter declares unknown \`in\` value ${JSON.stringify(value)}; expected one of query, path, header, cookie`,
29
+ pointer,
30
+ detail: {
31
+ name: parameterName,
32
+ in: value
33
+ }
34
+ });
12
35
  }
13
36
  function parseOpenApiDocument(doc) {
14
37
  const schemas = /* @__PURE__ */ new Map();
@@ -30,62 +53,79 @@ function getSchema(parsed, ref) {
30
53
  return resolved;
31
54
  }
32
55
  }
33
- const METHODS = [
34
- "get",
35
- "post",
36
- "put",
37
- "patch",
38
- "delete",
39
- "head",
40
- "options",
41
- "trace"
42
- ];
43
- /**
44
- * Resolve a path item, following a `$ref` to `components/pathItems/<Name>`
45
- * (OpenAPI 3.1) if present. Returns `undefined` when the value is not a
46
- * path item, the ref is malformed, or the target does not resolve.
47
- */
48
56
  /**
49
57
  * Follow Path Item Object `$ref` chains (up to MAX_PATH_ITEM_REF_HOPS).
50
58
  * Returns the resolved Path Item, or `undefined` when the chain cycles,
51
- * exceeds the cap, or any intermediate ref fails to resolve. The
52
- * detailed diagnostics for cycle and depth-cap are emitted by the
53
- * mirroring resolver in `resolve.ts` this parser-side resolver simply
54
- * stops walking.
59
+ * exceeds the cap, or any intermediate ref fails to resolve.
60
+ *
61
+ * When `diagnostics` is supplied, cycle and depth-cap conditions emit
62
+ * `cyclic-path-item-ref` and `path-item-ref-too-deep` respectively. When
63
+ * `diagnostics` is omitted, the resolver still rejects cycles and
64
+ * over-deep chains silently — callers that wire their own resolver
65
+ * (notably `resolve.ts:resolvePathItemNode`) supply diagnostics to
66
+ * mirror this behaviour with full pointer information.
55
67
  */
56
- function resolvePathItem(parsed, pathItem) {
68
+ function resolvePathItem(parsed, pathItem, diagnostics) {
57
69
  if (!isObject(pathItem)) return void 0;
58
- const visited = /* @__PURE__ */ new Set();
59
- let current = pathItem;
60
- for (let hop = 0; hop < 8; hop++) {
61
- const ref = getString(current, "$ref");
62
- if (ref === void 0) return current;
63
- if (visited.has(ref)) return void 0;
64
- visited.add(ref);
65
- const target = resolveRefInDoc(parsed.doc, ref);
66
- if (target === void 0) return void 0;
67
- current = target;
68
- }
70
+ return resolveRefChain(pathItem, {
71
+ lookup: (ref) => ref.startsWith("#/") ? resolveRefInDoc(parsed.doc, ref) : void 0,
72
+ maxHops: 8,
73
+ onCycle: (ref) => {
74
+ emitDiagnostic(diagnostics, {
75
+ code: "cyclic-path-item-ref",
76
+ message: `Cyclic Path Item Object $ref "${ref}"`,
77
+ pointer: ref,
78
+ detail: { ref }
79
+ });
80
+ },
81
+ onDepthExceeded: (ref) => {
82
+ emitDiagnostic(diagnostics, {
83
+ code: "path-item-ref-too-deep",
84
+ message: `Path Item Object $ref chain exceeded ${String(8)} hops`,
85
+ pointer: ref,
86
+ detail: {
87
+ maxHops: 8,
88
+ ref
89
+ }
90
+ });
91
+ }
92
+ });
69
93
  }
70
94
  function lookupPathItem(parsed, path) {
71
95
  const resolved = resolvePathItem(parsed, getProperty(getProperty(parsed.doc, "paths"), path));
72
96
  if (resolved !== void 0) return resolved;
73
97
  return resolvePathItem(parsed, getProperty(getProperty(parsed.doc, "webhooks"), path));
74
98
  }
75
- function listOperations(parsed) {
99
+ function listOperations(parsed, diagnostics) {
76
100
  const operations = [];
77
101
  const paths = getProperty(parsed.doc, "paths");
78
102
  if (!isObject(paths)) return operations;
103
+ const seenIds = /* @__PURE__ */ new Map();
79
104
  for (const [path, rawPathItem] of Object.entries(paths)) {
80
- const pathItem = resolvePathItem(parsed, rawPathItem);
105
+ const pathItem = resolvePathItem(parsed, rawPathItem, diagnostics);
81
106
  if (pathItem === void 0) continue;
82
- for (const method of METHODS) {
107
+ for (const method of HTTP_METHODS) {
83
108
  const operation = getProperty(pathItem, method);
84
109
  if (!isObject(operation)) continue;
110
+ const operationId = getString(operation, "operationId");
111
+ if (operationId !== void 0) {
112
+ const firstSeenAt = seenIds.get(operationId);
113
+ if (firstSeenAt !== void 0) emitDiagnostic(diagnostics, {
114
+ code: "duplicate-operation-id",
115
+ message: `operationId "${operationId}" is declared more than once (first at ${firstSeenAt}, again at ${method.toUpperCase()} ${path})`,
116
+ pointer: `/paths/${jsonPointerEscape(path)}/${method}/operationId`,
117
+ detail: {
118
+ operationId,
119
+ firstSeenAt,
120
+ duplicateAt: `${method.toUpperCase()} ${path}`
121
+ }
122
+ });
123
+ else seenIds.set(operationId, `${method.toUpperCase()} ${path}`);
124
+ }
85
125
  operations.push({
86
126
  path,
87
127
  method,
88
- operationId: getString(operation, "operationId"),
128
+ operationId,
89
129
  summary: getString(operation, "summary"),
90
130
  description: getString(operation, "description"),
91
131
  deprecated: getProperty(operation, "deprecated") === true,
@@ -95,31 +135,35 @@ function listOperations(parsed) {
95
135
  }
96
136
  return operations;
97
137
  }
98
- function getParameters(parsed, path, method) {
138
+ function getParameters(parsed, path, method, diagnostics) {
99
139
  const pathItem = lookupPathItem(parsed, path);
100
140
  if (pathItem === void 0) return [];
101
141
  const operation = getProperty(pathItem, method);
102
142
  if (!isObject(operation)) return [];
103
- const pathParams = extractParameterList(parsed.doc, getProperty(pathItem, "parameters"));
104
- const opParams = extractParameterList(parsed.doc, getProperty(operation, "parameters"));
143
+ const pathParams = extractParameterList(parsed.doc, getProperty(pathItem, "parameters"), `/paths/${jsonPointerEscape(path)}/parameters`, diagnostics);
144
+ const opParams = extractParameterList(parsed.doc, getProperty(operation, "parameters"), `/paths/${jsonPointerEscape(path)}/${method}/parameters`, diagnostics);
105
145
  const map = /* @__PURE__ */ new Map();
106
146
  for (const param of pathParams) map.set(`${param.name}:${param.location}`, param);
107
147
  for (const param of opParams) map.set(`${param.name}:${param.location}`, param);
108
148
  return [...map.values()];
109
149
  }
110
- function extractParameterList(doc, parameters) {
150
+ function extractParameterList(doc, parameters, pointerBase, diagnostics) {
111
151
  if (!Array.isArray(parameters)) return [];
112
152
  const result = [];
113
- for (const param of parameters) {
153
+ for (const [index, param] of parameters.entries()) {
114
154
  if (!isObject(param)) continue;
115
- const resolved = resolveParam(doc, param);
155
+ const entryPointer = `${pointerBase}/${String(index)}`;
156
+ const resolved = resolveParam(doc, param, diagnostics);
157
+ if (resolved === void 0) continue;
116
158
  const name = getProperty(resolved, "name");
117
- const location = getProperty(resolved, "in");
118
- if (typeof name !== "string" || typeof location !== "string") continue;
159
+ const rawLocation = getProperty(resolved, "in");
160
+ if (typeof name !== "string" || typeof rawLocation !== "string") continue;
161
+ const location = toParameterLocation(rawLocation, name, `${entryPointer}/in`, diagnostics);
162
+ if (location === void 0) continue;
119
163
  const schema = getProperty(resolved, "schema");
120
164
  result.push({
121
165
  name,
122
- location: toParameterLocation(location),
166
+ location,
123
167
  required: getProperty(resolved, "required") === true,
124
168
  deprecated: getProperty(resolved, "deprecated") === true,
125
169
  description: getString(resolved, "description"),
@@ -128,13 +172,69 @@ function extractParameterList(doc, parameters) {
128
172
  }
129
173
  return result;
130
174
  }
131
- function resolveParam(doc, param) {
132
- const ref = getProperty(param, "$ref");
133
- if (typeof ref === "string" && ref.startsWith("#/")) {
134
- const resolved = resolveRefInDoc(doc, ref);
135
- if (resolved !== void 0) return resolved;
136
- }
137
- return param;
175
+ /**
176
+ * Resolve a Reference Object chain on a non-Path-Item OpenAPI node
177
+ * (Parameter, Header, Link, etc.). Single-hop resolution is insufficient
178
+ * because OAS 3.x permits chains of Reference Objects of arbitrary
179
+ * length a Reference Object whose target is itself a Reference Object
180
+ * is legal. `resolveRefChain` centralises cycle and depth-cap protection.
181
+ *
182
+ * Cycles and over-deep chains reuse the existing `cyclic-path-item-ref`
183
+ * and `path-item-ref-too-deep` diagnostic codes with a
184
+ * `detail.kind: "<node-kind>"` discriminator (e.g. `"parameter"`,
185
+ * `"header"`, `"link"`). There is no dedicated code per node kind in the
186
+ * current `DiagnosticCode` union; consumers filter by `detail.kind` when
187
+ * they care to distinguish the source.
188
+ *
189
+ * TODO(round7-integration): consider adding dedicated `cyclic-*-ref` /
190
+ * `*-ref-too-deep` codes per node kind to `core/diagnostics.ts` so the
191
+ * kind discriminator on `detail` is not needed. The existing Swagger
192
+ * 2.0 path already uses a dedicated `swagger-cyclic-parameter-ref` for
193
+ * the equivalent failure mode.
194
+ */
195
+ function resolveReferenceObjectChain(doc, node, kind, diagnostics) {
196
+ const kindLabel = kind === "parameter" ? "Parameter Object" : kind === "header" ? "Header Object" : "Link Object";
197
+ return resolveRefChain(node, {
198
+ lookup: (ref) => ref.startsWith("#/") ? resolveRefInDoc(doc, ref) : void 0,
199
+ onCycle: (ref) => {
200
+ emitDiagnostic(diagnostics, {
201
+ code: "cyclic-path-item-ref",
202
+ message: `Cyclic ${kindLabel} $ref "${ref}"`,
203
+ pointer: ref,
204
+ detail: {
205
+ ref,
206
+ kind
207
+ }
208
+ });
209
+ },
210
+ onDepthExceeded: (ref) => {
211
+ emitDiagnostic(diagnostics, {
212
+ code: "path-item-ref-too-deep",
213
+ message: `${kindLabel} $ref chain exceeded the hop cap starting from "${ref}"`,
214
+ pointer: ref,
215
+ detail: {
216
+ ref,
217
+ kind
218
+ }
219
+ });
220
+ }
221
+ });
222
+ }
223
+ /**
224
+ * Resolve a Parameter Object `$ref` chain. See
225
+ * `resolveReferenceObjectChain` for the resolution contract.
226
+ */
227
+ function resolveParam(doc, param, diagnostics) {
228
+ return resolveReferenceObjectChain(doc, param, "parameter", diagnostics);
229
+ }
230
+ /**
231
+ * Encode a path segment for embedding in a JSON Pointer (RFC 6901).
232
+ * `~` → `~0`, `/` → `~1`. Used to build pointer fragments for diagnostics
233
+ * — the diagnostics layer does not currently re-encode segments inserted
234
+ * via template strings.
235
+ */
236
+ function jsonPointerEscape(segment) {
237
+ return segment.replace(/~/g, "~0").replace(/\//g, "~1");
138
238
  }
139
239
  function getRequestBody(parsed, path, method) {
140
240
  const requestBodyRaw = getProperty(getProperty(lookupPathItem(parsed, path), method), "requestBody");
@@ -157,7 +257,7 @@ function getRequestBody(parsed, path, method) {
157
257
  schema
158
258
  };
159
259
  }
160
- function getResponses(parsed, path, method) {
260
+ function getResponses(parsed, path, method, diagnostics) {
161
261
  const responses = getProperty(getProperty(lookupPathItem(parsed, path), method), "responses");
162
262
  if (!isObject(responses)) return [];
163
263
  const result = [];
@@ -168,7 +268,7 @@ function getResponses(parsed, path, method) {
168
268
  const content = getProperty(response, "content");
169
269
  const contentTypes = isObject(content) ? Object.keys(content) : [];
170
270
  const schema = isObject(content) ? extractSchemaFromContent(content) : void 0;
171
- const headers = getResponseHeaders(response, parsed.doc);
271
+ const headers = getResponseHeaders(response, parsed.doc, diagnostics);
172
272
  result.push({
173
273
  statusCode,
174
274
  description: getString(response, "description"),
@@ -186,15 +286,60 @@ function getResponses(parsed, path, method) {
186
286
  * it has no `$ref`, or `undefined` when the `$ref` is malformed or
187
287
  * cannot be resolved (so the caller skips the entry rather than reading
188
288
  * stale fields from the bare `{ $ref }` envelope).
289
+ *
290
+ * OpenAPI 3.1 Reference Object — sibling merge. OAS 3.1 explicitly
291
+ * permits `summary` and `description` siblings of `$ref`; the wrapper's
292
+ * siblings override the corresponding fields on the referenced node
293
+ * (spec: "If the property is present on both the Reference Object and
294
+ * the referenced node, the value on the Reference Object overrides the
295
+ * value of the referenced node"). OAS 3.0 forbids siblings, so the merge
296
+ * is gated on the document version. The gating is best-effort — if no
297
+ * recognisable `openapi`/`swagger` field is present we err on the side
298
+ * of NOT merging siblings to avoid changing behaviour for ambiguous or
299
+ * partially-built documents.
189
300
  */
190
301
  function resolveWrapperRef(doc, wrapper) {
191
302
  const ref = getString(wrapper, "$ref");
192
303
  if (ref === void 0) return wrapper;
193
- return resolveRefInDoc(doc, ref);
304
+ const target = resolveRefInDoc(doc, ref);
305
+ if (target === void 0) return void 0;
306
+ if (!documentAllowsReferenceSiblings(doc)) return target;
307
+ return mergeReferenceSiblings(wrapper, target);
308
+ }
309
+ /**
310
+ * OAS 3.1 admits `summary` and `description` siblings on a Reference
311
+ * Object; OAS 3.0 does not. Detect the document version once per call
312
+ * — `detectOpenApiVersion` reads the top-level `openapi`/`swagger` field
313
+ * and is cheap enough to call on every resolution without caching.
314
+ */
315
+ function documentAllowsReferenceSiblings(doc) {
316
+ const version = detectOpenApiVersion(doc);
317
+ if (version === void 0) return false;
318
+ return version.major === 3 && version.minor >= 1;
319
+ }
320
+ /**
321
+ * Per OAS 3.1, only `summary` and `description` siblings on a Reference
322
+ * Object are permitted and they override the referenced node. Any other
323
+ * sibling is ignored (spec: "Any properties of a Reference Object other
324
+ * than those described above SHALL be ignored"). The returned object is
325
+ * a fresh shallow merge — the input wrapper and target are not mutated.
326
+ */
327
+ const REFERENCE_OBJECT_SIBLING_KEYS = ["summary", "description"];
328
+ function mergeReferenceSiblings(wrapper, target) {
329
+ const merged = { ...target };
330
+ for (const key of REFERENCE_OBJECT_SIBLING_KEYS) {
331
+ const siblingValue = wrapper[key];
332
+ if (typeof siblingValue === "string") merged[key] = siblingValue;
333
+ }
334
+ return merged;
194
335
  }
195
336
  function extractSchemaFromContent(content) {
196
- const jsonSchema = getProperty(getProperty(content, "application/json"), "schema");
197
- if (isObject(jsonSchema)) return jsonSchema;
337
+ for (const [mediaType, mediaObj] of Object.entries(content)) {
338
+ if (mediaTypeBase(mediaType) !== "application/json") continue;
339
+ if (!isObject(mediaObj)) continue;
340
+ const schema = getProperty(mediaObj, "schema");
341
+ if (isObject(schema)) return schema;
342
+ }
198
343
  for (const [mediaType, mediaObj] of Object.entries(content)) {
199
344
  if (!isJsonSuffixMediaType(mediaType)) continue;
200
345
  if (!isObject(mediaObj)) continue;
@@ -208,16 +353,24 @@ function extractSchemaFromContent(content) {
208
353
  }
209
354
  }
210
355
  /**
356
+ * Return the lowercased media-type base — the type/subtype with any
357
+ * RFC 7231 parameters (`; charset=...`, `; profile=...`, etc.) stripped
358
+ * and surrounding whitespace trimmed. Returns the empty string when the
359
+ * input has no recognisable base (defensive against malformed entries).
360
+ */
361
+ function mediaTypeBase(mediaType) {
362
+ return mediaType.toLowerCase().split(";", 1)[0]?.trim() ?? "";
363
+ }
364
+ /**
211
365
  * Detect RFC 6839 structured-syntax-suffix media types that encode JSON.
212
366
  * Matches `application/<anything>+json`, optionally with parameters
213
367
  * (`; charset=utf-8`). Excludes the literal `application/json`, which
214
368
  * the caller checks separately to preserve preference order.
215
369
  */
216
370
  function isJsonSuffixMediaType(mediaType) {
217
- const lower = mediaType.toLowerCase();
218
- if (lower === "application/json") return false;
219
- const baseType = lower.split(";", 1)[0]?.trim() ?? "";
220
- return baseType.startsWith("application/") && baseType.endsWith("+json");
371
+ const base = mediaTypeBase(mediaType);
372
+ if (base === "application/json") return false;
373
+ return base.startsWith("application/") && base.endsWith("+json");
221
374
  }
222
375
  /**
223
376
  * Resolve an in-document `$ref` against the supplied doc root.
@@ -280,14 +433,13 @@ function getSecuritySchemes(parsed) {
280
433
  }
281
434
  return result;
282
435
  }
283
- function getResponseHeaders(response, doc) {
436
+ function getResponseHeaders(response, doc, diagnostics) {
284
437
  const result = /* @__PURE__ */ new Map();
285
438
  const headers = getProperty(response, "headers");
286
439
  if (!isObject(headers)) return result;
287
440
  for (const [name, headerObj] of Object.entries(headers)) {
288
441
  if (!isObject(headerObj)) continue;
289
- const ref = getString(headerObj, "$ref");
290
- const header = (ref !== void 0 && doc !== void 0 ? resolveRefInDoc(doc, ref) : void 0) ?? headerObj;
442
+ const header = doc !== void 0 ? resolveReferenceObjectChain(doc, headerObj, "header", diagnostics) ?? headerObj : headerObj;
291
443
  const schemaProp = getProperty(header, "schema");
292
444
  result.set(name, {
293
445
  name,
@@ -299,14 +451,15 @@ function getResponseHeaders(response, doc) {
299
451
  }
300
452
  return result;
301
453
  }
302
- function listWebhooks(parsed) {
454
+ function listWebhooks(parsed, diagnostics) {
303
455
  const result = [];
304
456
  const webhooks = getProperty(parsed.doc, "webhooks");
305
457
  if (!isObject(webhooks)) return result;
306
- for (const [name, hookItem] of Object.entries(webhooks)) {
307
- if (!isObject(hookItem)) continue;
458
+ for (const [name, rawHookItem] of Object.entries(webhooks)) {
459
+ const hookItem = resolvePathItem(parsed, rawHookItem, diagnostics);
460
+ if (hookItem === void 0) continue;
308
461
  const operations = [];
309
- for (const method of METHODS) {
462
+ for (const method of HTTP_METHODS) {
310
463
  const operation = getProperty(hookItem, method);
311
464
  if (!isObject(operation)) continue;
312
465
  operations.push({
@@ -347,7 +500,7 @@ function getXmlInfo(schema) {
347
500
  wrapped: getProperty(xml, "wrapped") === true
348
501
  };
349
502
  }
350
- function listCallbacks(parsed, path, method) {
503
+ function listCallbacks(parsed, path, method, diagnostics) {
351
504
  const operation = getProperty(lookupPathItem(parsed, path), method);
352
505
  if (!isObject(operation)) return [];
353
506
  const callbacks = getProperty(operation, "callbacks");
@@ -356,21 +509,20 @@ function listCallbacks(parsed, path, method) {
356
509
  for (const [name, callbackItem] of Object.entries(callbacks)) {
357
510
  if (!isObject(callbackItem)) continue;
358
511
  const operations = [];
359
- for (const [cbPath, cbPathItem] of Object.entries(callbackItem)) {
360
- if (!isObject(cbPathItem)) continue;
361
- for (const cbMethod of METHODS) {
512
+ for (const [cbPath, rawCbPathItem] of Object.entries(callbackItem)) {
513
+ const cbPathItem = resolvePathItem(parsed, rawCbPathItem, diagnostics);
514
+ if (cbPathItem === void 0) continue;
515
+ for (const cbMethod of HTTP_METHODS) {
362
516
  const cbOp = getProperty(cbPathItem, cbMethod);
363
517
  if (!isObject(cbOp)) continue;
364
- const ref = getString(cbOp, "$ref");
365
- const resolved = ref !== void 0 ? resolveRefInDoc(parsed.doc, ref) ?? cbOp : cbOp;
366
518
  operations.push({
367
519
  path: `${name}/${cbPath}`,
368
520
  method: cbMethod,
369
- operationId: getString(resolved, "operationId"),
370
- summary: getString(resolved, "summary"),
371
- description: getString(resolved, "description"),
372
- deprecated: getProperty(resolved, "deprecated") === true,
373
- operation: isObject(resolved) ? resolved : cbOp
521
+ operationId: getString(cbOp, "operationId"),
522
+ summary: getString(cbOp, "summary"),
523
+ description: getString(cbOp, "description"),
524
+ deprecated: getProperty(cbOp, "deprecated") === true,
525
+ operation: cbOp
374
526
  });
375
527
  }
376
528
  }
@@ -381,7 +533,7 @@ function listCallbacks(parsed, path, method) {
381
533
  }
382
534
  return result;
383
535
  }
384
- function getLinks(parsed, path, method, statusCode) {
536
+ function getLinks(parsed, path, method, statusCode, diagnostics) {
385
537
  const response = getProperty(getProperty(getProperty(lookupPathItem(parsed, path), method), "responses"), statusCode);
386
538
  if (!isObject(response)) return [];
387
539
  const links = getProperty(response, "links");
@@ -389,9 +541,7 @@ function getLinks(parsed, path, method, statusCode) {
389
541
  const result = [];
390
542
  for (const [name, linkObj] of Object.entries(links)) {
391
543
  if (!isObject(linkObj)) continue;
392
- const ref = getString(linkObj, "$ref");
393
- const resolved = ref !== void 0 ? resolveRefInDoc(parsed.doc, ref) ?? linkObj : linkObj;
394
- const link = isObject(resolved) ? resolved : linkObj;
544
+ const link = resolveReferenceObjectChain(parsed.doc, linkObj, "link", diagnostics) ?? linkObj;
395
545
  const params = getProperty(link, "parameters");
396
546
  const paramMap = /* @__PURE__ */ new Map();
397
547
  if (isObject(params)) {
@@ -1,4 +1,4 @@
1
- import { i as DiagnosticsOptions } from "../diagnostics-D0QCYGv0.mjs";
1
+ import { i as DiagnosticsOptions } from "../diagnostics-BS2kaUyE.mjs";
2
2
  import { OpenApiDocument, OperationInfo, ParameterInfo, ResponseInfo, getRequestBody } from "./parser.mjs";
3
3
 
4
4
  //#region src/openapi/resolve.d.ts
@@ -15,17 +15,26 @@ import { OpenApiDocument, OperationInfo, ParameterInfo, ResponseInfo, getRequest
15
15
  * same form `<SchemaComponent>` does, keeping the OpenAPI components on
16
16
  * the same pipeline as the top-level adapter.
17
17
  *
18
- * When `diagnostics` is supplied, normalisation events
19
- * (`duplicate-body-parameter`, `dropped-swagger-feature`,
20
- * `unknown-json-schema-dialect`, `divisible-by-conflict`,
21
- * `relative-ref-resolved`, etc.) are forwarded to the sink. Passing
22
- * diagnostics also bypasses the cache so each call observes the
23
- * normalisation pipeline running against the supplied sink — caching
24
- * would silently swallow every emission after the first.
18
+ * ### Caching and diagnostics
25
19
  *
26
- * The cache is keyed by the caller-supplied document so subsequent
27
- * cache-eligible calls with the same input bypass both normalisation
28
- * and parsing.
20
+ * Normalisation runs at most once per document identity. The full set
21
+ * of doc-level diagnostics emitted during that single run is captured
22
+ * into the cache alongside the parsed result. Each caller-supplied
23
+ * sink receives the captured diagnostics exactly once per cached
24
+ * entry, no matter how many times `getParsed` is called with that
25
+ * `(doc, sink)` pair.
26
+ *
27
+ * The previous implementation bypassed the cache whenever
28
+ * `diagnostics` was supplied and re-ran the entire normalisation
29
+ * pipeline against the new sink. That fired every doc-level
30
+ * diagnostic once per call, so a parent like `ApiWebhooks` that
31
+ * renders `ApiWebhook` per webhook entry caused N-fold emission of a
32
+ * single real cause. With the new strategy, cardinality stays at one
33
+ * per real cause regardless of how many child renders share the
34
+ * sink.
35
+ *
36
+ * Strict mode is treated as a per-call invariant — see
37
+ * {@link replayCapturedDiagnostics} for the rationale.
29
38
  */
30
39
  declare function getParsed(doc: Record<string, unknown>, diagnostics?: DiagnosticsOptions): OpenApiDocument;
31
40
  /**