@skmtc/core 0.35.1 → 0.35.2

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 (47) hide show
  1. package/esm/context/StackTrail.js +3 -13
  2. package/esm/context/documentTrail.d.ts +17 -0
  3. package/esm/context/documentTrail.js +28 -0
  4. package/esm/parse/pathParameters.d.ts +57 -0
  5. package/esm/parse/pathParameters.js +138 -0
  6. package/esm/parse/v3-0/operation/toOperationsV3.js +7 -1
  7. package/esm/parse/v3-0/parameter/toParameterV3.d.ts +7 -0
  8. package/esm/parse/v3-0/parameter/toParameterV3.js +19 -11
  9. package/esm/parse/v3-0/pathItem/toPathItemV3.d.ts +7 -1
  10. package/esm/parse/v3-0/pathItem/toPathItemV3.js +5 -3
  11. package/esm/parse/v3-0/webhook/toWebhooksV3.js +7 -1
  12. package/esm/parse/v3-1/operation/toOperationsV3.js +7 -1
  13. package/esm/parse/v3-1/parameter/toParameterV3.d.ts +7 -0
  14. package/esm/parse/v3-1/parameter/toParameterV3.js +19 -11
  15. package/esm/parse/v3-1/pathItem/toPathItemV3.d.ts +7 -1
  16. package/esm/parse/v3-1/pathItem/toPathItemV3.js +5 -3
  17. package/esm/parse/v3-1/webhook/toWebhooksV3.js +7 -1
  18. package/esm/parse/v3-2/operation/toOperationsV3.js +11 -10
  19. package/esm/parse/v3-2/parameter/toParameterV3.d.ts +7 -0
  20. package/esm/parse/v3-2/parameter/toParameterV3.js +30 -24
  21. package/esm/parse/v3-2/pathItem/toPathItemV3.d.ts +6 -13
  22. package/esm/parse/v3-2/pathItem/toPathItemV3.js +5 -30
  23. package/esm/parse/v3-2/webhook/toWebhooksV3.js +11 -10
  24. package/package.json +1 -1
  25. package/script/context/StackTrail.js +3 -13
  26. package/script/context/documentTrail.d.ts +17 -0
  27. package/script/context/documentTrail.js +34 -0
  28. package/script/parse/pathParameters.d.ts +57 -0
  29. package/script/parse/pathParameters.js +144 -0
  30. package/script/parse/v3-0/operation/toOperationsV3.js +7 -1
  31. package/script/parse/v3-0/parameter/toParameterV3.d.ts +7 -0
  32. package/script/parse/v3-0/parameter/toParameterV3.js +22 -13
  33. package/script/parse/v3-0/pathItem/toPathItemV3.d.ts +7 -1
  34. package/script/parse/v3-0/pathItem/toPathItemV3.js +4 -2
  35. package/script/parse/v3-0/webhook/toWebhooksV3.js +7 -1
  36. package/script/parse/v3-1/operation/toOperationsV3.js +7 -1
  37. package/script/parse/v3-1/parameter/toParameterV3.d.ts +7 -0
  38. package/script/parse/v3-1/parameter/toParameterV3.js +22 -13
  39. package/script/parse/v3-1/pathItem/toPathItemV3.d.ts +7 -1
  40. package/script/parse/v3-1/pathItem/toPathItemV3.js +4 -2
  41. package/script/parse/v3-1/webhook/toWebhooksV3.js +7 -1
  42. package/script/parse/v3-2/operation/toOperationsV3.js +10 -9
  43. package/script/parse/v3-2/parameter/toParameterV3.d.ts +7 -0
  44. package/script/parse/v3-2/parameter/toParameterV3.js +33 -26
  45. package/script/parse/v3-2/pathItem/toPathItemV3.d.ts +6 -13
  46. package/script/parse/v3-2/pathItem/toPathItemV3.js +5 -31
  47. package/script/parse/v3-2/webhook/toWebhooksV3.js +10 -9
@@ -13,6 +13,7 @@ var _StackTrail_stack;
13
13
  import "../_dnt.polyfills.js";
14
14
  import { componentsKeys } from '../oas/components/Components.js';
15
15
  import { toJsonPointer } from '../types/JsonPointer.js';
16
+ import { toDocumentFrames, toTrailString } from './documentTrail.js';
16
17
  export class StackTrail {
17
18
  constructor(stack = []) {
18
19
  /** Internal stack of traversal frames */
@@ -211,15 +212,7 @@ export class StackTrail {
211
212
  * ```
212
213
  */
213
214
  toSchemaPointer() {
214
- // Phase frames seeded by `CoreContext.toArtifacts` (PhaseType plus the
215
- // `post-pass` trace). The operational phase always sits before any
216
- // document key, so the FIRST match is the boundary — a document key
217
- // that happens to share a phase name (e.g. a schema literally named
218
- // `parse`) appears later and is unaffected.
219
- const phaseFrames = new Set(['parse', 'generate', 'render', 'post-pass']);
220
- const phaseIndex = __classPrivateFieldGet(this, _StackTrail_stack, "f").findIndex(frame => phaseFrames.has(frame));
221
- const documentFrames = phaseIndex === -1 ? __classPrivateFieldGet(this, _StackTrail_stack, "f") : __classPrivateFieldGet(this, _StackTrail_stack, "f").slice(phaseIndex + 1);
222
- return toJsonPointer(documentFrames);
215
+ return toJsonPointer(toDocumentFrames(__classPrivateFieldGet(this, _StackTrail_stack, "f")));
223
216
  }
224
217
  toStackRef() {
225
218
  const [first, second, third] = this.stackTrail;
@@ -305,9 +298,7 @@ export class StackTrail {
305
298
  * ```
306
299
  */
307
300
  toString() {
308
- return __classPrivateFieldGet(this, _StackTrail_stack, "f")
309
- .map(frame => frame.replace(/[%:]/g, character => escapes[character]))
310
- .join(':');
301
+ return toTrailString(__classPrivateFieldGet(this, _StackTrail_stack, "f"));
311
302
  }
312
303
  /**
313
304
  * Reads a string written by {@link StackTrail.toString} back into a trail.
@@ -330,5 +321,4 @@ export class StackTrail {
330
321
  }
331
322
  }
332
323
  _StackTrail_stack = new WeakMap();
333
- const escapes = { '%': '%25', ':': '%3A' };
334
324
  const decodes = { '25': '%', '3A': ':' };
@@ -0,0 +1,17 @@
1
+ /** Joins trail frames with `:`, escaping `%` as `%25` and `:` as `%3A` inside a frame. */
2
+ export declare const toTrailString: (frames: string[]) => string;
3
+ /**
4
+ * The frames of a trail that address the input document: everything after
5
+ * the first phase frame, or every frame when there is no phase frame.
6
+ */
7
+ export declare const toDocumentFrames: (frames: string[]) => string[];
8
+ /**
9
+ * The document-relative trail in `StackTrail.toString` form.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * toDocumentString(['trace-1', 'span-1', 'parse', 'paths', '/pets', 'parameters', '0'])
14
+ * // 'paths:/pets:parameters:0'
15
+ * ```
16
+ */
17
+ export declare const toDocumentString: (frames: string[]) => string;
@@ -0,0 +1,28 @@
1
+ const escapes = { '%': '%25', ':': '%3A' };
2
+ // Phase frames seeded by `CoreContext.toArtifacts` (PhaseType plus the
3
+ // `post-pass` trace).
4
+ const phaseFrames = new Set(['parse', 'generate', 'render', 'post-pass']);
5
+ /** Joins trail frames with `:`, escaping `%` as `%25` and `:` as `%3A` inside a frame. */
6
+ export const toTrailString = (frames) => frames.map(frame => frame.replace(/[%:]/g, character => escapes[character])).join(':');
7
+ /**
8
+ * The frames of a trail that address the input document: everything after
9
+ * the first phase frame, or every frame when there is no phase frame.
10
+ */
11
+ export const toDocumentFrames = (frames) => {
12
+ // The operational phase always sits before any document key, so the
13
+ // FIRST match is the boundary — a document key that happens to share a
14
+ // phase name (e.g. a schema literally named `parse`) appears later and
15
+ // is unaffected.
16
+ const phaseIndex = frames.findIndex(frame => phaseFrames.has(frame));
17
+ return phaseIndex === -1 ? frames : frames.slice(phaseIndex + 1);
18
+ };
19
+ /**
20
+ * The document-relative trail in `StackTrail.toString` form.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * toDocumentString(['trace-1', 'span-1', 'parse', 'paths', '/pets', 'parameters', '0'])
25
+ * // 'paths:/pets:parameters:0'
26
+ * ```
27
+ */
28
+ export const toDocumentString = (frames) => toTrailString(toDocumentFrames(frames));
@@ -0,0 +1,57 @@
1
+ import type { ParseContextType } from '../context/parseTypes.js';
2
+ import type { StackTrail } from '../context/StackTrail.js';
3
+ /**
4
+ * Reads a `parameters` field. `undefined` is no parameters. `{}` or `null`
5
+ * is read as no parameters with an `EMPTY_PARAMETER` warning at the
6
+ * field. Any other value that is not an array throws.
7
+ */
8
+ export declare const toParameterEntries: <Entry>({ parameters, stackTrail, context }: {
9
+ parameters: Entry[] | undefined;
10
+ /** Trail that ends in `parameters`. */
11
+ stackTrail: StackTrail;
12
+ context: ParseContextType;
13
+ }) => Entry[] | undefined;
14
+ /** A path-level parameter entry, or the whole field, that failed to parse. */
15
+ export type BrokenPathParameter = {
16
+ /** Document-relative trail of the entry, or of the `parameters` field when it is not an array. */
17
+ location: string;
18
+ /** Set only when the raw entry has string `name` and `in`. */
19
+ name?: string;
20
+ in?: string;
21
+ message: string;
22
+ };
23
+ export type PathParameterList<Parameter> = {
24
+ parameters: Parameter[] | undefined;
25
+ broken: BrokenPathParameter[];
26
+ };
27
+ export type ToPathParameterListArgs<Entry, Parameter> = {
28
+ parameters: Entry[] | undefined;
29
+ /** Trail that ends in `parameters`. */
30
+ stackTrail: StackTrail;
31
+ context: ParseContextType;
32
+ /** The tree's parser for one list entry, as used by `toParameterListV3`. */
33
+ toEntry: (args: {
34
+ parameter: Entry;
35
+ index: number;
36
+ }) => Parameter[];
37
+ };
38
+ /**
39
+ * Parses a path item's `parameters` without letting a throw escape. Each
40
+ * entry that fails logs one `INVALID_PARAMETER` error at its index and is
41
+ * returned in `broken`; a field that is not an array logs one at the field.
42
+ * The caller decides per operation which broken entries apply.
43
+ */
44
+ export declare const toPathParameterList: <Entry, Parameter>({ parameters, stackTrail, context, toEntry }: ToPathParameterListArgs<Entry, Parameter>) => PathParameterList<Parameter>;
45
+ /**
46
+ * True when a broken path-level parameter applies to the operation. Logs
47
+ * one `INVALID_OPERATION` error at the operation that names the first
48
+ * such entry.
49
+ */
50
+ export declare const isDroppedByPathParameter: ({ brokenParameters, operation, stackTrail, context }: {
51
+ brokenParameters: BrokenPathParameter[];
52
+ /** The raw operation object. */
53
+ operation: unknown;
54
+ /** Trail that ends in the operation's method. */
55
+ stackTrail: StackTrail;
56
+ context: ParseContextType;
57
+ }) => boolean;
@@ -0,0 +1,138 @@
1
+ import { isEmptyParameter } from './emptyParameter.js';
2
+ import { toDocumentString } from '../context/documentTrail.js';
3
+ /**
4
+ * Reads a `parameters` field. `undefined` is no parameters. `{}` or `null`
5
+ * is read as no parameters with an `EMPTY_PARAMETER` warning at the
6
+ * field. Any other value that is not an array throws.
7
+ */
8
+ export const toParameterEntries = ({ parameters, stackTrail, context }) => {
9
+ if (parameters === undefined) {
10
+ return undefined;
11
+ }
12
+ if (Array.isArray(parameters)) {
13
+ return parameters;
14
+ }
15
+ if (isEmptyParameter(parameters)) {
16
+ context.logIssueNoKey({
17
+ stackTrail,
18
+ parent: parameters,
19
+ level: 'warning',
20
+ type: 'EMPTY_PARAMETER',
21
+ message: 'Empty parameters field; read as no parameters'
22
+ });
23
+ return undefined;
24
+ }
25
+ throw new Error(`Expected parameters to be an array but received ${typeof parameters}`);
26
+ };
27
+ const toError = (error) => error instanceof Error ? error : new Error(String(error));
28
+ const toNameAndIn = (parameter) => {
29
+ if (typeof parameter === 'object' &&
30
+ parameter !== null &&
31
+ 'name' in parameter &&
32
+ 'in' in parameter &&
33
+ typeof parameter.name === 'string' &&
34
+ typeof parameter.in === 'string') {
35
+ return { name: parameter.name, in: parameter.in };
36
+ }
37
+ return {};
38
+ };
39
+ /**
40
+ * Parses a path item's `parameters` without letting a throw escape. Each
41
+ * entry that fails logs one `INVALID_PARAMETER` error at its index and is
42
+ * returned in `broken`; a field that is not an array logs one at the field.
43
+ * The caller decides per operation which broken entries apply.
44
+ */
45
+ export const toPathParameterList = ({ parameters, stackTrail, context, toEntry }) => {
46
+ const logBroken = (st, parent, error) => {
47
+ const normalized = toError(error);
48
+ context.logIssueNoKey({
49
+ level: 'error',
50
+ stackTrail: st,
51
+ parent,
52
+ message: normalized.message,
53
+ cause: normalized,
54
+ type: 'INVALID_PARAMETER'
55
+ });
56
+ return { location: toDocumentString(st.stackTrail), message: normalized.message };
57
+ };
58
+ const readEntries = () => {
59
+ try {
60
+ return { entries: toParameterEntries({ parameters, stackTrail, context }) };
61
+ }
62
+ catch (error) {
63
+ // A field that is not an array cannot be matched to an override.
64
+ return { broken: logBroken(stackTrail, parameters, error) };
65
+ }
66
+ };
67
+ const read = readEntries();
68
+ if ('broken' in read) {
69
+ return { parameters: undefined, broken: [read.broken] };
70
+ }
71
+ if (read.entries === undefined) {
72
+ return { parameters: undefined, broken: [] };
73
+ }
74
+ const results = read.entries.map((parameter, index) => {
75
+ try {
76
+ return { parsed: toEntry({ parameter, index }), broken: [] };
77
+ }
78
+ catch (error) {
79
+ return {
80
+ parsed: [],
81
+ broken: [
82
+ {
83
+ ...stackTrail.trace(`${index}`, st => logBroken(st, parameter, error)),
84
+ ...toNameAndIn(parameter)
85
+ }
86
+ ]
87
+ };
88
+ }
89
+ });
90
+ return {
91
+ parameters: results.flatMap(({ parsed }) => parsed),
92
+ broken: results.flatMap(({ broken }) => broken)
93
+ };
94
+ };
95
+ /**
96
+ * The first broken path-level parameter that applies to an operation. An
97
+ * entry applies unless it has a readable `name` and `in` and the
98
+ * operation's inline `parameters` hold the same pair, which overrides it.
99
+ * A `$ref` operation parameter cannot be resolved during parse, so it
100
+ * overrides nothing.
101
+ */
102
+ const toApplyingBrokenParameter = ({ broken, operation }) => {
103
+ if (broken.length === 0) {
104
+ return undefined;
105
+ }
106
+ const operationParameters = typeof operation === 'object' &&
107
+ operation !== null &&
108
+ 'parameters' in operation &&
109
+ Array.isArray(operation.parameters)
110
+ ? operation.parameters
111
+ : [];
112
+ const overrides = new Set(operationParameters.flatMap((parameter) => {
113
+ const { name, in: parameterIn } = toNameAndIn(parameter);
114
+ return name === undefined || parameterIn === undefined ? [] : [`${parameterIn}:${name}`];
115
+ }));
116
+ return broken.find(entry => entry.name === undefined ||
117
+ entry.in === undefined ||
118
+ !overrides.has(`${entry.in}:${entry.name}`));
119
+ };
120
+ /**
121
+ * True when a broken path-level parameter applies to the operation. Logs
122
+ * one `INVALID_OPERATION` error at the operation that names the first
123
+ * such entry.
124
+ */
125
+ export const isDroppedByPathParameter = ({ brokenParameters, operation, stackTrail, context }) => {
126
+ const broken = toApplyingBrokenParameter({ broken: brokenParameters, operation });
127
+ if (!broken) {
128
+ return false;
129
+ }
130
+ context.logIssueNoKey({
131
+ parent: operation,
132
+ level: 'error',
133
+ message: `Path-level parameter ${broken.location} failed to parse: ${broken.message}`,
134
+ stackTrail,
135
+ type: 'INVALID_OPERATION'
136
+ });
137
+ return true;
138
+ };
@@ -9,6 +9,7 @@ import { toSecurityRequirementsV3 } from '../securityRequirement/toSecurityRequi
9
9
  import { isEmpty } from '../../../helpers/isEmpty.js';
10
10
  import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
11
11
  import { toOptionalServersV3 } from '../server/toServerV3.js';
12
+ import { isDroppedByPathParameter } from '../../pathParameters.js';
12
13
  export const toOperationV3 = ({ operation, operationInfo, stackTrail, context }) => {
13
14
  const { method, path, pathItem } = operationInfo;
14
15
  const { operationId, tags, summary, description, parameters, requestBody, responses, deprecated, security, externalDocs, servers,
@@ -70,9 +71,11 @@ export const toOperationsV3 = ({ paths, stackTrail, context }) => {
70
71
  rest: pathItem,
71
72
  methodObject: {}
72
73
  });
73
- const pathItemObject = !isEmpty(cleaned.rest)
74
+ const pathItemResult = !isEmpty(cleaned.rest)
74
75
  ? toPathItemV3({ pathItem: cleaned.rest, stackTrail: pathStack, context })
75
76
  : undefined;
77
+ const pathItemObject = pathItemResult?.pathItem;
78
+ const brokenParameters = pathItemResult?.brokenParameters ?? [];
76
79
  return Object.entries(cleaned.methodObject)
77
80
  .map(([method, operation]) => {
78
81
  // Use `pathStack` (the trail with `path` already pushed),
@@ -84,6 +87,9 @@ export const toOperationsV3 = ({ paths, stackTrail, context }) => {
84
87
  if (!operation) {
85
88
  return;
86
89
  }
90
+ if (isDroppedByPathParameter({ brokenParameters, operation, stackTrail: st, context })) {
91
+ return undefined;
92
+ }
87
93
  try {
88
94
  return toOperationV3({
89
95
  operation,
@@ -4,6 +4,7 @@ import type { OpenAPIV3 } from 'openapi-types';
4
4
  import { OasParameter } from '../../../oas/parameter/Parameter.js';
5
5
  import type { OasRef } from '../../../oas/ref/Ref.js';
6
6
  import type { StackTrail } from '../../../context/StackTrail.js';
7
+ import { type PathParameterList } from '../../pathParameters.js';
7
8
  type ParameterLocation = Exclude<OasParameterLocation, 'querystring'>;
8
9
  type ParameterStyle = Exclude<OasParameterStyle, 'cookie'>;
9
10
  export type ToParameterListV3Args = {
@@ -12,6 +13,12 @@ export type ToParameterListV3Args = {
12
13
  context: ParseContextType;
13
14
  };
14
15
  export declare const toParameterListV3: ({ parameters, stackTrail, context }: ToParameterListV3Args) => (OasParameter | OasRef<"parameter">)[] | undefined;
16
+ /**
17
+ * Path-level `parameters`: like {@link toParameterListV3}, but an entry
18
+ * that fails to parse is logged and returned in `broken` instead of
19
+ * throwing.
20
+ */
21
+ export declare const toPathParameterListV3: ({ parameters, stackTrail, context }: ToParameterListV3Args) => PathParameterList<OasParameter | OasRef<"parameter">>;
15
22
  export type ToParametersV3Args = {
16
23
  parameters: Record<string, OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject>;
17
24
  stackTrail: StackTrail;
@@ -8,6 +8,7 @@ import { OasParameter } from '../../../oas/parameter/Parameter.js';
8
8
  import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
9
9
  import * as v from 'valibot';
10
10
  import { isEmptyParameter, logEmptyParameter } from '../../emptyParameter.js';
11
+ import { toParameterEntries, toPathParameterList } from '../../pathParameters.js';
11
12
  const parameterLocation = v.enum({
12
13
  query: 'query',
13
14
  header: 'header',
@@ -23,18 +24,25 @@ const parameterStyle = v.enum({
23
24
  pipeDelimited: 'pipeDelimited',
24
25
  deepObject: 'deepObject'
25
26
  });
26
- export const toParameterListV3 = ({ parameters, stackTrail, context }) => {
27
- if (!parameters) {
28
- return undefined;
27
+ export const toParameterListV3 = ({ parameters, stackTrail, context }) => toParameterEntries({ parameters, stackTrail, context })?.flatMap((parameter, index) => toParameterEntryV3({ parameter, index, stackTrail, context }));
28
+ /**
29
+ * Path-level `parameters`: like {@link toParameterListV3}, but an entry
30
+ * that fails to parse is logged and returned in `broken` instead of
31
+ * throwing.
32
+ */
33
+ export const toPathParameterListV3 = ({ parameters, stackTrail, context }) => toPathParameterList({
34
+ parameters,
35
+ stackTrail,
36
+ context,
37
+ toEntry: ({ parameter, index }) => toParameterEntryV3({ parameter, index, stackTrail, context })
38
+ });
39
+ const toParameterEntryV3 = ({ parameter, index, stackTrail, context }) => stackTrail.trace(`${index}`, st => {
40
+ if (isEmptyParameter(parameter)) {
41
+ logEmptyParameter({ parameter, stackTrail: st, context });
42
+ return [];
29
43
  }
30
- return parameters.flatMap((parameter, index) => stackTrail.trace(`${index}`, st => {
31
- if (isEmptyParameter(parameter)) {
32
- logEmptyParameter({ parameter, stackTrail: st, context });
33
- return [];
34
- }
35
- return [toParameterV3({ parameter, stackTrail: st, context })];
36
- }));
37
- };
44
+ return [toParameterV3({ parameter, stackTrail: st, context })];
45
+ });
38
46
  export const toParametersV3 = ({ parameters, stackTrail, context }) => {
39
47
  const output = {};
40
48
  const entries = Object.entries(parameters);
@@ -1,5 +1,6 @@
1
1
  import type { OpenAPIV3 } from 'openapi-types';
2
2
  import type { ParseContextType } from '../../../context/parseTypes.js';
3
+ import type { BrokenPathParameter } from '../../pathParameters.js';
3
4
  import { OasPathItem } from '../../../oas/pathItem/PathItem.js';
4
5
  import type { StackTrail } from '../../../context/StackTrail.js';
5
6
  export type ToPathItemV3Args = {
@@ -7,4 +8,9 @@ export type ToPathItemV3Args = {
7
8
  stackTrail: StackTrail;
8
9
  context: ParseContextType;
9
10
  };
10
- export declare const toPathItemV3: ({ pathItem, stackTrail, context }: ToPathItemV3Args) => OasPathItem;
11
+ export type PathItemV3 = {
12
+ pathItem: OasPathItem;
13
+ /** Path-level parameters that failed to parse; the caller drops each operation they apply to. */
14
+ brokenParameters: BrokenPathParameter[];
15
+ };
16
+ export declare const toPathItemV3: ({ pathItem, stackTrail, context }: ToPathItemV3Args) => PathItemV3;
@@ -1,14 +1,15 @@
1
- import { toParameterListV3 } from '../parameter/toParameterV3.js';
1
+ import { toPathParameterListV3 } from '../parameter/toParameterV3.js';
2
2
  import { OasPathItem } from '../../../oas/pathItem/PathItem.js';
3
3
  import { toOptionalServersV3 } from '../server/toServerV3.js';
4
4
  import { tryParseAt } from '../../../context/tryParseAt.js';
5
5
  import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
6
6
  export const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
7
7
  const { summary, description, parameters, servers, ...skipped } = pathItem;
8
- return new OasPathItem({
8
+ const pathParameters = stackTrail.trace('parameters', st => toPathParameterListV3({ parameters, stackTrail: st, context }));
9
+ const oasPathItem = new OasPathItem({
9
10
  summary,
10
11
  description,
11
- parameters: stackTrail.trace('parameters', st => toParameterListV3({ parameters, stackTrail: st, context })),
12
+ parameters: pathParameters.parameters,
12
13
  servers: tryParseAt({
13
14
  stackTrail,
14
15
  key: 'servers',
@@ -25,4 +26,5 @@ export const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
25
26
  parentType: 'pathItem'
26
27
  })
27
28
  });
29
+ return { pathItem: oasPathItem, brokenParameters: pathParameters.broken };
28
30
  };
@@ -9,6 +9,7 @@ import { toSecurityRequirementsV3 } from '../securityRequirement/toSecurityRequi
9
9
  import { isEmpty } from '../../../helpers/isEmpty.js';
10
10
  import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
11
11
  import { toOptionalServersV3 } from '../server/toServerV3.js';
12
+ import { isDroppedByPathParameter } from '../../pathParameters.js';
12
13
  /**
13
14
  * Parses a single webhook Operation Object into an {@link OasWebhook}.
14
15
  *
@@ -85,9 +86,11 @@ export const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
85
86
  rest: pathItem,
86
87
  methodObject: {}
87
88
  });
88
- const pathItemObject = !isEmpty(cleaned.rest)
89
+ const pathItemResult = !isEmpty(cleaned.rest)
89
90
  ? toPathItemV3({ pathItem: cleaned.rest, stackTrail: nameStack, context })
90
91
  : undefined;
92
+ const pathItemObject = pathItemResult?.pathItem;
93
+ const brokenParameters = pathItemResult?.brokenParameters ?? [];
91
94
  return Object.entries(cleaned.methodObject)
92
95
  .map(([method, operation]) => {
93
96
  // Use `nameStack` (the trail with the webhook name already
@@ -97,6 +100,9 @@ export const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
97
100
  if (!operation) {
98
101
  return;
99
102
  }
103
+ if (isDroppedByPathParameter({ brokenParameters, operation, stackTrail: st, context })) {
104
+ return undefined;
105
+ }
100
106
  try {
101
107
  return toWebhookV3({
102
108
  operation,
@@ -9,6 +9,7 @@ import { toSecurityRequirementsV3 } from '../securityRequirement/toSecurityRequi
9
9
  import { isEmpty } from '../../../helpers/isEmpty.js';
10
10
  import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
11
11
  import { toOptionalServersV3 } from '../server/toServerV3.js';
12
+ import { isDroppedByPathParameter } from '../../pathParameters.js';
12
13
  export const toOperationV3 = ({ operation, operationInfo, stackTrail, context }) => {
13
14
  const { method, path, pathItem } = operationInfo;
14
15
  const { operationId, tags, summary, description, parameters, requestBody, responses, deprecated, security, externalDocs, servers,
@@ -73,9 +74,11 @@ export const toOperationsV3 = ({ paths, stackTrail, context }) => {
73
74
  rest: pathItem,
74
75
  methodObject: {}
75
76
  });
76
- const pathItemObject = !isEmpty(cleaned.rest)
77
+ const pathItemResult = !isEmpty(cleaned.rest)
77
78
  ? toPathItemV3({ pathItem: cleaned.rest, stackTrail: pathStack, context })
78
79
  : undefined;
80
+ const pathItemObject = pathItemResult?.pathItem;
81
+ const brokenParameters = pathItemResult?.brokenParameters ?? [];
79
82
  return Object.entries(cleaned.methodObject)
80
83
  .map(([method, operation]) => {
81
84
  // Use `pathStack` (the trail with `path` already pushed),
@@ -87,6 +90,9 @@ export const toOperationsV3 = ({ paths, stackTrail, context }) => {
87
90
  if (!operation) {
88
91
  return;
89
92
  }
93
+ if (isDroppedByPathParameter({ brokenParameters, operation, stackTrail: st, context })) {
94
+ return undefined;
95
+ }
90
96
  try {
91
97
  return toOperationV3({
92
98
  operation,
@@ -4,6 +4,7 @@ import type { OpenAPIV3 } from 'openapi-types';
4
4
  import { OasParameter } from '../../../oas/parameter/Parameter.js';
5
5
  import type { OasRef } from '../../../oas/ref/Ref.js';
6
6
  import type { StackTrail } from '../../../context/StackTrail.js';
7
+ import { type PathParameterList } from '../../pathParameters.js';
7
8
  type ParameterLocation = Exclude<OasParameterLocation, 'querystring'>;
8
9
  type ParameterStyle = Exclude<OasParameterStyle, 'cookie'>;
9
10
  export type ToParameterListV3Args = {
@@ -12,6 +13,12 @@ export type ToParameterListV3Args = {
12
13
  context: ParseContextType;
13
14
  };
14
15
  export declare const toParameterListV3: ({ parameters, stackTrail, context }: ToParameterListV3Args) => (OasParameter | OasRef<"parameter">)[] | undefined;
16
+ /**
17
+ * Path-level `parameters`: like {@link toParameterListV3}, but an entry
18
+ * that fails to parse is logged and returned in `broken` instead of
19
+ * throwing.
20
+ */
21
+ export declare const toPathParameterListV3: ({ parameters, stackTrail, context }: ToParameterListV3Args) => PathParameterList<OasParameter | OasRef<"parameter">>;
15
22
  export type ToParametersV3Args = {
16
23
  parameters: Record<string, OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject>;
17
24
  stackTrail: StackTrail;
@@ -8,6 +8,7 @@ import { OasParameter } from '../../../oas/parameter/Parameter.js';
8
8
  import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
9
9
  import * as v from 'valibot';
10
10
  import { isEmptyParameter, logEmptyParameter } from '../../emptyParameter.js';
11
+ import { toParameterEntries, toPathParameterList } from '../../pathParameters.js';
11
12
  const parameterLocation = v.enum({
12
13
  query: 'query',
13
14
  header: 'header',
@@ -23,18 +24,25 @@ const parameterStyle = v.enum({
23
24
  pipeDelimited: 'pipeDelimited',
24
25
  deepObject: 'deepObject'
25
26
  });
26
- export const toParameterListV3 = ({ parameters, stackTrail, context }) => {
27
- if (!parameters) {
28
- return undefined;
27
+ export const toParameterListV3 = ({ parameters, stackTrail, context }) => toParameterEntries({ parameters, stackTrail, context })?.flatMap((parameter, index) => toParameterEntryV3({ parameter, index, stackTrail, context }));
28
+ /**
29
+ * Path-level `parameters`: like {@link toParameterListV3}, but an entry
30
+ * that fails to parse is logged and returned in `broken` instead of
31
+ * throwing.
32
+ */
33
+ export const toPathParameterListV3 = ({ parameters, stackTrail, context }) => toPathParameterList({
34
+ parameters,
35
+ stackTrail,
36
+ context,
37
+ toEntry: ({ parameter, index }) => toParameterEntryV3({ parameter, index, stackTrail, context })
38
+ });
39
+ const toParameterEntryV3 = ({ parameter, index, stackTrail, context }) => stackTrail.trace(`${index}`, st => {
40
+ if (isEmptyParameter(parameter)) {
41
+ logEmptyParameter({ parameter, stackTrail: st, context });
42
+ return [];
29
43
  }
30
- return parameters.flatMap((parameter, index) => stackTrail.trace(`${index}`, st => {
31
- if (isEmptyParameter(parameter)) {
32
- logEmptyParameter({ parameter, stackTrail: st, context });
33
- return [];
34
- }
35
- return [toParameterV3({ parameter, stackTrail: st, context })];
36
- }));
37
- };
44
+ return [toParameterV3({ parameter, stackTrail: st, context })];
45
+ });
38
46
  export const toParametersV3 = ({ parameters, stackTrail, context }) => {
39
47
  const output = {};
40
48
  const entries = Object.entries(parameters);
@@ -1,5 +1,6 @@
1
1
  import type { OpenAPIV3 } from 'openapi-types';
2
2
  import type { ParseContextType } from '../../../context/parseTypes.js';
3
+ import type { BrokenPathParameter } from '../../pathParameters.js';
3
4
  import { OasPathItem } from '../../../oas/pathItem/PathItem.js';
4
5
  import type { StackTrail } from '../../../context/StackTrail.js';
5
6
  export type ToPathItemV3Args = {
@@ -7,4 +8,9 @@ export type ToPathItemV3Args = {
7
8
  stackTrail: StackTrail;
8
9
  context: ParseContextType;
9
10
  };
10
- export declare const toPathItemV3: ({ pathItem, stackTrail, context }: ToPathItemV3Args) => OasPathItem;
11
+ export type PathItemV3 = {
12
+ pathItem: OasPathItem;
13
+ /** Path-level parameters that failed to parse; the caller drops each operation they apply to. */
14
+ brokenParameters: BrokenPathParameter[];
15
+ };
16
+ export declare const toPathItemV3: ({ pathItem, stackTrail, context }: ToPathItemV3Args) => PathItemV3;
@@ -1,14 +1,15 @@
1
- import { toParameterListV3 } from '../parameter/toParameterV3.js';
1
+ import { toPathParameterListV3 } from '../parameter/toParameterV3.js';
2
2
  import { OasPathItem } from '../../../oas/pathItem/PathItem.js';
3
3
  import { toOptionalServersV3 } from '../server/toServerV3.js';
4
4
  import { tryParseAt } from '../../../context/tryParseAt.js';
5
5
  import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
6
6
  export const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
7
7
  const { summary, description, parameters, servers, ...skipped } = pathItem;
8
- return new OasPathItem({
8
+ const pathParameters = stackTrail.trace('parameters', st => toPathParameterListV3({ parameters, stackTrail: st, context }));
9
+ const oasPathItem = new OasPathItem({
9
10
  summary,
10
11
  description,
11
- parameters: stackTrail.trace('parameters', st => toParameterListV3({ parameters, stackTrail: st, context })),
12
+ parameters: pathParameters.parameters,
12
13
  servers: tryParseAt({
13
14
  stackTrail,
14
15
  key: 'servers',
@@ -25,4 +26,5 @@ export const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
25
26
  parentType: 'pathItem'
26
27
  })
27
28
  });
29
+ return { pathItem: oasPathItem, brokenParameters: pathParameters.broken };
28
30
  };
@@ -9,6 +9,7 @@ import { toSecurityRequirementsV3 } from '../securityRequirement/toSecurityRequi
9
9
  import { isEmpty } from '../../../helpers/isEmpty.js';
10
10
  import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
11
11
  import { toOptionalServersV3 } from '../server/toServerV3.js';
12
+ import { isDroppedByPathParameter } from '../../pathParameters.js';
12
13
  /**
13
14
  * Parses a single webhook Operation Object into an {@link OasWebhook}.
14
15
  *
@@ -85,9 +86,11 @@ export const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
85
86
  rest: pathItem,
86
87
  methodObject: {}
87
88
  });
88
- const pathItemObject = !isEmpty(cleaned.rest)
89
+ const pathItemResult = !isEmpty(cleaned.rest)
89
90
  ? toPathItemV3({ pathItem: cleaned.rest, stackTrail: nameStack, context })
90
91
  : undefined;
92
+ const pathItemObject = pathItemResult?.pathItem;
93
+ const brokenParameters = pathItemResult?.brokenParameters ?? [];
91
94
  return Object.entries(cleaned.methodObject)
92
95
  .map(([method, operation]) => {
93
96
  // Use `nameStack` (the trail with the webhook name already
@@ -97,6 +100,9 @@ export const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
97
100
  if (!operation) {
98
101
  return;
99
102
  }
103
+ if (isDroppedByPathParameter({ brokenParameters, operation, stackTrail: st, context })) {
104
+ return undefined;
105
+ }
100
106
  try {
101
107
  return toWebhookV3({
102
108
  operation,