@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.
- package/esm/context/StackTrail.js +3 -13
- package/esm/context/documentTrail.d.ts +17 -0
- package/esm/context/documentTrail.js +28 -0
- package/esm/parse/pathParameters.d.ts +57 -0
- package/esm/parse/pathParameters.js +138 -0
- package/esm/parse/v3-0/_merge-all-of/merge-bounds.d.ts +7 -0
- package/esm/parse/v3-0/_merge-all-of/merge-bounds.js +46 -0
- package/esm/parse/v3-0/_merge-all-of/merge-integer-constraints.js +2 -20
- package/esm/parse/v3-0/_merge-all-of/merge-number-constraints.js +2 -20
- package/esm/parse/v3-0/operation/toOperationsV3.js +7 -1
- package/esm/parse/v3-0/parameter/toParameterV3.d.ts +7 -0
- package/esm/parse/v3-0/parameter/toParameterV3.js +19 -11
- package/esm/parse/v3-0/pathItem/toPathItemV3.d.ts +7 -1
- package/esm/parse/v3-0/pathItem/toPathItemV3.js +5 -3
- package/esm/parse/v3-0/webhook/toWebhooksV3.js +7 -1
- package/esm/parse/v3-1/_merge-all-of/decompose-union.d.ts +2 -0
- package/esm/parse/v3-1/_merge-all-of/decompose-union.js +3 -1
- package/esm/parse/v3-1/_merge-all-of/merge-bounds.d.ts +24 -0
- package/esm/parse/v3-1/_merge-all-of/merge-bounds.js +57 -0
- package/esm/parse/v3-1/_merge-all-of/merge-integer-constraints.js +2 -20
- package/esm/parse/v3-1/_merge-all-of/merge-number-constraints.js +2 -20
- package/esm/parse/v3-1/_merge-all-of/merge-union.d.ts +7 -0
- package/esm/parse/v3-1/_merge-all-of/merge-union.js +65 -7
- package/esm/parse/v3-1/_merge-all-of/merge.js +7 -3
- package/esm/parse/v3-1/array/toArray.js +4 -15
- package/esm/parse/v3-1/operation/toOperationsV3.js +7 -1
- package/esm/parse/v3-1/parameter/toParameterV3.d.ts +7 -0
- package/esm/parse/v3-1/parameter/toParameterV3.js +19 -11
- package/esm/parse/v3-1/pathItem/toPathItemV3.d.ts +7 -1
- package/esm/parse/v3-1/pathItem/toPathItemV3.js +5 -3
- package/esm/parse/v3-1/schema/normalize-schema-shape.js +10 -8
- package/esm/parse/v3-1/schema/toSchemasV3.js +7 -1
- package/esm/parse/v3-1/webhook/toWebhooksV3.js +7 -1
- package/esm/parse/v3-2/_merge-all-of/decompose-union.d.ts +2 -0
- package/esm/parse/v3-2/_merge-all-of/decompose-union.js +3 -1
- package/esm/parse/v3-2/_merge-all-of/merge-bounds.d.ts +24 -0
- package/esm/parse/v3-2/_merge-all-of/merge-bounds.js +57 -0
- package/esm/parse/v3-2/_merge-all-of/merge-integer-constraints.js +2 -20
- package/esm/parse/v3-2/_merge-all-of/merge-number-constraints.js +2 -20
- package/esm/parse/v3-2/_merge-all-of/merge-union.d.ts +7 -0
- package/esm/parse/v3-2/_merge-all-of/merge-union.js +65 -7
- package/esm/parse/v3-2/_merge-all-of/merge.js +7 -3
- package/esm/parse/v3-2/array/toArray.js +4 -15
- package/esm/parse/v3-2/operation/toOperationsV3.js +11 -10
- package/esm/parse/v3-2/parameter/toParameterV3.d.ts +7 -0
- package/esm/parse/v3-2/parameter/toParameterV3.js +30 -24
- package/esm/parse/v3-2/pathItem/toPathItemV3.d.ts +6 -13
- package/esm/parse/v3-2/pathItem/toPathItemV3.js +5 -30
- package/esm/parse/v3-2/schema/normalize-schema-shape.js +10 -8
- package/esm/parse/v3-2/schema/toSchemasV3.js +7 -1
- package/esm/parse/v3-2/webhook/toWebhooksV3.js +11 -10
- package/package.json +1 -1
- package/script/context/StackTrail.js +3 -13
- package/script/context/documentTrail.d.ts +17 -0
- package/script/context/documentTrail.js +34 -0
- package/script/parse/pathParameters.d.ts +57 -0
- package/script/parse/pathParameters.js +144 -0
- package/script/parse/v3-0/_merge-all-of/merge-bounds.d.ts +7 -0
- package/script/parse/v3-0/_merge-all-of/merge-bounds.js +50 -0
- package/script/parse/v3-0/_merge-all-of/merge-integer-constraints.js +2 -20
- package/script/parse/v3-0/_merge-all-of/merge-number-constraints.js +2 -20
- package/script/parse/v3-0/operation/toOperationsV3.js +7 -1
- package/script/parse/v3-0/parameter/toParameterV3.d.ts +7 -0
- package/script/parse/v3-0/parameter/toParameterV3.js +22 -13
- package/script/parse/v3-0/pathItem/toPathItemV3.d.ts +7 -1
- package/script/parse/v3-0/pathItem/toPathItemV3.js +4 -2
- package/script/parse/v3-0/webhook/toWebhooksV3.js +7 -1
- package/script/parse/v3-1/_merge-all-of/decompose-union.d.ts +2 -0
- package/script/parse/v3-1/_merge-all-of/decompose-union.js +5 -2
- package/script/parse/v3-1/_merge-all-of/merge-bounds.d.ts +24 -0
- package/script/parse/v3-1/_merge-all-of/merge-bounds.js +66 -0
- package/script/parse/v3-1/_merge-all-of/merge-integer-constraints.js +2 -20
- package/script/parse/v3-1/_merge-all-of/merge-number-constraints.js +2 -20
- package/script/parse/v3-1/_merge-all-of/merge-union.d.ts +7 -0
- package/script/parse/v3-1/_merge-all-of/merge-union.js +66 -7
- package/script/parse/v3-1/_merge-all-of/merge.js +6 -2
- package/script/parse/v3-1/array/toArray.js +4 -15
- package/script/parse/v3-1/operation/toOperationsV3.js +7 -1
- package/script/parse/v3-1/parameter/toParameterV3.d.ts +7 -0
- package/script/parse/v3-1/parameter/toParameterV3.js +22 -13
- package/script/parse/v3-1/pathItem/toPathItemV3.d.ts +7 -1
- package/script/parse/v3-1/pathItem/toPathItemV3.js +4 -2
- package/script/parse/v3-1/schema/normalize-schema-shape.js +10 -8
- package/script/parse/v3-1/schema/toSchemasV3.js +6 -0
- package/script/parse/v3-1/webhook/toWebhooksV3.js +7 -1
- package/script/parse/v3-2/_merge-all-of/decompose-union.d.ts +2 -0
- package/script/parse/v3-2/_merge-all-of/decompose-union.js +5 -2
- package/script/parse/v3-2/_merge-all-of/merge-bounds.d.ts +24 -0
- package/script/parse/v3-2/_merge-all-of/merge-bounds.js +66 -0
- package/script/parse/v3-2/_merge-all-of/merge-integer-constraints.js +2 -20
- package/script/parse/v3-2/_merge-all-of/merge-number-constraints.js +2 -20
- package/script/parse/v3-2/_merge-all-of/merge-union.d.ts +7 -0
- package/script/parse/v3-2/_merge-all-of/merge-union.js +66 -7
- package/script/parse/v3-2/_merge-all-of/merge.js +6 -2
- package/script/parse/v3-2/array/toArray.js +4 -15
- package/script/parse/v3-2/operation/toOperationsV3.js +10 -9
- package/script/parse/v3-2/parameter/toParameterV3.d.ts +7 -0
- package/script/parse/v3-2/parameter/toParameterV3.js +33 -26
- package/script/parse/v3-2/pathItem/toPathItemV3.d.ts +6 -13
- package/script/parse/v3-2/pathItem/toPathItemV3.js +5 -31
- package/script/parse/v3-2/schema/normalize-schema-shape.js +10 -8
- package/script/parse/v3-2/schema/toSchemasV3.js +6 -0
- package/script/parse/v3-2/webhook/toWebhooksV3.js +10 -9
|
@@ -1,32 +1,14 @@
|
|
|
1
1
|
import { genericMerge } from './generic-merge.js';
|
|
2
2
|
import * as v from 'valibot';
|
|
3
3
|
import { checkTypeConflicts } from './check-type-conflicts.js';
|
|
4
|
+
import { mergeBounds } from './merge-bounds.js';
|
|
4
5
|
export function mergeIntegerConstraints(first, second, getRef, normalize) {
|
|
5
6
|
checkTypeConflicts(first, second);
|
|
6
7
|
// First merge enum values if present
|
|
7
8
|
const result = genericMerge(first, second, getRef, normalize, v.number());
|
|
8
9
|
// Then merge other constraints
|
|
9
10
|
result.type = 'integer';
|
|
10
|
-
|
|
11
|
-
if (first.minimum !== undefined || second.minimum !== undefined) {
|
|
12
|
-
const minA = first.minimum ?? -Infinity;
|
|
13
|
-
const minB = second.minimum ?? -Infinity;
|
|
14
|
-
result.minimum = Math.max(minA, minB);
|
|
15
|
-
// If either minimum is exclusive, the result is exclusive
|
|
16
|
-
if (first.exclusiveMinimum || second.exclusiveMinimum) {
|
|
17
|
-
result.exclusiveMinimum = true;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
// Merge maximum and exclusiveMaximum
|
|
21
|
-
if (first.maximum !== undefined || second.maximum !== undefined) {
|
|
22
|
-
const maxA = first.maximum ?? Infinity;
|
|
23
|
-
const maxB = second.maximum ?? Infinity;
|
|
24
|
-
result.maximum = Math.min(maxA, maxB);
|
|
25
|
-
// If either maximum is exclusive, the result is exclusive
|
|
26
|
-
if (first.exclusiveMaximum || second.exclusiveMaximum) {
|
|
27
|
-
result.exclusiveMaximum = true;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
11
|
+
mergeBounds(result, first, second);
|
|
30
12
|
// Merge multipleOf
|
|
31
13
|
if (first.multipleOf !== undefined && second.multipleOf !== undefined) {
|
|
32
14
|
result.multipleOf = first.multipleOf * second.multipleOf;
|
|
@@ -1,32 +1,14 @@
|
|
|
1
1
|
import { genericMerge } from './generic-merge.js';
|
|
2
2
|
import * as v from 'valibot';
|
|
3
3
|
import { checkTypeConflicts } from './check-type-conflicts.js';
|
|
4
|
+
import { mergeBounds } from './merge-bounds.js';
|
|
4
5
|
export function mergeNumberConstraints(first, second, getRef, normalize) {
|
|
5
6
|
checkTypeConflicts(first, second);
|
|
6
7
|
// First merge enum values if present
|
|
7
8
|
const result = genericMerge(first, second, getRef, normalize, v.number());
|
|
8
9
|
// Then merge other constraints
|
|
9
10
|
result.type = 'number';
|
|
10
|
-
|
|
11
|
-
if (first.minimum !== undefined || second.minimum !== undefined) {
|
|
12
|
-
const minA = first.minimum ?? -Infinity;
|
|
13
|
-
const minB = second.minimum ?? -Infinity;
|
|
14
|
-
result.minimum = Math.max(minA, minB);
|
|
15
|
-
// If either minimum is exclusive, the result is exclusive
|
|
16
|
-
if (first.exclusiveMinimum || second.exclusiveMinimum) {
|
|
17
|
-
result.exclusiveMinimum = true;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
// Merge maximum and exclusiveMaximum
|
|
21
|
-
if (first.maximum !== undefined || second.maximum !== undefined) {
|
|
22
|
-
const maxA = first.maximum ?? Infinity;
|
|
23
|
-
const maxB = second.maximum ?? Infinity;
|
|
24
|
-
result.maximum = Math.min(maxA, maxB);
|
|
25
|
-
// If either maximum is exclusive, the result is exclusive
|
|
26
|
-
if (first.exclusiveMaximum || second.exclusiveMaximum) {
|
|
27
|
-
result.exclusiveMaximum = true;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
11
|
+
mergeBounds(result, first, second);
|
|
30
12
|
// Merge multipleOf
|
|
31
13
|
if (first.multipleOf !== undefined && second.multipleOf !== undefined) {
|
|
32
14
|
result.multipleOf = first.multipleOf * second.multipleOf;
|
|
@@ -14,4 +14,11 @@ type MergeCrossProductArgs = {
|
|
|
14
14
|
groupType: 'oneOf' | 'anyOf';
|
|
15
15
|
};
|
|
16
16
|
export declare const mergeCrossProduct: ({ first, second, getRef, normalize, groupType }: MergeCrossProductArgs) => SchemaObject;
|
|
17
|
+
/**
|
|
18
|
+
* A `oneOf`/`anyOf` whose every member is null-only (for example
|
|
19
|
+
* `oneOf: [{ type: 'null' }]`) reads as nullable with no other type, not
|
|
20
|
+
* as an empty union: the group is replaced by `nullable: true`. Any other
|
|
21
|
+
* schema is returned unchanged.
|
|
22
|
+
*/
|
|
23
|
+
export declare const collapseNullOnlyUnion: (schema: SchemaObject, normalize: NormalizeFn) => SchemaObject;
|
|
17
24
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { decomposeUnion } from './decompose-union.js';
|
|
1
|
+
import { decomposeUnion, isUnionLevelKey } from './decompose-union.js';
|
|
2
2
|
import { mergeSchemasOrRefs } from './merge.js';
|
|
3
3
|
import { crossProduct } from './cross-product.js';
|
|
4
4
|
import { isRef } from '../../../helpers/refFns.js';
|
|
@@ -37,15 +37,16 @@ export const mergeUnion = ({ schema, getRef, normalize, groupType }) => {
|
|
|
37
37
|
export const mergeCrossProduct = ({ first, second, getRef, normalize, groupType }) => {
|
|
38
38
|
const firstMembers = Array.isArray(first[groupType]) ? first[groupType] : [first];
|
|
39
39
|
const secondMembers = Array.isArray(second[groupType]) ? second[groupType] : [second];
|
|
40
|
-
// A member that normalizes to
|
|
41
|
-
// member: it makes the union nullable
|
|
40
|
+
// A member that normalizes to `{ nullable: true }`, with at most union-level
|
|
41
|
+
// keys beside it, is a null-only member: it makes the union nullable
|
|
42
|
+
// instead of joining the cross product.
|
|
42
43
|
const firstGroup = firstMembers.filter(member => !isNullableOnly(member, normalize));
|
|
43
44
|
const secondGroup = secondMembers.filter(member => !isNullableOnly(member, normalize));
|
|
44
45
|
const nullable = isNullableGroup(first, groupType) ||
|
|
45
46
|
isNullableGroup(second, groupType) ||
|
|
46
47
|
firstGroup.length !== firstMembers.length ||
|
|
47
48
|
secondGroup.length !== secondMembers.length;
|
|
48
|
-
const mergedGroup = crossProduct(firstGroup, secondGroup)
|
|
49
|
+
const mergedGroup = crossProduct(withGroupSiblings({ schema: first, members: firstGroup, getRef, normalize, groupType }), withGroupSiblings({ schema: second, members: secondGroup, getRef, normalize, groupType }))
|
|
49
50
|
.map(([firstItem, secondItem]) => {
|
|
50
51
|
try {
|
|
51
52
|
const result = mergeSchemasOrRefs(firstItem, secondItem, getRef, normalize);
|
|
@@ -56,6 +57,8 @@ export const mergeCrossProduct = ({ first, second, getRef, normalize, groupType
|
|
|
56
57
|
}
|
|
57
58
|
})
|
|
58
59
|
.filter(item => item !== undefined);
|
|
60
|
+
// A nested group is spread into this one below; its `nullable` carries over.
|
|
61
|
+
const nestedNullable = mergedGroup.some(item => !isRef(item) && Array.isArray(item[groupType]) && item.nullable === true);
|
|
59
62
|
return {
|
|
60
63
|
[groupType]: mergedGroup.flatMap(item => {
|
|
61
64
|
if (!isRef(item) && Array.isArray(item[groupType])) {
|
|
@@ -63,15 +66,70 @@ export const mergeCrossProduct = ({ first, second, getRef, normalize, groupType
|
|
|
63
66
|
}
|
|
64
67
|
return [item];
|
|
65
68
|
}),
|
|
66
|
-
...(nullable ? { nullable: true } : {})
|
|
69
|
+
...(nullable || nestedNullable ? { nullable: true } : {})
|
|
67
70
|
};
|
|
68
71
|
};
|
|
72
|
+
/**
|
|
73
|
+
* Merge the sibling keys of a `oneOf`/`anyOf` wrapper into each of its
|
|
74
|
+
* `members`. A 3.1 `type: ['string', 'number']` with `minLength` normalizes
|
|
75
|
+
* to a `oneOf` with `minLength` beside it. Union-level keys (`nullable`,
|
|
76
|
+
* `description`, …) are not merged in, and a `$ref` member is returned
|
|
77
|
+
* unchanged. A member that conflicts with the
|
|
78
|
+
* siblings is dropped, as in the cross product. A schema with no group is
|
|
79
|
+
* its own only member and is returned unchanged.
|
|
80
|
+
*/
|
|
81
|
+
const withGroupSiblings = ({ schema, members, getRef, normalize, groupType }) => {
|
|
82
|
+
if (!Array.isArray(schema[groupType])) {
|
|
83
|
+
return members;
|
|
84
|
+
}
|
|
85
|
+
const siblings = Object.entries(schema).filter(([key]) => key !== groupType && !isUnionLevelKey(key));
|
|
86
|
+
if (siblings.length === 0) {
|
|
87
|
+
return members;
|
|
88
|
+
}
|
|
89
|
+
const siblingSchema = Object.fromEntries(siblings);
|
|
90
|
+
return members
|
|
91
|
+
.map(member => {
|
|
92
|
+
// Merging into a `$ref` member would resolve it and lose its name.
|
|
93
|
+
if (isRef(member)) {
|
|
94
|
+
return member;
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
return mergeSchemasOrRefs(siblingSchema, member, getRef, normalize);
|
|
98
|
+
}
|
|
99
|
+
catch (_error) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
.filter(member => member !== undefined);
|
|
104
|
+
};
|
|
69
105
|
const isNullableOnly = (member, normalize) => {
|
|
70
106
|
if (isRef(member)) {
|
|
71
107
|
return false;
|
|
72
108
|
}
|
|
73
|
-
const normalized = normalize(member);
|
|
74
|
-
|
|
109
|
+
const normalized = collapseNullOnlyUnion(normalize(member), normalize);
|
|
110
|
+
// Union-level keys (`description`, `title`, …) do not change what a
|
|
111
|
+
// null-only member allows.
|
|
112
|
+
return normalized.nullable === true && Object.keys(normalized).every(isUnionLevelKey);
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* A `oneOf`/`anyOf` whose every member is null-only (for example
|
|
116
|
+
* `oneOf: [{ type: 'null' }]`) reads as nullable with no other type, not
|
|
117
|
+
* as an empty union: the group is replaced by `nullable: true`. Any other
|
|
118
|
+
* schema is returned unchanged.
|
|
119
|
+
*/
|
|
120
|
+
export const collapseNullOnlyUnion = (schema, normalize) => {
|
|
121
|
+
const isNullOnlyGroup = (members) => Array.isArray(members) &&
|
|
122
|
+
members.length > 0 &&
|
|
123
|
+
members.every(member => isNullableOnly(member, normalize));
|
|
124
|
+
if (isNullOnlyGroup(schema.oneOf)) {
|
|
125
|
+
const { oneOf: _oneOf, ...rest } = schema;
|
|
126
|
+
return { ...rest, nullable: true };
|
|
127
|
+
}
|
|
128
|
+
if (isNullOnlyGroup(schema.anyOf)) {
|
|
129
|
+
const { anyOf: _anyOf, ...rest } = schema;
|
|
130
|
+
return { ...rest, nullable: true };
|
|
131
|
+
}
|
|
132
|
+
return schema;
|
|
75
133
|
};
|
|
76
134
|
/** Is this a `oneOf`/`anyOf` group wrapper that already carries `nullable`? */
|
|
77
135
|
const isNullableGroup = (schema, groupType) => Array.isArray(schema[groupType]) && schema.nullable === true;
|
|
@@ -14,12 +14,16 @@ import { mergeBooleanConstraints } from './merge-boolean-constraints.js';
|
|
|
14
14
|
import { genericMerge } from './generic-merge.js';
|
|
15
15
|
import { checkAtLeastOneTypeMatch } from './check-at-least-one-type-match.js';
|
|
16
16
|
import { mergeIntersection } from './merge-intersection.js';
|
|
17
|
-
import { mergeCrossProduct } from './merge-union.js';
|
|
17
|
+
import { collapseNullOnlyUnion, mergeCrossProduct } from './merge-union.js';
|
|
18
18
|
import { isEmpty } from '../../../helpers/isEmpty.js';
|
|
19
19
|
import { isNullOnly, mergeNullOnly } from './nullable-merge.js';
|
|
20
20
|
export const mergeSchemasOrRefs = (inputFirst, inputSecond, getRef, normalize) => {
|
|
21
|
-
const first = isRef(inputFirst)
|
|
22
|
-
|
|
21
|
+
const first = isRef(inputFirst)
|
|
22
|
+
? inputFirst
|
|
23
|
+
: collapseNullOnlyUnion(normalize(inputFirst), normalize);
|
|
24
|
+
const second = isRef(inputSecond)
|
|
25
|
+
? inputSecond
|
|
26
|
+
: collapseNullOnlyUnion(normalize(inputSecond), normalize);
|
|
23
27
|
if (containsRef(first, second)) {
|
|
24
28
|
return mergeWithRef(first, second, getRef, normalize);
|
|
25
29
|
}
|
|
@@ -133,21 +133,10 @@ export const toParsedArray = ({ context, stackTrail, nullable, example, enums, d
|
|
|
133
133
|
nullable,
|
|
134
134
|
defaultValue,
|
|
135
135
|
items: stackTrail.trace('items', st => {
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
//
|
|
139
|
-
|
|
140
|
-
context.logIssue({
|
|
141
|
-
key: 'items',
|
|
142
|
-
level: 'warning',
|
|
143
|
-
message: 'Array schema has no "items" — treating as an array of unknown values',
|
|
144
|
-
parent: value,
|
|
145
|
-
stackTrail: st,
|
|
146
|
-
type: 'INVALID_SCHEMA'
|
|
147
|
-
});
|
|
148
|
-
return toSchemaV3({ schema: {}, stackTrail: st, context });
|
|
149
|
-
}
|
|
150
|
-
return toSchemaV3({ schema: items, stackTrail: st, context });
|
|
136
|
+
// `items` is optional in JSON Schema 2020-12: an array schema
|
|
137
|
+
// without it has unknown items — `{}` falls through toSchemaV3
|
|
138
|
+
// to OasUnknown.
|
|
139
|
+
return toSchemaV3({ schema: items ?? {}, stackTrail: st, context });
|
|
151
140
|
}),
|
|
152
141
|
extensionFields,
|
|
153
142
|
example,
|
|
@@ -2,7 +2,8 @@ import { toRequestBodyV3 } from '../requestBody/toRequestBodiesV3.js';
|
|
|
2
2
|
import { toResponsesV3 } from '../response/toResponseV3.js';
|
|
3
3
|
import { toParameterListV3 } from '../parameter/toParameterV3.js';
|
|
4
4
|
import { OasOperation } from '../../../oas/operation/Operation.js';
|
|
5
|
-
import {
|
|
5
|
+
import { toPathItemV3 } from '../pathItem/toPathItemV3.js';
|
|
6
|
+
import { isEmpty } from '../../../helpers/isEmpty.js';
|
|
6
7
|
import { toPathItemMethod } from '../methods.js';
|
|
7
8
|
import { dropAdditionalOperationsV3 } from '../pathItem/dropAdditionalOperationsV3.js';
|
|
8
9
|
import { warnQuerystringConflictsV3 } from '../parameter/warnQuerystringConflictsV3.js';
|
|
@@ -10,6 +11,7 @@ import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecif
|
|
|
10
11
|
import { toSecurityRequirementsV3 } from '../securityRequirement/toSecurityRequirement.js';
|
|
11
12
|
import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
|
|
12
13
|
import { toOptionalServersV3 } from '../server/toServerV3.js';
|
|
14
|
+
import { isDroppedByPathParameter } from '../../pathParameters.js';
|
|
13
15
|
export const toOperationV3 = ({ operation, operationInfo, stackTrail, context }) => {
|
|
14
16
|
const { method, path, pathItem } = operationInfo;
|
|
15
17
|
const { operationId, tags, summary, description, parameters, requestBody, responses, deprecated, security, externalDocs, servers,
|
|
@@ -76,15 +78,11 @@ export const toOperationsV3 = ({ paths, stackTrail, context }) => {
|
|
|
76
78
|
rest: fixedFields,
|
|
77
79
|
methodObject: {}
|
|
78
80
|
});
|
|
79
|
-
const pathItemResult =
|
|
80
|
-
pathItem: cleaned.rest,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (!pathItemResult.valid) {
|
|
85
|
-
return [];
|
|
86
|
-
}
|
|
87
|
-
const pathItemObject = pathItemResult.pathItem;
|
|
81
|
+
const pathItemResult = !isEmpty(cleaned.rest)
|
|
82
|
+
? toPathItemV3({ pathItem: cleaned.rest, stackTrail: pathStack, context })
|
|
83
|
+
: undefined;
|
|
84
|
+
const pathItemObject = pathItemResult?.pathItem;
|
|
85
|
+
const brokenParameters = pathItemResult?.brokenParameters ?? [];
|
|
88
86
|
return Object.entries(cleaned.methodObject)
|
|
89
87
|
.map(([method, operation]) => {
|
|
90
88
|
// Use `pathStack` (the trail with `path` already pushed),
|
|
@@ -96,6 +94,9 @@ export const toOperationsV3 = ({ paths, stackTrail, context }) => {
|
|
|
96
94
|
if (!operation) {
|
|
97
95
|
return;
|
|
98
96
|
}
|
|
97
|
+
if (isDroppedByPathParameter({ brokenParameters, operation, stackTrail: st, context })) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
99
100
|
try {
|
|
100
101
|
return toOperationV3({
|
|
101
102
|
operation,
|
|
@@ -4,12 +4,19 @@ 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
|
export type ToParameterListV3Args = {
|
|
8
9
|
parameters: (OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject)[] | undefined;
|
|
9
10
|
stackTrail: StackTrail;
|
|
10
11
|
context: ParseContextType;
|
|
11
12
|
};
|
|
12
13
|
export declare const toParameterListV3: ({ parameters, stackTrail, context }: ToParameterListV3Args) => (OasParameter | OasRef<"parameter">)[] | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Path-level `parameters`: like {@link toParameterListV3}, but an entry
|
|
16
|
+
* that fails to parse is logged and returned in `broken` instead of
|
|
17
|
+
* throwing.
|
|
18
|
+
*/
|
|
19
|
+
export declare const toPathParameterListV3: ({ parameters, stackTrail, context }: ToParameterListV3Args) => PathParameterList<OasParameter | OasRef<"parameter">>;
|
|
13
20
|
export type ToParametersV3Args = {
|
|
14
21
|
parameters: Record<string, OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject>;
|
|
15
22
|
stackTrail: StackTrail;
|
|
@@ -9,31 +9,37 @@ import { OasParameter } from '../../../oas/parameter/Parameter.js';
|
|
|
9
9
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
10
10
|
import * as v from 'valibot';
|
|
11
11
|
import { isEmptyParameter, logEmptyParameter } from '../../emptyParameter.js';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
import { toParameterEntries, toPathParameterList } from '../../pathParameters.js';
|
|
13
|
+
export const toParameterListV3 = ({ parameters, stackTrail, context }) => toParameterEntries({ parameters, stackTrail, context })?.flatMap((parameter, index) => toParameterEntryV3({ parameter, index, stackTrail, context }));
|
|
14
|
+
/**
|
|
15
|
+
* Path-level `parameters`: like {@link toParameterListV3}, but an entry
|
|
16
|
+
* that fails to parse is logged and returned in `broken` instead of
|
|
17
|
+
* throwing.
|
|
18
|
+
*/
|
|
19
|
+
export const toPathParameterListV3 = ({ parameters, stackTrail, context }) => toPathParameterList({
|
|
20
|
+
parameters,
|
|
21
|
+
stackTrail,
|
|
22
|
+
context,
|
|
23
|
+
toEntry: ({ parameter, index }) => toParameterEntryV3({ parameter, index, stackTrail, context })
|
|
24
|
+
});
|
|
25
|
+
const toParameterEntryV3 = ({ parameter, index, stackTrail, context }) => {
|
|
26
|
+
if (isEmptyParameter(parameter)) {
|
|
27
|
+
stackTrail.trace(`${index}`, st => logEmptyParameter({ parameter, stackTrail: st, context }));
|
|
28
|
+
return [];
|
|
15
29
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
type: 'INVALID_PARAMETER'
|
|
30
|
-
});
|
|
31
|
-
return [];
|
|
32
|
-
}
|
|
33
|
-
return [
|
|
34
|
-
stackTrail.trace(`${index}`, st => toParameterV3({ parameter, stackTrail: st, context }))
|
|
35
|
-
];
|
|
36
|
-
});
|
|
30
|
+
const querystringIssue = toQuerystringIssue(parameter);
|
|
31
|
+
if (querystringIssue) {
|
|
32
|
+
context.logIssue({
|
|
33
|
+
key: `${index}`,
|
|
34
|
+
parent: parameter,
|
|
35
|
+
level: 'error',
|
|
36
|
+
message: querystringIssue,
|
|
37
|
+
stackTrail,
|
|
38
|
+
type: 'INVALID_PARAMETER'
|
|
39
|
+
});
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
return [stackTrail.trace(`${index}`, st => toParameterV3({ parameter, stackTrail: st, context }))];
|
|
37
43
|
};
|
|
38
44
|
/**
|
|
39
45
|
* A `querystring` parameter describes the whole query string, so it must
|
|
@@ -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,17 +8,9 @@ export type ToPathItemV3Args = {
|
|
|
7
8
|
stackTrail: StackTrail;
|
|
8
9
|
context: ParseContextType;
|
|
9
10
|
};
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} | {
|
|
15
|
-
valid: false;
|
|
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[];
|
|
16
15
|
};
|
|
17
|
-
|
|
18
|
-
* Parses a path item's shared fields without letting a throw escape. A
|
|
19
|
-
* path-level parameter that fails validation (for example `in: body`) logs
|
|
20
|
-
* one `INVALID_OPERATION` at the path and returns `{ valid: false }`, so
|
|
21
|
-
* the caller skips that path and keeps the rest.
|
|
22
|
-
*/
|
|
23
|
-
export declare const toPathItemResultV3: ({ pathItem, stackTrail, context }: ToPathItemV3Args) => PathItemResult;
|
|
16
|
+
export declare const toPathItemV3: ({ pathItem, stackTrail, context }: ToPathItemV3Args) => PathItemV3;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
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
|
-
import { isEmpty } from '../../../helpers/isEmpty.js';
|
|
7
6
|
export const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
|
|
8
7
|
const { summary, description, parameters, servers, ...skipped } = pathItem;
|
|
9
|
-
|
|
8
|
+
const pathParameters = stackTrail.trace('parameters', st => toPathParameterListV3({ parameters, stackTrail: st, context }));
|
|
9
|
+
const oasPathItem = new OasPathItem({
|
|
10
10
|
summary,
|
|
11
11
|
description,
|
|
12
|
-
parameters:
|
|
12
|
+
parameters: pathParameters.parameters,
|
|
13
13
|
servers: tryParseAt({
|
|
14
14
|
stackTrail,
|
|
15
15
|
key: 'servers',
|
|
@@ -26,30 +26,5 @@ export const toPathItemV3 = ({ pathItem, stackTrail, context }) => {
|
|
|
26
26
|
parentType: 'pathItem'
|
|
27
27
|
})
|
|
28
28
|
});
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Parses a path item's shared fields without letting a throw escape. A
|
|
32
|
-
* path-level parameter that fails validation (for example `in: body`) logs
|
|
33
|
-
* one `INVALID_OPERATION` at the path and returns `{ valid: false }`, so
|
|
34
|
-
* the caller skips that path and keeps the rest.
|
|
35
|
-
*/
|
|
36
|
-
export const toPathItemResultV3 = ({ pathItem, stackTrail, context }) => {
|
|
37
|
-
if (isEmpty(pathItem)) {
|
|
38
|
-
return { valid: true, pathItem: undefined };
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
return { valid: true, pathItem: toPathItemV3({ pathItem, stackTrail, context }) };
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
45
|
-
context.logIssueNoKey({
|
|
46
|
-
parent: pathItem,
|
|
47
|
-
level: 'error',
|
|
48
|
-
message: normalized.message,
|
|
49
|
-
cause: normalized,
|
|
50
|
-
stackTrail,
|
|
51
|
-
type: 'INVALID_OPERATION'
|
|
52
|
-
});
|
|
53
|
-
return { valid: false };
|
|
54
|
-
}
|
|
29
|
+
return { pathItem: oasPathItem, brokenParameters: pathParameters.broken };
|
|
55
30
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { toMaximum, toMinimum, toTighterMaximum, toTighterMinimum, writeBounds } from '../_merge-all-of/merge-bounds.js';
|
|
1
2
|
/**
|
|
2
3
|
* OpenAPI 3.1 lets a schema's `type` be an ARRAY (e.g. `['string', 'null']`),
|
|
3
4
|
* which the shared IR — modelling a single `type` plus a `nullable` flag —
|
|
@@ -94,15 +95,16 @@ const normalizeExclusiveBounds = (schema) => {
|
|
|
94
95
|
if (typeof exclusiveMinimum !== 'number' && typeof exclusiveMaximum !== 'number') {
|
|
95
96
|
return schema;
|
|
96
97
|
}
|
|
98
|
+
// A schema may carry both `minimum` and a numeric `exclusiveMinimum`:
|
|
99
|
+
// keep the tighter of the two (the same for maximum).
|
|
100
|
+
const minimum = typeof exclusiveMinimum === 'number'
|
|
101
|
+
? toTighterMinimum(toMinimum(schema), { value: exclusiveMinimum, exclusive: true })
|
|
102
|
+
: undefined;
|
|
103
|
+
const maximum = typeof exclusiveMaximum === 'number'
|
|
104
|
+
? toTighterMaximum(toMaximum(schema), { value: exclusiveMaximum, exclusive: true })
|
|
105
|
+
: undefined;
|
|
97
106
|
const next = { ...schema };
|
|
98
|
-
|
|
99
|
-
next.minimum = exclusiveMinimum;
|
|
100
|
-
next.exclusiveMinimum = true;
|
|
101
|
-
}
|
|
102
|
-
if (typeof exclusiveMaximum === 'number') {
|
|
103
|
-
next.maximum = exclusiveMaximum;
|
|
104
|
-
next.exclusiveMaximum = true;
|
|
105
|
-
}
|
|
107
|
+
writeBounds(next, minimum, maximum);
|
|
106
108
|
return next;
|
|
107
109
|
};
|
|
108
110
|
/**
|
|
@@ -10,7 +10,7 @@ import { toUnknown } from '../unknown/toUnknown.js';
|
|
|
10
10
|
import { toUnion } from '../union/toUnion.js';
|
|
11
11
|
import { toGetRef } from '../../../helpers/refFns.js';
|
|
12
12
|
import { mergeIntersection } from '../_merge-all-of/merge-intersection.js';
|
|
13
|
-
import { mergeUnion } from '../_merge-all-of/merge-union.js';
|
|
13
|
+
import { collapseNullOnlyUnion, mergeUnion } from '../_merge-all-of/merge-union.js';
|
|
14
14
|
import { tryParseAt } from '../../../context/tryParseAt.js';
|
|
15
15
|
import { isNullOnlyType, normalizeMergeMember, normalizeSchemaShape } from './normalize-schema-shape.js';
|
|
16
16
|
export const toSchemasV3 = ({ schemas, stackTrail, context }) => {
|
|
@@ -166,6 +166,12 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
166
166
|
return toSchemaV3({ schema: merged, stackTrail: st, context });
|
|
167
167
|
});
|
|
168
168
|
}
|
|
169
|
+
// A `oneOf`/`anyOf` of only null members reads as nullable, not as an
|
|
170
|
+
// empty union.
|
|
171
|
+
const collapsed = collapseNullOnlyUnion(schema, normalizeMergeMember);
|
|
172
|
+
if (collapsed !== schema) {
|
|
173
|
+
return toSchemaV3({ schema: collapsed, stackTrail, context });
|
|
174
|
+
}
|
|
169
175
|
if ('oneOf' in schema && Array.isArray(schema.oneOf)) {
|
|
170
176
|
const wrapper = withoutWrapperUnevaluatedProperties({
|
|
171
177
|
schema,
|
|
@@ -2,7 +2,8 @@ import { toRequestBodyV3 } from '../requestBody/toRequestBodiesV3.js';
|
|
|
2
2
|
import { toResponsesV3 } from '../response/toResponseV3.js';
|
|
3
3
|
import { toParameterListV3 } from '../parameter/toParameterV3.js';
|
|
4
4
|
import { OasWebhook } from '../../../oas/webhook/Webhook.js';
|
|
5
|
-
import {
|
|
5
|
+
import { toPathItemV3 } from '../pathItem/toPathItemV3.js';
|
|
6
|
+
import { isEmpty } from '../../../helpers/isEmpty.js';
|
|
6
7
|
import { toPathItemMethod } from '../methods.js';
|
|
7
8
|
import { dropAdditionalOperationsV3 } from '../pathItem/dropAdditionalOperationsV3.js';
|
|
8
9
|
import { warnQuerystringConflictsV3 } from '../parameter/warnQuerystringConflictsV3.js';
|
|
@@ -10,6 +11,7 @@ import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecif
|
|
|
10
11
|
import { toSecurityRequirementsV3 } from '../securityRequirement/toSecurityRequirement.js';
|
|
11
12
|
import { toExternalDocs } from '../externalDocs/toExternalDocs.js';
|
|
12
13
|
import { toOptionalServersV3 } from '../server/toServerV3.js';
|
|
14
|
+
import { isDroppedByPathParameter } from '../../pathParameters.js';
|
|
13
15
|
/**
|
|
14
16
|
* Parses a single webhook Operation Object into an {@link OasWebhook}.
|
|
15
17
|
*
|
|
@@ -88,15 +90,11 @@ export const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
|
|
|
88
90
|
rest: fixedFields,
|
|
89
91
|
methodObject: {}
|
|
90
92
|
});
|
|
91
|
-
const pathItemResult =
|
|
92
|
-
pathItem: cleaned.rest,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (!pathItemResult.valid) {
|
|
97
|
-
return [];
|
|
98
|
-
}
|
|
99
|
-
const pathItemObject = pathItemResult.pathItem;
|
|
93
|
+
const pathItemResult = !isEmpty(cleaned.rest)
|
|
94
|
+
? toPathItemV3({ pathItem: cleaned.rest, stackTrail: nameStack, context })
|
|
95
|
+
: undefined;
|
|
96
|
+
const pathItemObject = pathItemResult?.pathItem;
|
|
97
|
+
const brokenParameters = pathItemResult?.brokenParameters ?? [];
|
|
100
98
|
return Object.entries(cleaned.methodObject)
|
|
101
99
|
.map(([method, operation]) => {
|
|
102
100
|
// Use `nameStack` (the trail with the webhook name already
|
|
@@ -106,6 +104,9 @@ export const toWebhooksV3 = ({ webhooks, stackTrail, context }) => {
|
|
|
106
104
|
if (!operation) {
|
|
107
105
|
return;
|
|
108
106
|
}
|
|
107
|
+
if (isDroppedByPathParameter({ brokenParameters, operation, stackTrail: st, context })) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
109
110
|
try {
|
|
110
111
|
return toWebhookV3({
|
|
111
112
|
operation,
|
package/package.json
CHANGED
|
@@ -16,6 +16,7 @@ exports.StackTrail = void 0;
|
|
|
16
16
|
require("../_dnt.polyfills.js");
|
|
17
17
|
const Components_js_1 = require("../oas/components/Components.js");
|
|
18
18
|
const JsonPointer_js_1 = require("../types/JsonPointer.js");
|
|
19
|
+
const documentTrail_js_1 = require("./documentTrail.js");
|
|
19
20
|
class StackTrail {
|
|
20
21
|
constructor(stack = []) {
|
|
21
22
|
/** Internal stack of traversal frames */
|
|
@@ -214,15 +215,7 @@ class StackTrail {
|
|
|
214
215
|
* ```
|
|
215
216
|
*/
|
|
216
217
|
toSchemaPointer() {
|
|
217
|
-
|
|
218
|
-
// `post-pass` trace). The operational phase always sits before any
|
|
219
|
-
// document key, so the FIRST match is the boundary — a document key
|
|
220
|
-
// that happens to share a phase name (e.g. a schema literally named
|
|
221
|
-
// `parse`) appears later and is unaffected.
|
|
222
|
-
const phaseFrames = new Set(['parse', 'generate', 'render', 'post-pass']);
|
|
223
|
-
const phaseIndex = __classPrivateFieldGet(this, _StackTrail_stack, "f").findIndex(frame => phaseFrames.has(frame));
|
|
224
|
-
const documentFrames = phaseIndex === -1 ? __classPrivateFieldGet(this, _StackTrail_stack, "f") : __classPrivateFieldGet(this, _StackTrail_stack, "f").slice(phaseIndex + 1);
|
|
225
|
-
return (0, JsonPointer_js_1.toJsonPointer)(documentFrames);
|
|
218
|
+
return (0, JsonPointer_js_1.toJsonPointer)((0, documentTrail_js_1.toDocumentFrames)(__classPrivateFieldGet(this, _StackTrail_stack, "f")));
|
|
226
219
|
}
|
|
227
220
|
toStackRef() {
|
|
228
221
|
const [first, second, third] = this.stackTrail;
|
|
@@ -308,9 +301,7 @@ class StackTrail {
|
|
|
308
301
|
* ```
|
|
309
302
|
*/
|
|
310
303
|
toString() {
|
|
311
|
-
return __classPrivateFieldGet(this, _StackTrail_stack, "f")
|
|
312
|
-
.map(frame => frame.replace(/[%:]/g, character => escapes[character]))
|
|
313
|
-
.join(':');
|
|
304
|
+
return (0, documentTrail_js_1.toTrailString)(__classPrivateFieldGet(this, _StackTrail_stack, "f"));
|
|
314
305
|
}
|
|
315
306
|
/**
|
|
316
307
|
* Reads a string written by {@link StackTrail.toString} back into a trail.
|
|
@@ -334,5 +325,4 @@ class StackTrail {
|
|
|
334
325
|
}
|
|
335
326
|
exports.StackTrail = StackTrail;
|
|
336
327
|
_StackTrail_stack = new WeakMap();
|
|
337
|
-
const escapes = { '%': '%25', ':': '%3A' };
|
|
338
328
|
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;
|