@skmtc/core 0.32.1 → 0.32.3
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/parse/v3-0/operation/toOperationsV3.js +1 -2
- package/esm/parse/v3-0/server/toServerV3.js +16 -2
- package/esm/parse/v3-0/webhook/toWebhooksV3.js +1 -2
- package/esm/parse/v3-1/_merge-all-of/check-array-item-type-conflicts.d.ts +2 -1
- package/esm/parse/v3-1/_merge-all-of/check-array-item-type-conflicts.js +7 -3
- package/esm/parse/v3-1/_merge-all-of/generic-merge.d.ts +2 -2
- package/esm/parse/v3-1/_merge-all-of/generic-merge.js +2 -2
- package/esm/parse/v3-1/_merge-all-of/merge-array-constraints.d.ts +2 -2
- package/esm/parse/v3-1/_merge-all-of/merge-array-constraints.js +8 -12
- package/esm/parse/v3-1/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
- package/esm/parse/v3-1/_merge-all-of/merge-boolean-constraints.js +2 -2
- package/esm/parse/v3-1/_merge-all-of/merge-integer-constraints.d.ts +2 -2
- package/esm/parse/v3-1/_merge-all-of/merge-integer-constraints.js +2 -2
- package/esm/parse/v3-1/_merge-all-of/merge-intersection.d.ts +3 -2
- package/esm/parse/v3-1/_merge-all-of/merge-intersection.js +2 -2
- package/esm/parse/v3-1/_merge-all-of/merge-number-constraints.d.ts +2 -2
- package/esm/parse/v3-1/_merge-all-of/merge-number-constraints.js +2 -2
- package/esm/parse/v3-1/_merge-all-of/merge-object-constraints.d.ts +2 -2
- package/esm/parse/v3-1/_merge-all-of/merge-object-constraints.js +3 -3
- package/esm/parse/v3-1/_merge-all-of/merge-properties.d.ts +2 -2
- package/esm/parse/v3-1/_merge-all-of/merge-properties.js +2 -2
- package/esm/parse/v3-1/_merge-all-of/merge-string-constraints.d.ts +2 -2
- package/esm/parse/v3-1/_merge-all-of/merge-string-constraints.js +3 -3
- package/esm/parse/v3-1/_merge-all-of/merge-union.d.ts +5 -3
- package/esm/parse/v3-1/_merge-all-of/merge-union.js +31 -7
- package/esm/parse/v3-1/_merge-all-of/merge.d.ts +2 -2
- package/esm/parse/v3-1/_merge-all-of/merge.js +28 -23
- package/esm/parse/v3-1/_merge-all-of/types.d.ts +6 -0
- package/esm/parse/v3-1/operation/toOperationsV3.js +1 -2
- package/esm/parse/v3-1/schema/normalize-schema-shape.d.ts +24 -0
- package/esm/parse/v3-1/schema/normalize-schema-shape.js +213 -0
- package/esm/parse/v3-1/schema/toSchemasV3.js +7 -195
- package/esm/parse/v3-1/server/toServerV3.js +16 -2
- package/esm/parse/v3-1/webhook/toWebhooksV3.js +1 -2
- package/esm/parse/v3-2/_merge-all-of/check-array-item-type-conflicts.d.ts +2 -1
- package/esm/parse/v3-2/_merge-all-of/check-array-item-type-conflicts.js +7 -3
- package/esm/parse/v3-2/_merge-all-of/generic-merge.d.ts +2 -2
- package/esm/parse/v3-2/_merge-all-of/generic-merge.js +2 -2
- package/esm/parse/v3-2/_merge-all-of/merge-array-constraints.d.ts +2 -2
- package/esm/parse/v3-2/_merge-all-of/merge-array-constraints.js +8 -12
- package/esm/parse/v3-2/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
- package/esm/parse/v3-2/_merge-all-of/merge-boolean-constraints.js +2 -2
- package/esm/parse/v3-2/_merge-all-of/merge-integer-constraints.d.ts +2 -2
- package/esm/parse/v3-2/_merge-all-of/merge-integer-constraints.js +2 -2
- package/esm/parse/v3-2/_merge-all-of/merge-intersection.d.ts +3 -2
- package/esm/parse/v3-2/_merge-all-of/merge-intersection.js +2 -2
- package/esm/parse/v3-2/_merge-all-of/merge-number-constraints.d.ts +2 -2
- package/esm/parse/v3-2/_merge-all-of/merge-number-constraints.js +2 -2
- package/esm/parse/v3-2/_merge-all-of/merge-object-constraints.d.ts +2 -2
- package/esm/parse/v3-2/_merge-all-of/merge-object-constraints.js +3 -3
- package/esm/parse/v3-2/_merge-all-of/merge-properties.d.ts +2 -2
- package/esm/parse/v3-2/_merge-all-of/merge-properties.js +2 -2
- package/esm/parse/v3-2/_merge-all-of/merge-string-constraints.d.ts +2 -2
- package/esm/parse/v3-2/_merge-all-of/merge-string-constraints.js +3 -3
- package/esm/parse/v3-2/_merge-all-of/merge-union.d.ts +5 -3
- package/esm/parse/v3-2/_merge-all-of/merge-union.js +31 -7
- package/esm/parse/v3-2/_merge-all-of/merge.d.ts +2 -2
- package/esm/parse/v3-2/_merge-all-of/merge.js +28 -23
- package/esm/parse/v3-2/_merge-all-of/types.d.ts +6 -0
- package/esm/parse/v3-2/operation/toOperationsV3.js +1 -2
- package/esm/parse/v3-2/schema/normalize-schema-shape.d.ts +24 -0
- package/esm/parse/v3-2/schema/normalize-schema-shape.js +213 -0
- package/esm/parse/v3-2/schema/toSchemasV3.js +7 -195
- package/esm/parse/v3-2/server/toServerV3.js +16 -2
- package/esm/parse/v3-2/webhook/toWebhooksV3.js +1 -2
- package/package.json +1 -1
- package/script/parse/v3-0/operation/toOperationsV3.js +1 -2
- package/script/parse/v3-0/server/toServerV3.js +16 -2
- package/script/parse/v3-0/webhook/toWebhooksV3.js +1 -2
- package/script/parse/v3-1/_merge-all-of/check-array-item-type-conflicts.d.ts +2 -1
- package/script/parse/v3-1/_merge-all-of/check-array-item-type-conflicts.js +7 -3
- package/script/parse/v3-1/_merge-all-of/generic-merge.d.ts +2 -2
- package/script/parse/v3-1/_merge-all-of/generic-merge.js +2 -2
- package/script/parse/v3-1/_merge-all-of/merge-array-constraints.d.ts +2 -2
- package/script/parse/v3-1/_merge-all-of/merge-array-constraints.js +8 -12
- package/script/parse/v3-1/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
- package/script/parse/v3-1/_merge-all-of/merge-boolean-constraints.js +2 -2
- package/script/parse/v3-1/_merge-all-of/merge-integer-constraints.d.ts +2 -2
- package/script/parse/v3-1/_merge-all-of/merge-integer-constraints.js +2 -2
- package/script/parse/v3-1/_merge-all-of/merge-intersection.d.ts +3 -2
- package/script/parse/v3-1/_merge-all-of/merge-intersection.js +2 -2
- package/script/parse/v3-1/_merge-all-of/merge-number-constraints.d.ts +2 -2
- package/script/parse/v3-1/_merge-all-of/merge-number-constraints.js +2 -2
- package/script/parse/v3-1/_merge-all-of/merge-object-constraints.d.ts +2 -2
- package/script/parse/v3-1/_merge-all-of/merge-object-constraints.js +3 -3
- package/script/parse/v3-1/_merge-all-of/merge-properties.d.ts +2 -2
- package/script/parse/v3-1/_merge-all-of/merge-properties.js +2 -2
- package/script/parse/v3-1/_merge-all-of/merge-string-constraints.d.ts +2 -2
- package/script/parse/v3-1/_merge-all-of/merge-string-constraints.js +3 -3
- package/script/parse/v3-1/_merge-all-of/merge-union.d.ts +5 -3
- package/script/parse/v3-1/_merge-all-of/merge-union.js +31 -7
- package/script/parse/v3-1/_merge-all-of/merge.d.ts +2 -2
- package/script/parse/v3-1/_merge-all-of/merge.js +28 -23
- package/script/parse/v3-1/_merge-all-of/types.d.ts +6 -0
- package/script/parse/v3-1/operation/toOperationsV3.js +1 -2
- package/script/parse/v3-1/schema/normalize-schema-shape.d.ts +24 -0
- package/script/parse/v3-1/schema/normalize-schema-shape.js +219 -0
- package/script/parse/v3-1/schema/toSchemasV3.js +8 -196
- package/script/parse/v3-1/server/toServerV3.js +16 -2
- package/script/parse/v3-1/webhook/toWebhooksV3.js +1 -2
- package/script/parse/v3-2/_merge-all-of/check-array-item-type-conflicts.d.ts +2 -1
- package/script/parse/v3-2/_merge-all-of/check-array-item-type-conflicts.js +7 -3
- package/script/parse/v3-2/_merge-all-of/generic-merge.d.ts +2 -2
- package/script/parse/v3-2/_merge-all-of/generic-merge.js +2 -2
- package/script/parse/v3-2/_merge-all-of/merge-array-constraints.d.ts +2 -2
- package/script/parse/v3-2/_merge-all-of/merge-array-constraints.js +8 -12
- package/script/parse/v3-2/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
- package/script/parse/v3-2/_merge-all-of/merge-boolean-constraints.js +2 -2
- package/script/parse/v3-2/_merge-all-of/merge-integer-constraints.d.ts +2 -2
- package/script/parse/v3-2/_merge-all-of/merge-integer-constraints.js +2 -2
- package/script/parse/v3-2/_merge-all-of/merge-intersection.d.ts +3 -2
- package/script/parse/v3-2/_merge-all-of/merge-intersection.js +2 -2
- package/script/parse/v3-2/_merge-all-of/merge-number-constraints.d.ts +2 -2
- package/script/parse/v3-2/_merge-all-of/merge-number-constraints.js +2 -2
- package/script/parse/v3-2/_merge-all-of/merge-object-constraints.d.ts +2 -2
- package/script/parse/v3-2/_merge-all-of/merge-object-constraints.js +3 -3
- package/script/parse/v3-2/_merge-all-of/merge-properties.d.ts +2 -2
- package/script/parse/v3-2/_merge-all-of/merge-properties.js +2 -2
- package/script/parse/v3-2/_merge-all-of/merge-string-constraints.d.ts +2 -2
- package/script/parse/v3-2/_merge-all-of/merge-string-constraints.js +3 -3
- package/script/parse/v3-2/_merge-all-of/merge-union.d.ts +5 -3
- package/script/parse/v3-2/_merge-all-of/merge-union.js +31 -7
- package/script/parse/v3-2/_merge-all-of/merge.d.ts +2 -2
- package/script/parse/v3-2/_merge-all-of/merge.js +28 -23
- package/script/parse/v3-2/_merge-all-of/types.d.ts +6 -0
- package/script/parse/v3-2/operation/toOperationsV3.js +1 -2
- package/script/parse/v3-2/schema/normalize-schema-shape.d.ts +24 -0
- package/script/parse/v3-2/schema/normalize-schema-shape.js +219 -0
- package/script/parse/v3-2/schema/toSchemasV3.js +8 -196
- package/script/parse/v3-2/server/toServerV3.js +16 -2
- package/script/parse/v3-2/webhook/toWebhooksV3.js +1 -2
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
2
|
-
import type { GetRefFn } from './types.js';
|
|
3
|
-
export declare function mergeNumberConstraints(first: OpenAPIV3.SchemaObject, second: OpenAPIV3.SchemaObject, getRef: GetRefFn): OpenAPIV3.SchemaObject;
|
|
2
|
+
import type { GetRefFn, NormalizeFn } from './types.js';
|
|
3
|
+
export declare function mergeNumberConstraints(first: OpenAPIV3.SchemaObject, second: OpenAPIV3.SchemaObject, getRef: GetRefFn, normalize: NormalizeFn): OpenAPIV3.SchemaObject;
|
|
@@ -1,10 +1,10 @@
|
|
|
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
|
-
export function mergeNumberConstraints(first, second, getRef) {
|
|
4
|
+
export function mergeNumberConstraints(first, second, getRef, normalize) {
|
|
5
5
|
checkTypeConflicts(first, second);
|
|
6
6
|
// First merge enum values if present
|
|
7
|
-
const result = genericMerge(first, second, getRef, v.number());
|
|
7
|
+
const result = genericMerge(first, second, getRef, normalize, v.number());
|
|
8
8
|
// Then merge other constraints
|
|
9
9
|
result.type = 'number';
|
|
10
10
|
// Merge minimum and exclusiveMinimum
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
2
|
+
import type { GetRefFn, NormalizeFn } from './types.js';
|
|
2
3
|
type SchemaObject = OpenAPIV3.SchemaObject;
|
|
3
|
-
|
|
4
|
-
export declare const mergeObjectConstraints: (first: SchemaObject, second: SchemaObject, getRef: (ref: ReferenceObject) => SchemaObject) => SchemaObject;
|
|
4
|
+
export declare const mergeObjectConstraints: (first: SchemaObject, second: SchemaObject, getRef: GetRefFn, normalize: NormalizeFn) => SchemaObject;
|
|
5
5
|
export {};
|
|
@@ -2,14 +2,14 @@ import { mergeSchemasOrRefs } from './merge.js';
|
|
|
2
2
|
import { genericMerge } from './generic-merge.js';
|
|
3
3
|
import * as v from 'valibot';
|
|
4
4
|
import { checkTypeConflicts } from './check-type-conflicts.js';
|
|
5
|
-
export const mergeObjectConstraints = (first, second, getRef) => {
|
|
5
|
+
export const mergeObjectConstraints = (first, second, getRef, normalize) => {
|
|
6
6
|
// Check for type conflicts
|
|
7
7
|
checkTypeConflicts(first, second);
|
|
8
|
-
const result = genericMerge(first, second, getRef, v.record(v.string(), v.any()));
|
|
8
|
+
const result = genericMerge(first, second, getRef, normalize, v.record(v.string(), v.any()));
|
|
9
9
|
if (typeof second.additionalProperties === 'object' &&
|
|
10
10
|
typeof first.additionalProperties === 'object') {
|
|
11
11
|
// If both have additionalProperties as schemas, merge them
|
|
12
|
-
result.additionalProperties = mergeSchemasOrRefs(first.additionalProperties, second.additionalProperties, getRef);
|
|
12
|
+
result.additionalProperties = mergeSchemasOrRefs(first.additionalProperties, second.additionalProperties, getRef, normalize);
|
|
13
13
|
}
|
|
14
14
|
else if (second.additionalProperties !== undefined) {
|
|
15
15
|
result.additionalProperties = second.additionalProperties;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { SchemaObject, GetRefFn } from './types.js';
|
|
2
|
-
export declare const mergeProperties: (first: SchemaObject, second: SchemaObject, getRef: GetRefFn) => SchemaObject | undefined;
|
|
1
|
+
import type { SchemaObject, GetRefFn, NormalizeFn } from './types.js';
|
|
2
|
+
export declare const mergeProperties: (first: SchemaObject, second: SchemaObject, getRef: GetRefFn, normalize: NormalizeFn) => SchemaObject | undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mergeSchemasOrRefs } from './merge.js';
|
|
2
|
-
export const mergeProperties = (first, second, getRef) => {
|
|
2
|
+
export const mergeProperties = (first, second, getRef, normalize) => {
|
|
3
3
|
if (containsProperties(first, second)) {
|
|
4
4
|
const properties = { ...first.properties };
|
|
5
5
|
if (!properties) {
|
|
@@ -9,7 +9,7 @@ export const mergeProperties = (first, second, getRef) => {
|
|
|
9
9
|
}
|
|
10
10
|
for (const key in second.properties) {
|
|
11
11
|
if (key in properties) {
|
|
12
|
-
properties[key] = mergeSchemasOrRefs(properties[key], second.properties[key], getRef);
|
|
12
|
+
properties[key] = mergeSchemasOrRefs(properties[key], second.properties[key], getRef, normalize);
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
15
|
properties[key] = second.properties[key];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
2
|
-
import type { GetRefFn } from './types.js';
|
|
3
|
-
export declare function mergeStringConstraints(first: OpenAPIV3.SchemaObject, second: OpenAPIV3.SchemaObject, getRef: GetRefFn): OpenAPIV3.SchemaObject;
|
|
2
|
+
import type { GetRefFn, NormalizeFn } from './types.js';
|
|
3
|
+
export declare function mergeStringConstraints(first: OpenAPIV3.SchemaObject, second: OpenAPIV3.SchemaObject, getRef: GetRefFn, normalize: NormalizeFn): OpenAPIV3.SchemaObject;
|
|
@@ -2,13 +2,13 @@ import { genericMerge } from './generic-merge.js';
|
|
|
2
2
|
import * as v from 'valibot';
|
|
3
3
|
import { checkTypeConflicts } from './check-type-conflicts.js';
|
|
4
4
|
import { checkAtLeastOneTypeMatch } from './check-at-least-one-type-match.js';
|
|
5
|
-
export function mergeStringConstraints(first, second, getRef) {
|
|
5
|
+
export function mergeStringConstraints(first, second, getRef, normalize) {
|
|
6
6
|
checkTypeConflicts(first, second);
|
|
7
7
|
if (!checkAtLeastOneTypeMatch(first, second, 'string')) {
|
|
8
|
-
return genericMerge(first, second, getRef);
|
|
8
|
+
return genericMerge(first, second, getRef, normalize);
|
|
9
9
|
}
|
|
10
10
|
// First merge enum values if present
|
|
11
|
-
const result = genericMerge(first, second, getRef, v.string());
|
|
11
|
+
const result = genericMerge(first, second, getRef, normalize, v.string());
|
|
12
12
|
// Then merge other constraints
|
|
13
13
|
result.type = 'string';
|
|
14
14
|
// Merge minLength
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import type { GetRefFn, SchemaOrReference, SchemaObject } from './types.js';
|
|
1
|
+
import type { GetRefFn, NormalizeFn, SchemaOrReference, SchemaObject } from './types.js';
|
|
2
2
|
type MergeUnionArgs = {
|
|
3
3
|
schema: SchemaObject;
|
|
4
4
|
getRef: GetRefFn;
|
|
5
|
+
normalize: NormalizeFn;
|
|
5
6
|
groupType: 'oneOf' | 'anyOf';
|
|
6
7
|
};
|
|
7
|
-
export declare const mergeUnion: ({ schema, getRef, groupType }: MergeUnionArgs) => SchemaOrReference;
|
|
8
|
+
export declare const mergeUnion: ({ schema, getRef, normalize, groupType }: MergeUnionArgs) => SchemaOrReference;
|
|
8
9
|
type MergeCrossProductArgs = {
|
|
9
10
|
first: SchemaObject;
|
|
10
11
|
second: SchemaObject;
|
|
11
12
|
getRef: GetRefFn;
|
|
13
|
+
normalize: NormalizeFn;
|
|
12
14
|
groupType: 'oneOf' | 'anyOf';
|
|
13
15
|
};
|
|
14
|
-
export declare const mergeCrossProduct: ({ first, second, getRef, groupType }: MergeCrossProductArgs) => SchemaObject;
|
|
16
|
+
export declare const mergeCrossProduct: ({ first, second, getRef, normalize, groupType }: MergeCrossProductArgs) => SchemaObject;
|
|
15
17
|
export {};
|
|
@@ -2,7 +2,7 @@ import { decomposeUnion } 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';
|
|
5
|
-
export const mergeUnion = ({ schema, getRef, groupType }) => {
|
|
5
|
+
export const mergeUnion = ({ schema, getRef, normalize, groupType }) => {
|
|
6
6
|
const { beforeExcluded, decomposed, afterExcluded } = decomposeUnion({ schema, groupType });
|
|
7
7
|
// if (decomposed.length === 1) {
|
|
8
8
|
// console.log('DECOMPOSED', JSON.stringify(decomposed[0], null, 2))
|
|
@@ -18,7 +18,13 @@ export const mergeUnion = ({ schema, getRef, groupType }) => {
|
|
|
18
18
|
return '$ref' in decomposed ? getRef(decomposed) : decomposed;
|
|
19
19
|
});
|
|
20
20
|
const result = dereffed.reduce((acc, decomposed) => {
|
|
21
|
-
const merged = mergeCrossProduct({
|
|
21
|
+
const merged = mergeCrossProduct({
|
|
22
|
+
first: acc,
|
|
23
|
+
second: decomposed,
|
|
24
|
+
getRef,
|
|
25
|
+
normalize,
|
|
26
|
+
groupType
|
|
27
|
+
});
|
|
22
28
|
return merged;
|
|
23
29
|
}, {});
|
|
24
30
|
const output = {
|
|
@@ -28,13 +34,21 @@ export const mergeUnion = ({ schema, getRef, groupType }) => {
|
|
|
28
34
|
};
|
|
29
35
|
return output;
|
|
30
36
|
};
|
|
31
|
-
export const mergeCrossProduct = ({ first, second, getRef, groupType }) => {
|
|
32
|
-
const
|
|
33
|
-
const
|
|
37
|
+
export const mergeCrossProduct = ({ first, second, getRef, normalize, groupType }) => {
|
|
38
|
+
const firstMembers = Array.isArray(first[groupType]) ? first[groupType] : [first];
|
|
39
|
+
const secondMembers = Array.isArray(second[groupType]) ? second[groupType] : [second];
|
|
40
|
+
// A member that normalizes to exactly `{ nullable: true }` is a null-only
|
|
41
|
+
// member: it makes the union nullable instead of joining the cross product.
|
|
42
|
+
const firstGroup = firstMembers.filter(member => !isNullableOnly(member, normalize));
|
|
43
|
+
const secondGroup = secondMembers.filter(member => !isNullableOnly(member, normalize));
|
|
44
|
+
const nullable = isNullableGroup(first, groupType) ||
|
|
45
|
+
isNullableGroup(second, groupType) ||
|
|
46
|
+
firstGroup.length !== firstMembers.length ||
|
|
47
|
+
secondGroup.length !== secondMembers.length;
|
|
34
48
|
const mergedGroup = crossProduct(firstGroup, secondGroup)
|
|
35
49
|
.map(([firstItem, secondItem]) => {
|
|
36
50
|
try {
|
|
37
|
-
const result = mergeSchemasOrRefs(firstItem, secondItem, getRef);
|
|
51
|
+
const result = mergeSchemasOrRefs(firstItem, secondItem, getRef, normalize);
|
|
38
52
|
return result;
|
|
39
53
|
}
|
|
40
54
|
catch (_error) {
|
|
@@ -48,6 +62,16 @@ export const mergeCrossProduct = ({ first, second, getRef, groupType }) => {
|
|
|
48
62
|
return item[groupType];
|
|
49
63
|
}
|
|
50
64
|
return [item];
|
|
51
|
-
})
|
|
65
|
+
}),
|
|
66
|
+
...(nullable ? { nullable: true } : {})
|
|
52
67
|
};
|
|
53
68
|
};
|
|
69
|
+
const isNullableOnly = (member, normalize) => {
|
|
70
|
+
if (isRef(member)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
const normalized = normalize(member);
|
|
74
|
+
return normalized.nullable === true && Object.keys(normalized).length === 1;
|
|
75
|
+
};
|
|
76
|
+
/** Is this a `oneOf`/`anyOf` group wrapper that already carries `nullable`? */
|
|
77
|
+
const isNullableGroup = (schema, groupType) => Array.isArray(schema[groupType]) && schema.nullable === true;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { SchemaOrReference, GetRefFn } from './types.js';
|
|
2
|
-
export declare const mergeSchemasOrRefs: (
|
|
1
|
+
import type { SchemaOrReference, GetRefFn, NormalizeFn } from './types.js';
|
|
2
|
+
export declare const mergeSchemasOrRefs: (inputFirst: SchemaOrReference, inputSecond: SchemaOrReference, getRef: GetRefFn, normalize: NormalizeFn) => SchemaOrReference;
|
|
@@ -17,9 +17,11 @@ import { mergeIntersection } from './merge-intersection.js';
|
|
|
17
17
|
import { mergeCrossProduct } from './merge-union.js';
|
|
18
18
|
import { isEmpty } from '../../../helpers/isEmpty.js';
|
|
19
19
|
import { isNullOnly, mergeNullOnly } from './nullable-merge.js';
|
|
20
|
-
export const mergeSchemasOrRefs = (
|
|
20
|
+
export const mergeSchemasOrRefs = (inputFirst, inputSecond, getRef, normalize) => {
|
|
21
|
+
const first = isRef(inputFirst) ? inputFirst : normalize(inputFirst);
|
|
22
|
+
const second = isRef(inputSecond) ? inputSecond : normalize(inputSecond);
|
|
21
23
|
if (containsRef(first, second)) {
|
|
22
|
-
return mergeWithRef(first, second, getRef);
|
|
24
|
+
return mergeWithRef(first, second, getRef, normalize);
|
|
23
25
|
}
|
|
24
26
|
if (isRef(first)) {
|
|
25
27
|
throw new Error('Ref in first');
|
|
@@ -28,17 +30,19 @@ export const mergeSchemasOrRefs = (first, second, getRef) => {
|
|
|
28
30
|
throw new Error('Ref in second');
|
|
29
31
|
}
|
|
30
32
|
if (containsAllOf(first) || containsAllOf(second)) {
|
|
31
|
-
const mergedFirst = containsAllOf(first)
|
|
33
|
+
const mergedFirst = containsAllOf(first)
|
|
34
|
+
? mergeIntersection({ schema: first, getRef, normalize })
|
|
35
|
+
: first;
|
|
32
36
|
const mergedSecond = containsAllOf(second)
|
|
33
|
-
? mergeIntersection({ schema: second, getRef })
|
|
37
|
+
? mergeIntersection({ schema: second, getRef, normalize })
|
|
34
38
|
: second;
|
|
35
|
-
return mergeSchemasOrRefs(mergedFirst, mergedSecond, getRef);
|
|
39
|
+
return mergeSchemasOrRefs(mergedFirst, mergedSecond, getRef, normalize);
|
|
36
40
|
}
|
|
37
41
|
if (containsOneOf(first, second)) {
|
|
38
|
-
return mergeCrossProduct({ first, second, getRef, groupType: 'oneOf' });
|
|
42
|
+
return mergeCrossProduct({ first, second, getRef, normalize, groupType: 'oneOf' });
|
|
39
43
|
}
|
|
40
44
|
if (containsAnyOf(first, second)) {
|
|
41
|
-
return mergeCrossProduct({ first, second, getRef, groupType: 'anyOf' });
|
|
45
|
+
return mergeCrossProduct({ first, second, getRef, normalize, groupType: 'anyOf' });
|
|
42
46
|
}
|
|
43
47
|
if (isNullOnly(first)) {
|
|
44
48
|
return mergeNullOnly(second);
|
|
@@ -46,7 +50,7 @@ export const mergeSchemasOrRefs = (first, second, getRef) => {
|
|
|
46
50
|
if (isNullOnly(second)) {
|
|
47
51
|
return mergeNullOnly(first);
|
|
48
52
|
}
|
|
49
|
-
return mergeSchemas(first, second, getRef);
|
|
53
|
+
return mergeSchemas(first, second, getRef, normalize);
|
|
50
54
|
};
|
|
51
55
|
const containsAllOf = (schema) => {
|
|
52
56
|
if (schema.allOf) {
|
|
@@ -90,7 +94,7 @@ const containsOneOf = (first, second) => {
|
|
|
90
94
|
const containsRef = (first, second) => {
|
|
91
95
|
return isRef(first) || isRef(second);
|
|
92
96
|
};
|
|
93
|
-
const mergeSchemas = (first, second, getRef) => {
|
|
97
|
+
const mergeSchemas = (first, second, getRef, normalize) => {
|
|
94
98
|
try {
|
|
95
99
|
checkTypeConflicts(first, second);
|
|
96
100
|
}
|
|
@@ -101,37 +105,38 @@ const mergeSchemas = (first, second, getRef) => {
|
|
|
101
105
|
checkFormatConflicts(first, second);
|
|
102
106
|
checkEnumConflicts(first, second);
|
|
103
107
|
checkNumberConstraintsConflicts(first, second);
|
|
104
|
-
checkArrayItemTypeConflicts(first, second);
|
|
108
|
+
checkArrayItemTypeConflicts(first, second, normalize);
|
|
105
109
|
if (first.not || second.not) {
|
|
106
110
|
throw new Error('Merging schemas with "not" keyword is not supported');
|
|
107
111
|
}
|
|
108
|
-
return typedMerge(first, second, getRef);
|
|
112
|
+
return typedMerge(first, second, getRef, normalize);
|
|
109
113
|
};
|
|
110
|
-
const typedMerge = (first, second, getRef) => {
|
|
114
|
+
const typedMerge = (first, second, getRef, normalize) => {
|
|
111
115
|
if (!first.type && !second.type) {
|
|
112
|
-
return genericMerge(first, second, getRef);
|
|
116
|
+
return genericMerge(first, second, getRef, normalize);
|
|
113
117
|
}
|
|
114
118
|
if (checkAtLeastOneTypeMatch(first, second, 'object')) {
|
|
115
|
-
return mergeObjectConstraints(first, second, getRef);
|
|
119
|
+
return mergeObjectConstraints(first, second, getRef, normalize);
|
|
116
120
|
}
|
|
117
121
|
if (checkAtLeastOneTypeMatch(first, second, 'array')) {
|
|
118
|
-
return mergeArrayConstraints(first, second, getRef);
|
|
122
|
+
return mergeArrayConstraints(first, second, getRef, normalize);
|
|
119
123
|
}
|
|
120
124
|
if (checkAtLeastOneTypeMatch(first, second, 'string')) {
|
|
121
|
-
return mergeStringConstraints(first, second, getRef);
|
|
125
|
+
return mergeStringConstraints(first, second, getRef, normalize);
|
|
122
126
|
}
|
|
123
127
|
if (checkAtLeastOneTypeMatch(first, second, 'number')) {
|
|
124
|
-
return mergeNumberConstraints(first, second, getRef);
|
|
128
|
+
return mergeNumberConstraints(first, second, getRef, normalize);
|
|
125
129
|
}
|
|
126
130
|
if (checkAtLeastOneTypeMatch(first, second, 'integer')) {
|
|
127
|
-
return mergeIntegerConstraints(first, second, getRef);
|
|
131
|
+
return mergeIntegerConstraints(first, second, getRef, normalize);
|
|
128
132
|
}
|
|
129
133
|
if (checkAtLeastOneTypeMatch(first, second, 'boolean')) {
|
|
130
|
-
return mergeBooleanConstraints(first, second, getRef);
|
|
134
|
+
return mergeBooleanConstraints(first, second, getRef, normalize);
|
|
131
135
|
}
|
|
132
136
|
throw new Error(`Cannot merge schemas with type "${first.type}" with type "${second.type}"`);
|
|
133
137
|
};
|
|
134
|
-
const mergeWithRef = (first, second, getRef) => {
|
|
138
|
+
const mergeWithRef = (first, second, getRef, normalize) => {
|
|
139
|
+
const readRef = (ref) => normalize(getRef(ref));
|
|
135
140
|
if (isRef(first) && isRef(second)) {
|
|
136
141
|
if (first.$ref === second.$ref) {
|
|
137
142
|
return {
|
|
@@ -140,15 +145,15 @@ const mergeWithRef = (first, second, getRef) => {
|
|
|
140
145
|
};
|
|
141
146
|
}
|
|
142
147
|
else {
|
|
143
|
-
return mergeSchemas(
|
|
148
|
+
return mergeSchemas(readRef(first), readRef(second), getRef, normalize);
|
|
144
149
|
}
|
|
145
150
|
}
|
|
146
151
|
if (isRef(first) && !isRef(second)) {
|
|
147
|
-
const merged = isEmpty(second) ? first : mergeSchemas(
|
|
152
|
+
const merged = isEmpty(second) ? first : mergeSchemas(readRef(first), second, getRef, normalize);
|
|
148
153
|
return merged;
|
|
149
154
|
}
|
|
150
155
|
if (!isRef(first) && isRef(second)) {
|
|
151
|
-
const merged = isEmpty(first) ? second : mergeSchemas(first,
|
|
156
|
+
const merged = isEmpty(first) ? second : mergeSchemas(first, readRef(second), getRef, normalize);
|
|
152
157
|
return merged;
|
|
153
158
|
}
|
|
154
159
|
throw new Error('Invalid input');
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
2
2
|
import * as v from 'valibot';
|
|
3
3
|
export type GetRefFn = (ref: OpenAPIV3.ReferenceObject) => OpenAPIV3.SchemaObject;
|
|
4
|
+
/**
|
|
5
|
+
* Maps a schema the merge reads (a member, a nested property or item schema,
|
|
6
|
+
* a `$ref` target) onto the shape the merge understands. The caller supplies
|
|
7
|
+
* it, so the merge holds no dialect rules of its own. Must be idempotent.
|
|
8
|
+
*/
|
|
9
|
+
export type NormalizeFn = (schema: OpenAPIV3.SchemaObject) => OpenAPIV3.SchemaObject;
|
|
4
10
|
export type OneOfObject = {
|
|
5
11
|
oneOf?: (OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject)[];
|
|
6
12
|
} & OpenAPIV3.SchemaObject;
|
|
@@ -110,8 +110,7 @@ export const toOperationsV3 = ({ paths, stackTrail, context }) => {
|
|
|
110
110
|
}
|
|
111
111
|
catch (error) {
|
|
112
112
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
113
|
-
context.
|
|
114
|
-
key: method,
|
|
113
|
+
context.logIssueNoKey({
|
|
115
114
|
parent: operation,
|
|
116
115
|
level: 'error',
|
|
117
116
|
message: normalized.message,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { OpenAPIV3 } from 'openapi-types';
|
|
2
|
+
/**
|
|
3
|
+
* Map the 3.1-only schema-shape encodings onto the shared IR shape before
|
|
4
|
+
* dispatching: `unevaluatedProperties`, type arrays, `const`, `examples[]`,
|
|
5
|
+
* numeric exclusive bounds, and binary/base64 content keywords. Each step
|
|
6
|
+
* returns its input unchanged when it does not apply, so the composed result
|
|
7
|
+
* is referentially equal to `schema` when nothing matched — letting the
|
|
8
|
+
* dispatcher re-dispatch only when needed. Idempotent: a normalized schema
|
|
9
|
+
* comes back as the same object.
|
|
10
|
+
*/
|
|
11
|
+
export declare const normalizeSchemaShape: (schema: OpenAPIV3.SchemaObject) => OpenAPIV3.SchemaObject;
|
|
12
|
+
/**
|
|
13
|
+
* Is `type` only `null` (`'null'` or `['null']`)? `'null'` is a 3.1 type the
|
|
14
|
+
* 3.0-typed SchemaObject does not model, so read it loosely.
|
|
15
|
+
*/
|
|
16
|
+
export declare const isNullOnlyType: (type: unknown) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Normalize a schema as it enters the `allOf`/`oneOf`/`anyOf` merge: the
|
|
19
|
+
* {@link normalizeSchemaShape} rules, plus a null-only member (`type: 'null'`
|
|
20
|
+
* or `['null']`) becomes `{ nullable: true }` with no `type`, so it adds
|
|
21
|
+
* nullability instead of conflicting with the other members' types.
|
|
22
|
+
* Idempotent, like `normalizeSchemaShape`.
|
|
23
|
+
*/
|
|
24
|
+
export declare const normalizeMergeMember: (schema: OpenAPIV3.SchemaObject) => OpenAPIV3.SchemaObject;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAPI 3.1 lets a schema's `type` be an ARRAY (e.g. `['string', 'null']`),
|
|
3
|
+
* which the shared IR — modelling a single `type` plus a `nullable` flag —
|
|
4
|
+
* does not. Normalize the array form into shapes the rest of the dispatcher
|
|
5
|
+
* already understands:
|
|
6
|
+
*
|
|
7
|
+
* - `['T', 'null']` (one non-null type) → `{ type: 'T', nullable: true }`.
|
|
8
|
+
* An array type without `items` keeps `items` absent (unknown items).
|
|
9
|
+
* - `['T1', 'T2', …]` (several non-null) → a `oneOf` of the bare types,
|
|
10
|
+
* i.e. the 3.1 multi-type union. 3.0 cannot express this — it is the
|
|
11
|
+
* CASE-2 gap where the v3-0 parser degrades to OasUnknown.
|
|
12
|
+
* - `['null']` (only null) → left unchanged → OasUnknown,
|
|
13
|
+
* since there is no first-class OasNull IR node yet (a documented gap).
|
|
14
|
+
* Inside a merge, {@link normalizeMergeMember} handles it.
|
|
15
|
+
*
|
|
16
|
+
* The hoisted `nullable` flag is the IR's representation of nullability; the
|
|
17
|
+
* leaf parsers read it via `parseNullable`. A non-array `type` passes through.
|
|
18
|
+
*/
|
|
19
|
+
const normalizeTypeArray = (schema) => {
|
|
20
|
+
const rawType = schema.type;
|
|
21
|
+
if (!Array.isArray(rawType)) {
|
|
22
|
+
return schema;
|
|
23
|
+
}
|
|
24
|
+
const members = rawType.filter(member => member !== 'null');
|
|
25
|
+
const nullable = rawType.length !== members.length || schema.nullable;
|
|
26
|
+
// Only `null` (`type: ['null']`): no OasNull node yet — fall through.
|
|
27
|
+
if (members.length === 0) {
|
|
28
|
+
return schema;
|
|
29
|
+
}
|
|
30
|
+
// Several non-null types: a 3.1 multi-type union. Model it as a `oneOf`
|
|
31
|
+
// of the bare types and let the oneOf branch build the OasUnion.
|
|
32
|
+
if (members.length > 1) {
|
|
33
|
+
const { type: _type, ...rest } = schema;
|
|
34
|
+
return { ...rest, nullable, oneOf: members.map(member => ({ type: member })) };
|
|
35
|
+
}
|
|
36
|
+
// Exactly one non-null type: dispatch as that type, carrying nullability.
|
|
37
|
+
switch (members[0]) {
|
|
38
|
+
case 'object':
|
|
39
|
+
case 'integer':
|
|
40
|
+
case 'number':
|
|
41
|
+
case 'boolean':
|
|
42
|
+
case 'string':
|
|
43
|
+
case 'array':
|
|
44
|
+
return { ...schema, type: members[0], nullable };
|
|
45
|
+
default:
|
|
46
|
+
return schema;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* OpenAPI 3.1 `const: X` is the single-value form of `enum` (3.0 expresses a
|
|
51
|
+
* literal as a one-element `enum`). Rewrite it so the existing enum-aware leaf
|
|
52
|
+
* parsers handle it; matches down-convert's `convertConstToEnum`, so a 3.0
|
|
53
|
+
* `enum:[X]` and a 3.1 `const:X` land on the same IR.
|
|
54
|
+
*/
|
|
55
|
+
const normalizeConst = (schema) => {
|
|
56
|
+
if (!('const' in schema)) {
|
|
57
|
+
return schema;
|
|
58
|
+
}
|
|
59
|
+
// `const` is a 3.1 keyword the 3.0-typed SchemaObject does not model; read
|
|
60
|
+
// it via an annotated destructure rather than a cast.
|
|
61
|
+
const { const: constValue, ...rest } = schema;
|
|
62
|
+
return { ...rest, enum: [constValue] };
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* OpenAPI 3.1 schemas carry `examples` (an array, JSON Schema 2020-12); 3.0
|
|
66
|
+
* and the IR use a single `example`. Adopt the first array element as the IR
|
|
67
|
+
* `example` when no singular `example` is set, and drop the array. Matches
|
|
68
|
+
* down-convert's `convertJsonSchemaExamples`.
|
|
69
|
+
*/
|
|
70
|
+
const normalizeExamples = (schema) => {
|
|
71
|
+
if ('example' in schema || !('examples' in schema)) {
|
|
72
|
+
return schema;
|
|
73
|
+
}
|
|
74
|
+
// `examples` is a 3.1 keyword the 3.0-typed SchemaObject does not model.
|
|
75
|
+
const { examples, ...rest } = schema;
|
|
76
|
+
if (!Array.isArray(examples) || examples.length === 0) {
|
|
77
|
+
return rest;
|
|
78
|
+
}
|
|
79
|
+
return { ...rest, example: examples[0] };
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* OpenAPI 3.1 expresses exclusive bounds as NUMBERS (`exclusiveMinimum: 5`
|
|
83
|
+
* means "> 5"); the shared IR (and 3.0) model them as a boolean flag paired
|
|
84
|
+
* with `minimum`/`maximum`. Convert the numeric form so the number/integer
|
|
85
|
+
* leaves validate. Matches down-convert's `convertExclusiveMinMax`, so a 3.0
|
|
86
|
+
* `{minimum:5, exclusiveMinimum:true}` and a 3.1 `{exclusiveMinimum:5}` land
|
|
87
|
+
* on the same IR.
|
|
88
|
+
*/
|
|
89
|
+
const normalizeExclusiveBounds = (schema) => {
|
|
90
|
+
// `exclusiveMinimum`/`exclusiveMaximum` are 3.0-typed boolean here; in 3.1
|
|
91
|
+
// they arrive as numbers, so read them loosely.
|
|
92
|
+
const exclusiveMinimum = schema.exclusiveMinimum;
|
|
93
|
+
const exclusiveMaximum = schema.exclusiveMaximum;
|
|
94
|
+
if (typeof exclusiveMinimum !== 'number' && typeof exclusiveMaximum !== 'number') {
|
|
95
|
+
return schema;
|
|
96
|
+
}
|
|
97
|
+
const next = { ...schema };
|
|
98
|
+
if (typeof exclusiveMinimum === 'number') {
|
|
99
|
+
next.minimum = exclusiveMinimum;
|
|
100
|
+
next.exclusiveMinimum = true;
|
|
101
|
+
}
|
|
102
|
+
if (typeof exclusiveMaximum === 'number') {
|
|
103
|
+
next.maximum = exclusiveMaximum;
|
|
104
|
+
next.exclusiveMaximum = true;
|
|
105
|
+
}
|
|
106
|
+
return next;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* OpenAPI 3.1 / JSON Schema 2020-12 expresses a binary string payload with
|
|
110
|
+
* `contentMediaType: 'application/octet-stream'` and base64 with
|
|
111
|
+
* `contentEncoding: 'base64'`; the shared IR (and 3.0) carry these as a string
|
|
112
|
+
* `format` (`binary` / `byte`, both in the format allow-list). Map them so the
|
|
113
|
+
* format reaches the IR. Mirrors down-convert's
|
|
114
|
+
* `convertJsonSchemaContentMediaType` / `convertJsonSchemaContentEncoding`:
|
|
115
|
+
* string schemas only, and a pre-existing (conflicting) `format` wins — the
|
|
116
|
+
* content keyword is dropped, not overwritten. Without this, retiring
|
|
117
|
+
* down-convert would silently lose the `format` signal on 3.1 binary uploads.
|
|
118
|
+
*/
|
|
119
|
+
const normalizeContentFormat = (schema) => {
|
|
120
|
+
if (schema.type !== 'string') {
|
|
121
|
+
return schema;
|
|
122
|
+
}
|
|
123
|
+
// `contentMediaType`/`contentEncoding` are 3.1 keywords the 3.0-typed
|
|
124
|
+
// SchemaObject does not model; read them loosely.
|
|
125
|
+
const view = schema;
|
|
126
|
+
const derivedFormat = view.contentMediaType === 'application/octet-stream'
|
|
127
|
+
? 'binary'
|
|
128
|
+
: view.contentEncoding === 'base64'
|
|
129
|
+
? 'byte'
|
|
130
|
+
: undefined;
|
|
131
|
+
if (derivedFormat === undefined) {
|
|
132
|
+
return schema;
|
|
133
|
+
}
|
|
134
|
+
const { contentMediaType: _contentMediaType, contentEncoding: _contentEncoding, ...rest } = view;
|
|
135
|
+
return 'format' in rest ? rest : { ...rest, format: derivedFormat };
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* In-place applicators that evaluate keys `unevaluatedProperties` would
|
|
139
|
+
* otherwise see. `$ref` never reaches `normalizeSchemaShape`, and both the
|
|
140
|
+
* dispatcher and the merge refuse a schema with `not`.
|
|
141
|
+
*/
|
|
142
|
+
const inPlaceApplicators = [
|
|
143
|
+
'allOf',
|
|
144
|
+
'oneOf',
|
|
145
|
+
'anyOf',
|
|
146
|
+
'if',
|
|
147
|
+
'then',
|
|
148
|
+
'else',
|
|
149
|
+
'dependentSchemas',
|
|
150
|
+
'$dynamicRef'
|
|
151
|
+
];
|
|
152
|
+
/**
|
|
153
|
+
* With no in-place applicator on the same schema, `unevaluatedProperties`
|
|
154
|
+
* means the same as `additionalProperties` (JSON Schema 2020-12 §11.3,
|
|
155
|
+
* §10.3.2.3), so rename it. When `additionalProperties` is also present it
|
|
156
|
+
* evaluates every remaining key, so `unevaluatedProperties` is dropped.
|
|
157
|
+
*/
|
|
158
|
+
const normalizeUnevaluatedProperties = (schema) => {
|
|
159
|
+
if (!('unevaluatedProperties' in schema)) {
|
|
160
|
+
return schema;
|
|
161
|
+
}
|
|
162
|
+
if (inPlaceApplicators.some(keyword => keyword in schema)) {
|
|
163
|
+
return schema;
|
|
164
|
+
}
|
|
165
|
+
// `unevaluatedProperties` is a 3.1 keyword the 3.0-typed SchemaObject does
|
|
166
|
+
// not model; read it via an annotated destructure.
|
|
167
|
+
const { unevaluatedProperties, ...rest } = schema;
|
|
168
|
+
if ('additionalProperties' in rest) {
|
|
169
|
+
return rest;
|
|
170
|
+
}
|
|
171
|
+
if (!isAdditionalPropertiesValue(unevaluatedProperties)) {
|
|
172
|
+
return schema;
|
|
173
|
+
}
|
|
174
|
+
return { ...rest, additionalProperties: unevaluatedProperties };
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Is this a value `additionalProperties` accepts: a boolean, or a schema or
|
|
178
|
+
* `$ref` object?
|
|
179
|
+
*/
|
|
180
|
+
const isAdditionalPropertiesValue = (value) => typeof value === 'boolean' ||
|
|
181
|
+
(typeof value === 'object' && value !== null && !Array.isArray(value));
|
|
182
|
+
/**
|
|
183
|
+
* Map the 3.1-only schema-shape encodings onto the shared IR shape before
|
|
184
|
+
* dispatching: `unevaluatedProperties`, type arrays, `const`, `examples[]`,
|
|
185
|
+
* numeric exclusive bounds, and binary/base64 content keywords. Each step
|
|
186
|
+
* returns its input unchanged when it does not apply, so the composed result
|
|
187
|
+
* is referentially equal to `schema` when nothing matched — letting the
|
|
188
|
+
* dispatcher re-dispatch only when needed. Idempotent: a normalized schema
|
|
189
|
+
* comes back as the same object.
|
|
190
|
+
*/
|
|
191
|
+
export const normalizeSchemaShape = (schema) => {
|
|
192
|
+
return normalizeExclusiveBounds(normalizeExamples(normalizeConst(normalizeContentFormat(normalizeTypeArray(normalizeUnevaluatedProperties(schema))))));
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Is `type` only `null` (`'null'` or `['null']`)? `'null'` is a 3.1 type the
|
|
196
|
+
* 3.0-typed SchemaObject does not model, so read it loosely.
|
|
197
|
+
*/
|
|
198
|
+
export const isNullOnlyType = (type) => type === 'null' || (Array.isArray(type) && type.length > 0 && type.every(item => item === 'null'));
|
|
199
|
+
/**
|
|
200
|
+
* Normalize a schema as it enters the `allOf`/`oneOf`/`anyOf` merge: the
|
|
201
|
+
* {@link normalizeSchemaShape} rules, plus a null-only member (`type: 'null'`
|
|
202
|
+
* or `['null']`) becomes `{ nullable: true }` with no `type`, so it adds
|
|
203
|
+
* nullability instead of conflicting with the other members' types.
|
|
204
|
+
* Idempotent, like `normalizeSchemaShape`.
|
|
205
|
+
*/
|
|
206
|
+
export const normalizeMergeMember = (schema) => {
|
|
207
|
+
const normalized = normalizeSchemaShape(schema);
|
|
208
|
+
if (!isNullOnlyType(normalized.type)) {
|
|
209
|
+
return normalized;
|
|
210
|
+
}
|
|
211
|
+
const { type: _type, ...rest } = normalized;
|
|
212
|
+
return { ...rest, nullable: true };
|
|
213
|
+
};
|