@skmtc/core 0.35.0 → 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 (103) 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/_merge-all-of/merge-bounds.d.ts +7 -0
  7. package/esm/parse/v3-0/_merge-all-of/merge-bounds.js +46 -0
  8. package/esm/parse/v3-0/_merge-all-of/merge-integer-constraints.js +2 -20
  9. package/esm/parse/v3-0/_merge-all-of/merge-number-constraints.js +2 -20
  10. package/esm/parse/v3-0/operation/toOperationsV3.js +7 -1
  11. package/esm/parse/v3-0/parameter/toParameterV3.d.ts +7 -0
  12. package/esm/parse/v3-0/parameter/toParameterV3.js +19 -11
  13. package/esm/parse/v3-0/pathItem/toPathItemV3.d.ts +7 -1
  14. package/esm/parse/v3-0/pathItem/toPathItemV3.js +5 -3
  15. package/esm/parse/v3-0/webhook/toWebhooksV3.js +7 -1
  16. package/esm/parse/v3-1/_merge-all-of/decompose-union.d.ts +2 -0
  17. package/esm/parse/v3-1/_merge-all-of/decompose-union.js +3 -1
  18. package/esm/parse/v3-1/_merge-all-of/merge-bounds.d.ts +24 -0
  19. package/esm/parse/v3-1/_merge-all-of/merge-bounds.js +57 -0
  20. package/esm/parse/v3-1/_merge-all-of/merge-integer-constraints.js +2 -20
  21. package/esm/parse/v3-1/_merge-all-of/merge-number-constraints.js +2 -20
  22. package/esm/parse/v3-1/_merge-all-of/merge-union.d.ts +7 -0
  23. package/esm/parse/v3-1/_merge-all-of/merge-union.js +65 -7
  24. package/esm/parse/v3-1/_merge-all-of/merge.js +7 -3
  25. package/esm/parse/v3-1/array/toArray.js +4 -15
  26. package/esm/parse/v3-1/operation/toOperationsV3.js +7 -1
  27. package/esm/parse/v3-1/parameter/toParameterV3.d.ts +7 -0
  28. package/esm/parse/v3-1/parameter/toParameterV3.js +19 -11
  29. package/esm/parse/v3-1/pathItem/toPathItemV3.d.ts +7 -1
  30. package/esm/parse/v3-1/pathItem/toPathItemV3.js +5 -3
  31. package/esm/parse/v3-1/schema/normalize-schema-shape.js +10 -8
  32. package/esm/parse/v3-1/schema/toSchemasV3.js +7 -1
  33. package/esm/parse/v3-1/webhook/toWebhooksV3.js +7 -1
  34. package/esm/parse/v3-2/_merge-all-of/decompose-union.d.ts +2 -0
  35. package/esm/parse/v3-2/_merge-all-of/decompose-union.js +3 -1
  36. package/esm/parse/v3-2/_merge-all-of/merge-bounds.d.ts +24 -0
  37. package/esm/parse/v3-2/_merge-all-of/merge-bounds.js +57 -0
  38. package/esm/parse/v3-2/_merge-all-of/merge-integer-constraints.js +2 -20
  39. package/esm/parse/v3-2/_merge-all-of/merge-number-constraints.js +2 -20
  40. package/esm/parse/v3-2/_merge-all-of/merge-union.d.ts +7 -0
  41. package/esm/parse/v3-2/_merge-all-of/merge-union.js +65 -7
  42. package/esm/parse/v3-2/_merge-all-of/merge.js +7 -3
  43. package/esm/parse/v3-2/array/toArray.js +4 -15
  44. package/esm/parse/v3-2/operation/toOperationsV3.js +11 -10
  45. package/esm/parse/v3-2/parameter/toParameterV3.d.ts +7 -0
  46. package/esm/parse/v3-2/parameter/toParameterV3.js +30 -24
  47. package/esm/parse/v3-2/pathItem/toPathItemV3.d.ts +6 -13
  48. package/esm/parse/v3-2/pathItem/toPathItemV3.js +5 -30
  49. package/esm/parse/v3-2/schema/normalize-schema-shape.js +10 -8
  50. package/esm/parse/v3-2/schema/toSchemasV3.js +7 -1
  51. package/esm/parse/v3-2/webhook/toWebhooksV3.js +11 -10
  52. package/package.json +1 -1
  53. package/script/context/StackTrail.js +3 -13
  54. package/script/context/documentTrail.d.ts +17 -0
  55. package/script/context/documentTrail.js +34 -0
  56. package/script/parse/pathParameters.d.ts +57 -0
  57. package/script/parse/pathParameters.js +144 -0
  58. package/script/parse/v3-0/_merge-all-of/merge-bounds.d.ts +7 -0
  59. package/script/parse/v3-0/_merge-all-of/merge-bounds.js +50 -0
  60. package/script/parse/v3-0/_merge-all-of/merge-integer-constraints.js +2 -20
  61. package/script/parse/v3-0/_merge-all-of/merge-number-constraints.js +2 -20
  62. package/script/parse/v3-0/operation/toOperationsV3.js +7 -1
  63. package/script/parse/v3-0/parameter/toParameterV3.d.ts +7 -0
  64. package/script/parse/v3-0/parameter/toParameterV3.js +22 -13
  65. package/script/parse/v3-0/pathItem/toPathItemV3.d.ts +7 -1
  66. package/script/parse/v3-0/pathItem/toPathItemV3.js +4 -2
  67. package/script/parse/v3-0/webhook/toWebhooksV3.js +7 -1
  68. package/script/parse/v3-1/_merge-all-of/decompose-union.d.ts +2 -0
  69. package/script/parse/v3-1/_merge-all-of/decompose-union.js +5 -2
  70. package/script/parse/v3-1/_merge-all-of/merge-bounds.d.ts +24 -0
  71. package/script/parse/v3-1/_merge-all-of/merge-bounds.js +66 -0
  72. package/script/parse/v3-1/_merge-all-of/merge-integer-constraints.js +2 -20
  73. package/script/parse/v3-1/_merge-all-of/merge-number-constraints.js +2 -20
  74. package/script/parse/v3-1/_merge-all-of/merge-union.d.ts +7 -0
  75. package/script/parse/v3-1/_merge-all-of/merge-union.js +66 -7
  76. package/script/parse/v3-1/_merge-all-of/merge.js +6 -2
  77. package/script/parse/v3-1/array/toArray.js +4 -15
  78. package/script/parse/v3-1/operation/toOperationsV3.js +7 -1
  79. package/script/parse/v3-1/parameter/toParameterV3.d.ts +7 -0
  80. package/script/parse/v3-1/parameter/toParameterV3.js +22 -13
  81. package/script/parse/v3-1/pathItem/toPathItemV3.d.ts +7 -1
  82. package/script/parse/v3-1/pathItem/toPathItemV3.js +4 -2
  83. package/script/parse/v3-1/schema/normalize-schema-shape.js +10 -8
  84. package/script/parse/v3-1/schema/toSchemasV3.js +6 -0
  85. package/script/parse/v3-1/webhook/toWebhooksV3.js +7 -1
  86. package/script/parse/v3-2/_merge-all-of/decompose-union.d.ts +2 -0
  87. package/script/parse/v3-2/_merge-all-of/decompose-union.js +5 -2
  88. package/script/parse/v3-2/_merge-all-of/merge-bounds.d.ts +24 -0
  89. package/script/parse/v3-2/_merge-all-of/merge-bounds.js +66 -0
  90. package/script/parse/v3-2/_merge-all-of/merge-integer-constraints.js +2 -20
  91. package/script/parse/v3-2/_merge-all-of/merge-number-constraints.js +2 -20
  92. package/script/parse/v3-2/_merge-all-of/merge-union.d.ts +7 -0
  93. package/script/parse/v3-2/_merge-all-of/merge-union.js +66 -7
  94. package/script/parse/v3-2/_merge-all-of/merge.js +6 -2
  95. package/script/parse/v3-2/array/toArray.js +4 -15
  96. package/script/parse/v3-2/operation/toOperationsV3.js +10 -9
  97. package/script/parse/v3-2/parameter/toParameterV3.d.ts +7 -0
  98. package/script/parse/v3-2/parameter/toParameterV3.js +33 -26
  99. package/script/parse/v3-2/pathItem/toPathItemV3.d.ts +6 -13
  100. package/script/parse/v3-2/pathItem/toPathItemV3.js +5 -31
  101. package/script/parse/v3-2/schema/normalize-schema-shape.js +10 -8
  102. package/script/parse/v3-2/schema/toSchemasV3.js +6 -0
  103. package/script/parse/v3-2/webhook/toWebhooksV3.js +10 -9
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toDocumentString = exports.toDocumentFrames = exports.toTrailString = void 0;
4
+ const escapes = { '%': '%25', ':': '%3A' };
5
+ // Phase frames seeded by `CoreContext.toArtifacts` (PhaseType plus the
6
+ // `post-pass` trace).
7
+ const phaseFrames = new Set(['parse', 'generate', 'render', 'post-pass']);
8
+ /** Joins trail frames with `:`, escaping `%` as `%25` and `:` as `%3A` inside a frame. */
9
+ const toTrailString = (frames) => frames.map(frame => frame.replace(/[%:]/g, character => escapes[character])).join(':');
10
+ exports.toTrailString = toTrailString;
11
+ /**
12
+ * The frames of a trail that address the input document: everything after
13
+ * the first phase frame, or every frame when there is no phase frame.
14
+ */
15
+ const toDocumentFrames = (frames) => {
16
+ // The operational phase always sits before any document key, so the
17
+ // FIRST match is the boundary — a document key that happens to share a
18
+ // phase name (e.g. a schema literally named `parse`) appears later and
19
+ // is unaffected.
20
+ const phaseIndex = frames.findIndex(frame => phaseFrames.has(frame));
21
+ return phaseIndex === -1 ? frames : frames.slice(phaseIndex + 1);
22
+ };
23
+ exports.toDocumentFrames = toDocumentFrames;
24
+ /**
25
+ * The document-relative trail in `StackTrail.toString` form.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * toDocumentString(['trace-1', 'span-1', 'parse', 'paths', '/pets', 'parameters', '0'])
30
+ * // 'paths:/pets:parameters:0'
31
+ * ```
32
+ */
33
+ const toDocumentString = (frames) => (0, exports.toTrailString)((0, exports.toDocumentFrames)(frames));
34
+ exports.toDocumentString = toDocumentString;
@@ -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,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDroppedByPathParameter = exports.toPathParameterList = exports.toParameterEntries = void 0;
4
+ const emptyParameter_js_1 = require("./emptyParameter.js");
5
+ const documentTrail_js_1 = require("../context/documentTrail.js");
6
+ /**
7
+ * Reads a `parameters` field. `undefined` is no parameters. `{}` or `null`
8
+ * is read as no parameters with an `EMPTY_PARAMETER` warning at the
9
+ * field. Any other value that is not an array throws.
10
+ */
11
+ const toParameterEntries = ({ parameters, stackTrail, context }) => {
12
+ if (parameters === undefined) {
13
+ return undefined;
14
+ }
15
+ if (Array.isArray(parameters)) {
16
+ return parameters;
17
+ }
18
+ if ((0, emptyParameter_js_1.isEmptyParameter)(parameters)) {
19
+ context.logIssueNoKey({
20
+ stackTrail,
21
+ parent: parameters,
22
+ level: 'warning',
23
+ type: 'EMPTY_PARAMETER',
24
+ message: 'Empty parameters field; read as no parameters'
25
+ });
26
+ return undefined;
27
+ }
28
+ throw new Error(`Expected parameters to be an array but received ${typeof parameters}`);
29
+ };
30
+ exports.toParameterEntries = toParameterEntries;
31
+ const toError = (error) => error instanceof Error ? error : new Error(String(error));
32
+ const toNameAndIn = (parameter) => {
33
+ if (typeof parameter === 'object' &&
34
+ parameter !== null &&
35
+ 'name' in parameter &&
36
+ 'in' in parameter &&
37
+ typeof parameter.name === 'string' &&
38
+ typeof parameter.in === 'string') {
39
+ return { name: parameter.name, in: parameter.in };
40
+ }
41
+ return {};
42
+ };
43
+ /**
44
+ * Parses a path item's `parameters` without letting a throw escape. Each
45
+ * entry that fails logs one `INVALID_PARAMETER` error at its index and is
46
+ * returned in `broken`; a field that is not an array logs one at the field.
47
+ * The caller decides per operation which broken entries apply.
48
+ */
49
+ const toPathParameterList = ({ parameters, stackTrail, context, toEntry }) => {
50
+ const logBroken = (st, parent, error) => {
51
+ const normalized = toError(error);
52
+ context.logIssueNoKey({
53
+ level: 'error',
54
+ stackTrail: st,
55
+ parent,
56
+ message: normalized.message,
57
+ cause: normalized,
58
+ type: 'INVALID_PARAMETER'
59
+ });
60
+ return { location: (0, documentTrail_js_1.toDocumentString)(st.stackTrail), message: normalized.message };
61
+ };
62
+ const readEntries = () => {
63
+ try {
64
+ return { entries: (0, exports.toParameterEntries)({ parameters, stackTrail, context }) };
65
+ }
66
+ catch (error) {
67
+ // A field that is not an array cannot be matched to an override.
68
+ return { broken: logBroken(stackTrail, parameters, error) };
69
+ }
70
+ };
71
+ const read = readEntries();
72
+ if ('broken' in read) {
73
+ return { parameters: undefined, broken: [read.broken] };
74
+ }
75
+ if (read.entries === undefined) {
76
+ return { parameters: undefined, broken: [] };
77
+ }
78
+ const results = read.entries.map((parameter, index) => {
79
+ try {
80
+ return { parsed: toEntry({ parameter, index }), broken: [] };
81
+ }
82
+ catch (error) {
83
+ return {
84
+ parsed: [],
85
+ broken: [
86
+ {
87
+ ...stackTrail.trace(`${index}`, st => logBroken(st, parameter, error)),
88
+ ...toNameAndIn(parameter)
89
+ }
90
+ ]
91
+ };
92
+ }
93
+ });
94
+ return {
95
+ parameters: results.flatMap(({ parsed }) => parsed),
96
+ broken: results.flatMap(({ broken }) => broken)
97
+ };
98
+ };
99
+ exports.toPathParameterList = toPathParameterList;
100
+ /**
101
+ * The first broken path-level parameter that applies to an operation. An
102
+ * entry applies unless it has a readable `name` and `in` and the
103
+ * operation's inline `parameters` hold the same pair, which overrides it.
104
+ * A `$ref` operation parameter cannot be resolved during parse, so it
105
+ * overrides nothing.
106
+ */
107
+ const toApplyingBrokenParameter = ({ broken, operation }) => {
108
+ if (broken.length === 0) {
109
+ return undefined;
110
+ }
111
+ const operationParameters = typeof operation === 'object' &&
112
+ operation !== null &&
113
+ 'parameters' in operation &&
114
+ Array.isArray(operation.parameters)
115
+ ? operation.parameters
116
+ : [];
117
+ const overrides = new Set(operationParameters.flatMap((parameter) => {
118
+ const { name, in: parameterIn } = toNameAndIn(parameter);
119
+ return name === undefined || parameterIn === undefined ? [] : [`${parameterIn}:${name}`];
120
+ }));
121
+ return broken.find(entry => entry.name === undefined ||
122
+ entry.in === undefined ||
123
+ !overrides.has(`${entry.in}:${entry.name}`));
124
+ };
125
+ /**
126
+ * True when a broken path-level parameter applies to the operation. Logs
127
+ * one `INVALID_OPERATION` error at the operation that names the first
128
+ * such entry.
129
+ */
130
+ const isDroppedByPathParameter = ({ brokenParameters, operation, stackTrail, context }) => {
131
+ const broken = toApplyingBrokenParameter({ broken: brokenParameters, operation });
132
+ if (!broken) {
133
+ return false;
134
+ }
135
+ context.logIssueNoKey({
136
+ parent: operation,
137
+ level: 'error',
138
+ message: `Path-level parameter ${broken.location} failed to parse: ${broken.message}`,
139
+ stackTrail,
140
+ type: 'INVALID_OPERATION'
141
+ });
142
+ return true;
143
+ };
144
+ exports.isDroppedByPathParameter = isDroppedByPathParameter;
@@ -0,0 +1,7 @@
1
+ import type { SchemaObject } from './types.js';
2
+ /**
3
+ * Write the merged `minimum`/`exclusiveMinimum` and `maximum`/`exclusiveMaximum`
4
+ * of `first` and `second` onto `result`. Members are in the normalized form,
5
+ * where an exclusive bound is `minimum` plus `exclusiveMinimum: true`.
6
+ */
7
+ export declare const mergeBounds: (result: SchemaObject, first: SchemaObject, second: SchemaObject) => void;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeBounds = void 0;
4
+ /**
5
+ * Pick the tighter of two bounds. The tighter bound keeps its own
6
+ * exclusivity; when both bounds are equal, exclusive wins.
7
+ */
8
+ const toTighterBound = (first, second, isTighter) => {
9
+ if (first === undefined || second === undefined) {
10
+ return first ?? second;
11
+ }
12
+ if (first.value === second.value) {
13
+ return { value: first.value, exclusive: first.exclusive || second.exclusive };
14
+ }
15
+ return isTighter(first.value, second.value) ? first : second;
16
+ };
17
+ const toMinimum = (schema) => schema.minimum === undefined
18
+ ? undefined
19
+ : { value: schema.minimum, exclusive: schema.exclusiveMinimum === true };
20
+ const toMaximum = (schema) => schema.maximum === undefined
21
+ ? undefined
22
+ : { value: schema.maximum, exclusive: schema.exclusiveMaximum === true };
23
+ /**
24
+ * Write the merged `minimum`/`exclusiveMinimum` and `maximum`/`exclusiveMaximum`
25
+ * of `first` and `second` onto `result`. Members are in the normalized form,
26
+ * where an exclusive bound is `minimum` plus `exclusiveMinimum: true`.
27
+ */
28
+ const mergeBounds = (result, first, second) => {
29
+ const minimum = toTighterBound(toMinimum(first), toMinimum(second), (a, b) => a > b);
30
+ const maximum = toTighterBound(toMaximum(first), toMaximum(second), (a, b) => a < b);
31
+ if (minimum !== undefined) {
32
+ result.minimum = minimum.value;
33
+ if (minimum.exclusive) {
34
+ result.exclusiveMinimum = true;
35
+ }
36
+ else {
37
+ delete result.exclusiveMinimum;
38
+ }
39
+ }
40
+ if (maximum !== undefined) {
41
+ result.maximum = maximum.value;
42
+ if (maximum.exclusive) {
43
+ result.exclusiveMaximum = true;
44
+ }
45
+ else {
46
+ delete result.exclusiveMaximum;
47
+ }
48
+ }
49
+ };
50
+ exports.mergeBounds = mergeBounds;
@@ -37,32 +37,14 @@ exports.mergeIntegerConstraints = mergeIntegerConstraints;
37
37
  const generic_merge_js_1 = require("./generic-merge.js");
38
38
  const v = __importStar(require("valibot"));
39
39
  const check_type_conflicts_js_1 = require("./check-type-conflicts.js");
40
+ const merge_bounds_js_1 = require("./merge-bounds.js");
40
41
  function mergeIntegerConstraints(first, second, getRef) {
41
42
  (0, check_type_conflicts_js_1.checkTypeConflicts)(first, second);
42
43
  // First merge enum values if present
43
44
  const result = (0, generic_merge_js_1.genericMerge)(first, second, getRef, v.number());
44
45
  // Then merge other constraints
45
46
  result.type = 'integer';
46
- // Merge minimum and exclusiveMinimum
47
- if (first.minimum !== undefined || second.minimum !== undefined) {
48
- const minA = first.minimum ?? -Infinity;
49
- const minB = second.minimum ?? -Infinity;
50
- result.minimum = Math.max(minA, minB);
51
- // If either minimum is exclusive, the result is exclusive
52
- if (first.exclusiveMinimum || second.exclusiveMinimum) {
53
- result.exclusiveMinimum = true;
54
- }
55
- }
56
- // Merge maximum and exclusiveMaximum
57
- if (first.maximum !== undefined || second.maximum !== undefined) {
58
- const maxA = first.maximum ?? Infinity;
59
- const maxB = second.maximum ?? Infinity;
60
- result.maximum = Math.min(maxA, maxB);
61
- // If either maximum is exclusive, the result is exclusive
62
- if (first.exclusiveMaximum || second.exclusiveMaximum) {
63
- result.exclusiveMaximum = true;
64
- }
65
- }
47
+ (0, merge_bounds_js_1.mergeBounds)(result, first, second);
66
48
  // Merge multipleOf
67
49
  if (first.multipleOf !== undefined && second.multipleOf !== undefined) {
68
50
  result.multipleOf = first.multipleOf * second.multipleOf;
@@ -37,32 +37,14 @@ exports.mergeNumberConstraints = mergeNumberConstraints;
37
37
  const generic_merge_js_1 = require("./generic-merge.js");
38
38
  const v = __importStar(require("valibot"));
39
39
  const check_type_conflicts_js_1 = require("./check-type-conflicts.js");
40
+ const merge_bounds_js_1 = require("./merge-bounds.js");
40
41
  function mergeNumberConstraints(first, second, getRef) {
41
42
  (0, check_type_conflicts_js_1.checkTypeConflicts)(first, second);
42
43
  // First merge enum values if present
43
44
  const result = (0, generic_merge_js_1.genericMerge)(first, second, getRef, v.number());
44
45
  // Then merge other constraints
45
46
  result.type = 'number';
46
- // Merge minimum and exclusiveMinimum
47
- if (first.minimum !== undefined || second.minimum !== undefined) {
48
- const minA = first.minimum ?? -Infinity;
49
- const minB = second.minimum ?? -Infinity;
50
- result.minimum = Math.max(minA, minB);
51
- // If either minimum is exclusive, the result is exclusive
52
- if (first.exclusiveMinimum || second.exclusiveMinimum) {
53
- result.exclusiveMinimum = true;
54
- }
55
- }
56
- // Merge maximum and exclusiveMaximum
57
- if (first.maximum !== undefined || second.maximum !== undefined) {
58
- const maxA = first.maximum ?? Infinity;
59
- const maxB = second.maximum ?? Infinity;
60
- result.maximum = Math.min(maxA, maxB);
61
- // If either maximum is exclusive, the result is exclusive
62
- if (first.exclusiveMaximum || second.exclusiveMaximum) {
63
- result.exclusiveMaximum = true;
64
- }
65
- }
47
+ (0, merge_bounds_js_1.mergeBounds)(result, first, second);
66
48
  // Merge multipleOf
67
49
  if (first.multipleOf !== undefined && second.multipleOf !== undefined) {
68
50
  result.multipleOf = first.multipleOf * second.multipleOf;
@@ -12,6 +12,7 @@ const toSecurityRequirement_js_1 = require("../securityRequirement/toSecurityReq
12
12
  const isEmpty_js_1 = require("../../../helpers/isEmpty.js");
13
13
  const toExternalDocs_js_1 = require("../externalDocs/toExternalDocs.js");
14
14
  const toServerV3_js_1 = require("../server/toServerV3.js");
15
+ const pathParameters_js_1 = require("../../pathParameters.js");
15
16
  const toOperationV3 = ({ operation, operationInfo, stackTrail, context }) => {
16
17
  const { method, path, pathItem } = operationInfo;
17
18
  const { operationId, tags, summary, description, parameters, requestBody, responses, deprecated, security, externalDocs, servers,
@@ -74,9 +75,11 @@ const toOperationsV3 = ({ paths, stackTrail, context }) => {
74
75
  rest: pathItem,
75
76
  methodObject: {}
76
77
  });
77
- const pathItemObject = !(0, isEmpty_js_1.isEmpty)(cleaned.rest)
78
+ const pathItemResult = !(0, isEmpty_js_1.isEmpty)(cleaned.rest)
78
79
  ? (0, toPathItemV3_js_1.toPathItemV3)({ pathItem: cleaned.rest, stackTrail: pathStack, context })
79
80
  : undefined;
81
+ const pathItemObject = pathItemResult?.pathItem;
82
+ const brokenParameters = pathItemResult?.brokenParameters ?? [];
80
83
  return Object.entries(cleaned.methodObject)
81
84
  .map(([method, operation]) => {
82
85
  // Use `pathStack` (the trail with `path` already pushed),
@@ -88,6 +91,9 @@ const toOperationsV3 = ({ paths, stackTrail, context }) => {
88
91
  if (!operation) {
89
92
  return;
90
93
  }
94
+ if ((0, pathParameters_js_1.isDroppedByPathParameter)({ brokenParameters, operation, stackTrail: st, context })) {
95
+ return undefined;
96
+ }
91
97
  try {
92
98
  return (0, exports.toOperationV3)({
93
99
  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;
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.toOptionalParametersV3 = exports.toParametersV3 = exports.toParameterListV3 = void 0;
36
+ exports.toOptionalParametersV3 = exports.toParametersV3 = exports.toPathParameterListV3 = exports.toParameterListV3 = void 0;
37
37
  const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
38
38
  const refFns_js_1 = require("../../../helpers/refFns.js");
39
39
  const toExamplesV3_js_1 = require("../example/toExamplesV3.js");
@@ -44,6 +44,7 @@ const Parameter_js_1 = require("../../../oas/parameter/Parameter.js");
44
44
  const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
45
45
  const v = __importStar(require("valibot"));
46
46
  const emptyParameter_js_1 = require("../../emptyParameter.js");
47
+ const pathParameters_js_1 = require("../../pathParameters.js");
47
48
  const parameterLocation = v.enum({
48
49
  query: 'query',
49
50
  header: 'header',
@@ -59,19 +60,27 @@ const parameterStyle = v.enum({
59
60
  pipeDelimited: 'pipeDelimited',
60
61
  deepObject: 'deepObject'
61
62
  });
62
- const toParameterListV3 = ({ parameters, stackTrail, context }) => {
63
- if (!parameters) {
64
- return undefined;
65
- }
66
- return parameters.flatMap((parameter, index) => stackTrail.trace(`${index}`, st => {
67
- if ((0, emptyParameter_js_1.isEmptyParameter)(parameter)) {
68
- (0, emptyParameter_js_1.logEmptyParameter)({ parameter, stackTrail: st, context });
69
- return [];
70
- }
71
- return [toParameterV3({ parameter, stackTrail: st, context })];
72
- }));
73
- };
63
+ const toParameterListV3 = ({ parameters, stackTrail, context }) => (0, pathParameters_js_1.toParameterEntries)({ parameters, stackTrail, context })?.flatMap((parameter, index) => toParameterEntryV3({ parameter, index, stackTrail, context }));
74
64
  exports.toParameterListV3 = toParameterListV3;
65
+ /**
66
+ * Path-level `parameters`: like {@link toParameterListV3}, but an entry
67
+ * that fails to parse is logged and returned in `broken` instead of
68
+ * throwing.
69
+ */
70
+ const toPathParameterListV3 = ({ parameters, stackTrail, context }) => (0, pathParameters_js_1.toPathParameterList)({
71
+ parameters,
72
+ stackTrail,
73
+ context,
74
+ toEntry: ({ parameter, index }) => toParameterEntryV3({ parameter, index, stackTrail, context })
75
+ });
76
+ exports.toPathParameterListV3 = toPathParameterListV3;
77
+ const toParameterEntryV3 = ({ parameter, index, stackTrail, context }) => stackTrail.trace(`${index}`, st => {
78
+ if ((0, emptyParameter_js_1.isEmptyParameter)(parameter)) {
79
+ (0, emptyParameter_js_1.logEmptyParameter)({ parameter, stackTrail: st, context });
80
+ return [];
81
+ }
82
+ return [toParameterV3({ parameter, stackTrail: st, context })];
83
+ });
75
84
  const toParametersV3 = ({ parameters, stackTrail, context }) => {
76
85
  const output = {};
77
86
  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;
@@ -8,10 +8,11 @@ const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
8
8
  const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
9
9
  const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
10
10
  const { summary, description, parameters, servers, ...skipped } = pathItem;
11
- return new PathItem_js_1.OasPathItem({
11
+ const pathParameters = stackTrail.trace('parameters', st => (0, toParameterV3_js_1.toPathParameterListV3)({ parameters, stackTrail: st, context }));
12
+ const oasPathItem = new PathItem_js_1.OasPathItem({
12
13
  summary,
13
14
  description,
14
- parameters: stackTrail.trace('parameters', st => (0, toParameterV3_js_1.toParameterListV3)({ parameters, stackTrail: st, context })),
15
+ parameters: pathParameters.parameters,
15
16
  servers: (0, tryParseAt_js_1.tryParseAt)({
16
17
  stackTrail,
17
18
  key: 'servers',
@@ -28,5 +29,6 @@ const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
28
29
  parentType: 'pathItem'
29
30
  })
30
31
  });
32
+ return { pathItem: oasPathItem, brokenParameters: pathParameters.broken };
31
33
  };
32
34
  exports.toPathItemV3 = toPathItemV3;
@@ -12,6 +12,7 @@ const toSecurityRequirement_js_1 = require("../securityRequirement/toSecurityReq
12
12
  const isEmpty_js_1 = require("../../../helpers/isEmpty.js");
13
13
  const toExternalDocs_js_1 = require("../externalDocs/toExternalDocs.js");
14
14
  const toServerV3_js_1 = require("../server/toServerV3.js");
15
+ const pathParameters_js_1 = require("../../pathParameters.js");
15
16
  /**
16
17
  * Parses a single webhook Operation Object into an {@link OasWebhook}.
17
18
  *
@@ -89,9 +90,11 @@ const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
89
90
  rest: pathItem,
90
91
  methodObject: {}
91
92
  });
92
- const pathItemObject = !(0, isEmpty_js_1.isEmpty)(cleaned.rest)
93
+ const pathItemResult = !(0, isEmpty_js_1.isEmpty)(cleaned.rest)
93
94
  ? (0, toPathItemV3_js_1.toPathItemV3)({ pathItem: cleaned.rest, stackTrail: nameStack, context })
94
95
  : undefined;
96
+ const pathItemObject = pathItemResult?.pathItem;
97
+ const brokenParameters = pathItemResult?.brokenParameters ?? [];
95
98
  return Object.entries(cleaned.methodObject)
96
99
  .map(([method, operation]) => {
97
100
  // Use `nameStack` (the trail with the webhook name already
@@ -101,6 +104,9 @@ const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
101
104
  if (!operation) {
102
105
  return;
103
106
  }
107
+ if ((0, pathParameters_js_1.isDroppedByPathParameter)({ brokenParameters, operation, stackTrail: st, context })) {
108
+ return undefined;
109
+ }
104
110
  try {
105
111
  return (0, exports.toWebhookV3)({
106
112
  operation,
@@ -9,4 +9,6 @@ type DecomposeUnionReturn = {
9
9
  afterExcluded: SchemaObject;
10
10
  };
11
11
  export declare const decomposeUnion: ({ schema, groupType }: DecomposeUnionArgs) => DecomposeUnionReturn;
12
+ /** Is `key` a union-level key, kept on the union rather than merged into each member? */
13
+ export declare const isUnionLevelKey: (key: string) => boolean;
12
14
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decomposeUnion = void 0;
3
+ exports.isUnionLevelKey = exports.decomposeUnion = void 0;
4
4
  // Convert a schema object into an array of schemas that can be merged iteratively into a new schema
5
5
  const decomposeUnion = ({ schema, groupType }) => {
6
6
  if (!schema[groupType]) {
@@ -60,9 +60,12 @@ const excludedProperties = [
60
60
  'writeOnly',
61
61
  'deprecated'
62
62
  ];
63
+ /** Is `key` a union-level key, kept on the union rather than merged into each member? */
64
+ const isUnionLevelKey = (key) => excludedProperties.includes(key);
65
+ exports.isUnionLevelKey = isUnionLevelKey;
63
66
  const exclude = (entries) => {
64
67
  return entries.reduce((acc, [key, value]) => {
65
- if (excludedProperties.includes(key)) {
68
+ if ((0, exports.isUnionLevelKey)(key)) {
66
69
  acc.excluded.push([key, value]);
67
70
  }
68
71
  else {
@@ -0,0 +1,24 @@
1
+ import type { SchemaObject } from './types.js';
2
+ export type Bound = {
3
+ value: number;
4
+ exclusive: boolean;
5
+ };
6
+ /** The tighter of two lower bounds. */
7
+ export declare const toTighterMinimum: (first: Bound | undefined, second: Bound | undefined) => Bound | undefined;
8
+ /** The tighter of two upper bounds. */
9
+ export declare const toTighterMaximum: (first: Bound | undefined, second: Bound | undefined) => Bound | undefined;
10
+ /** The lower bound of `schema`; exclusive only when `exclusiveMinimum` is `true`. */
11
+ export declare const toMinimum: (schema: SchemaObject) => Bound | undefined;
12
+ /** The upper bound of `schema`; exclusive only when `exclusiveMaximum` is `true`. */
13
+ export declare const toMaximum: (schema: SchemaObject) => Bound | undefined;
14
+ /**
15
+ * Write the merged `minimum`/`exclusiveMinimum` and `maximum`/`exclusiveMaximum`
16
+ * of `first` and `second` onto `result`. Members are in the normalized form,
17
+ * where an exclusive bound is `minimum` plus `exclusiveMinimum: true`.
18
+ */
19
+ export declare const mergeBounds: (result: SchemaObject, first: SchemaObject, second: SchemaObject) => void;
20
+ /**
21
+ * Write `minimum` and `maximum` onto `result` in the normalized form. An
22
+ * undefined bound leaves `result` unchanged.
23
+ */
24
+ export declare const writeBounds: (result: SchemaObject, minimum: Bound | undefined, maximum: Bound | undefined) => void;