@skmtc/core 0.45.0 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/anchors/attribute.js +3 -2
- package/esm/context/CoreContext.d.ts +1 -1
- package/esm/context/CoreContext.js +1 -1
- package/esm/context/GenerateContext.d.ts +13 -10
- package/esm/context/GenerateContext.js +36 -25
- package/esm/context/ParseContext.d.ts +3 -0
- package/esm/context/ParseContext.js +151 -39
- package/esm/context/generateTypes.d.ts +7 -6
- package/esm/dsl/GeneratorKeys.d.ts +21 -15
- package/esm/dsl/GeneratorKeys.js +16 -11
- package/esm/dsl/Inserted.d.ts +1 -1
- package/esm/dsl/Inserted.js +1 -1
- package/esm/dsl/model/ModelDriver.d.ts +6 -5
- package/esm/dsl/model/ModelDriver.js +22 -20
- package/esm/dsl/model/toModelEntry.d.ts +18 -18
- package/esm/dsl/model/toModelEntry.js +9 -9
- package/esm/dsl/model/toModelProjectionBase.d.ts +17 -16
- package/esm/dsl/model/toModelProjectionBase.js +12 -8
- package/esm/dsl/model/types.d.ts +26 -17
- package/esm/dsl/operation/gql/toGqlOperationProjectionBase.d.ts +2 -2
- package/esm/dsl/operation/gql/toGqlOperationProjectionBase.js +2 -2
- package/esm/dsl/operation/oas/toOasOperationProjectionBase.d.ts +2 -2
- package/esm/dsl/operation/oas/toOasOperationProjectionBase.js +2 -2
- package/esm/dsl/webhook/toWebhookProjectionBase.d.ts +2 -2
- package/esm/dsl/webhook/toWebhookProjectionBase.js +2 -2
- package/esm/helpers/collateExamples.js +35 -17
- package/esm/helpers/refFns.d.ts +108 -43
- package/esm/helpers/refFns.js +166 -57
- package/esm/mod.d.ts +1 -0
- package/esm/mod.js +1 -0
- package/esm/oas/document/Document.d.ts +6 -0
- package/esm/oas/document/Document.js +44 -2
- package/esm/oas/intersection/Intersection.d.ts +122 -0
- package/esm/oas/intersection/Intersection.js +266 -0
- package/esm/oas/mediaType/jsonMediaType.d.ts +1 -1
- package/esm/oas/mediaType/jsonMediaType.js +3 -3
- package/esm/oas/ref/DanglingRefError.d.ts +5 -2
- package/esm/oas/ref/DanglingRefError.js +4 -3
- package/esm/oas/ref/Ref.d.ts +23 -12
- package/esm/oas/ref/Ref.js +68 -72
- package/esm/oas/requestBody/RequestBody.d.ts +1 -1
- package/esm/oas/requestBody/RequestBody.js +1 -1
- package/esm/oas/response/Response.d.ts +1 -1
- package/esm/oas/response/Response.js +1 -1
- package/esm/oas/schema/Schema.d.ts +4 -2
- package/esm/oas/schema/siblings.d.ts +10 -2
- package/esm/oas/schema/siblings.js +87 -22
- package/esm/oas/schemaPath/traverseSchema.d.ts +2 -0
- package/esm/oas/schemaPath/traverseSchema.js +51 -5
- package/esm/parse/allOfSystem.d.ts +3 -0
- package/esm/parse/allOfSystem.js +2 -1
- package/esm/parse/keptIntersection.d.ts +53 -0
- package/esm/parse/keptIntersection.js +155 -0
- package/esm/parse/keptRefs.d.ts +23 -0
- package/esm/parse/keptRefs.js +59 -0
- package/esm/parse/toCyclicRefs.d.ts +8 -0
- package/esm/parse/toCyclicRefs.js +126 -0
- package/esm/parse/toDeclaredTypes.d.ts +20 -0
- package/esm/parse/toDeclaredTypes.js +43 -0
- package/esm/parse/v3-0/_merge-all-of/merge-intersection.js +8 -4
- package/esm/parse/v3-0/_merge-all-of/merge-union.js +7 -1
- package/esm/parse/v3-0/_merge-all-of/merge.js +13 -0
- package/esm/parse/v3-0/_merge-all-of/types.d.ts +3 -0
- package/esm/parse/v3-0/intersection/toIntersection.d.ts +12 -0
- package/esm/parse/v3-0/intersection/toIntersection.js +61 -0
- package/esm/parse/v3-0/ref/toRefTargetV3.d.ts +23 -0
- package/esm/parse/v3-0/ref/toRefTargetV3.js +70 -0
- package/esm/parse/v3-0/schema/toSchemasV3.js +13 -1
- package/esm/parse/v3-1/_merge-all-of/merge-intersection.js +8 -4
- package/esm/parse/v3-1/_merge-all-of/merge-union.js +7 -1
- package/esm/parse/v3-1/_merge-all-of/merge.js +13 -0
- package/esm/parse/v3-1/_merge-all-of/types.d.ts +3 -0
- package/esm/parse/v3-1/intersection/toIntersection.d.ts +12 -0
- package/esm/parse/v3-1/intersection/toIntersection.js +61 -0
- package/esm/parse/v3-1/ref/toRefTargetV3.d.ts +23 -0
- package/esm/parse/v3-1/ref/toRefTargetV3.js +70 -0
- package/esm/parse/v3-1/schema/toSchemasV3.js +15 -2
- package/esm/parse/v3-2/_merge-all-of/merge-intersection.js +8 -4
- package/esm/parse/v3-2/_merge-all-of/merge-union.js +7 -1
- package/esm/parse/v3-2/_merge-all-of/merge.js +13 -0
- package/esm/parse/v3-2/_merge-all-of/types.d.ts +3 -0
- package/esm/parse/v3-2/intersection/toIntersection.d.ts +12 -0
- package/esm/parse/v3-2/intersection/toIntersection.js +61 -0
- package/esm/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
- package/esm/parse/v3-2/ref/toRefTargetV3.js +70 -0
- package/esm/parse/v3-2/schema/toSchemasV3.js +15 -2
- package/esm/types/GeneratorType.d.ts +1 -1
- package/esm/types/ProjectionOptions.d.ts +1 -1
- package/esm/types/ProjectionOptions.js +1 -1
- package/esm/types/RefName.d.ts +3 -3
- package/esm/types/Settings.d.ts +9 -0
- package/esm/types/Settings.js +2 -1
- package/esm/types/TypeSystem.d.ts +20 -5
- package/package.json +1 -1
- package/script/anchors/attribute.js +3 -2
- package/script/context/CoreContext.d.ts +1 -1
- package/script/context/CoreContext.js +1 -1
- package/script/context/GenerateContext.d.ts +13 -10
- package/script/context/GenerateContext.js +36 -25
- package/script/context/ParseContext.d.ts +3 -0
- package/script/context/ParseContext.js +150 -38
- package/script/context/generateTypes.d.ts +7 -6
- package/script/dsl/GeneratorKeys.d.ts +21 -15
- package/script/dsl/GeneratorKeys.js +16 -11
- package/script/dsl/Inserted.d.ts +1 -1
- package/script/dsl/Inserted.js +1 -1
- package/script/dsl/model/ModelDriver.d.ts +6 -5
- package/script/dsl/model/ModelDriver.js +22 -20
- package/script/dsl/model/toModelEntry.d.ts +18 -18
- package/script/dsl/model/toModelEntry.js +9 -9
- package/script/dsl/model/toModelProjectionBase.d.ts +17 -16
- package/script/dsl/model/toModelProjectionBase.js +12 -8
- package/script/dsl/model/types.d.ts +26 -17
- package/script/dsl/operation/gql/toGqlOperationProjectionBase.d.ts +2 -2
- package/script/dsl/operation/gql/toGqlOperationProjectionBase.js +2 -2
- package/script/dsl/operation/oas/toOasOperationProjectionBase.d.ts +2 -2
- package/script/dsl/operation/oas/toOasOperationProjectionBase.js +2 -2
- package/script/dsl/webhook/toWebhookProjectionBase.d.ts +2 -2
- package/script/dsl/webhook/toWebhookProjectionBase.js +2 -2
- package/script/helpers/collateExamples.js +35 -17
- package/script/helpers/refFns.d.ts +108 -43
- package/script/helpers/refFns.js +180 -59
- package/script/mod.d.ts +1 -0
- package/script/mod.js +1 -0
- package/script/oas/document/Document.d.ts +6 -0
- package/script/oas/document/Document.js +44 -2
- package/script/oas/intersection/Intersection.d.ts +122 -0
- package/script/oas/intersection/Intersection.js +270 -0
- package/script/oas/mediaType/jsonMediaType.d.ts +1 -1
- package/script/oas/mediaType/jsonMediaType.js +3 -3
- package/script/oas/ref/DanglingRefError.d.ts +5 -2
- package/script/oas/ref/DanglingRefError.js +4 -3
- package/script/oas/ref/Ref.d.ts +23 -12
- package/script/oas/ref/Ref.js +67 -71
- package/script/oas/requestBody/RequestBody.d.ts +1 -1
- package/script/oas/requestBody/RequestBody.js +1 -1
- package/script/oas/response/Response.d.ts +1 -1
- package/script/oas/response/Response.js +1 -1
- package/script/oas/schema/Schema.d.ts +4 -2
- package/script/oas/schema/siblings.d.ts +10 -2
- package/script/oas/schema/siblings.js +89 -23
- package/script/oas/schemaPath/traverseSchema.d.ts +2 -0
- package/script/oas/schemaPath/traverseSchema.js +50 -4
- package/script/parse/allOfSystem.d.ts +3 -0
- package/script/parse/allOfSystem.js +2 -1
- package/script/parse/keptIntersection.d.ts +53 -0
- package/script/parse/keptIntersection.js +164 -0
- package/script/parse/keptRefs.d.ts +23 -0
- package/script/parse/keptRefs.js +63 -0
- package/script/parse/toCyclicRefs.d.ts +8 -0
- package/script/parse/toCyclicRefs.js +130 -0
- package/script/parse/toDeclaredTypes.d.ts +20 -0
- package/script/parse/toDeclaredTypes.js +48 -0
- package/script/parse/v3-0/_merge-all-of/merge-intersection.js +8 -4
- package/script/parse/v3-0/_merge-all-of/merge-union.js +7 -1
- package/script/parse/v3-0/_merge-all-of/merge.js +13 -0
- package/script/parse/v3-0/_merge-all-of/types.d.ts +3 -0
- package/script/parse/v3-0/intersection/toIntersection.d.ts +12 -0
- package/script/parse/v3-0/intersection/toIntersection.js +65 -0
- package/script/parse/v3-0/ref/toRefTargetV3.d.ts +23 -0
- package/script/parse/v3-0/ref/toRefTargetV3.js +74 -0
- package/script/parse/v3-0/schema/toSchemasV3.js +13 -1
- package/script/parse/v3-1/_merge-all-of/merge-intersection.js +8 -4
- package/script/parse/v3-1/_merge-all-of/merge-union.js +7 -1
- package/script/parse/v3-1/_merge-all-of/merge.js +13 -0
- package/script/parse/v3-1/_merge-all-of/types.d.ts +3 -0
- package/script/parse/v3-1/intersection/toIntersection.d.ts +12 -0
- package/script/parse/v3-1/intersection/toIntersection.js +65 -0
- package/script/parse/v3-1/ref/toRefTargetV3.d.ts +23 -0
- package/script/parse/v3-1/ref/toRefTargetV3.js +74 -0
- package/script/parse/v3-1/schema/toSchemasV3.js +15 -2
- package/script/parse/v3-2/_merge-all-of/merge-intersection.js +8 -4
- package/script/parse/v3-2/_merge-all-of/merge-union.js +7 -1
- package/script/parse/v3-2/_merge-all-of/merge.js +13 -0
- package/script/parse/v3-2/_merge-all-of/types.d.ts +3 -0
- package/script/parse/v3-2/intersection/toIntersection.d.ts +12 -0
- package/script/parse/v3-2/intersection/toIntersection.js +65 -0
- package/script/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
- package/script/parse/v3-2/ref/toRefTargetV3.js +74 -0
- package/script/parse/v3-2/schema/toSchemasV3.js +15 -2
- package/script/types/GeneratorType.d.ts +1 -1
- package/script/types/ProjectionOptions.d.ts +1 -1
- package/script/types/ProjectionOptions.js +1 -1
- package/script/types/RefName.d.ts +3 -3
- package/script/types/Settings.d.ts +9 -0
- package/script/types/Settings.js +2 -1
- package/script/types/TypeSystem.d.ts +20 -5
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toIntersection = void 0;
|
|
4
|
+
const Intersection_js_1 = require("../../../oas/intersection/Intersection.js");
|
|
5
|
+
const refFns_js_1 = require("../../../helpers/refFns.js");
|
|
6
|
+
const anyOfSystem_js_1 = require("../../anyOfSystem.js");
|
|
7
|
+
const keptIntersection_js_1 = require("../../keptIntersection.js");
|
|
8
|
+
const toSchemasV3_js_1 = require("../schema/toSchemasV3.js");
|
|
9
|
+
const toUnknown_js_1 = require("../unknown/toUnknown.js");
|
|
10
|
+
const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
|
|
11
|
+
const parseNullable_js_1 = require("../_helpers/parseNullable.js");
|
|
12
|
+
const parseExample_js_1 = require("../_helpers/parseExample.js");
|
|
13
|
+
const parseDefault_js_1 = require("../_helpers/parseDefault.js");
|
|
14
|
+
const toExternalDocs_js_1 = require("../externalDocs/toExternalDocs.js");
|
|
15
|
+
const toIntersection = ({ value, members, stackTrail, context }) => {
|
|
16
|
+
const { nullable, value: valueWithoutNullable } = (0, parseNullable_js_1.parseNullable)({ value, context, stackTrail });
|
|
17
|
+
const { title, description, externalDocs, readOnly, writeOnly, deprecated, example: unparsedExample, default: unparsedDefaultValue, ...skipped } = valueWithoutNullable;
|
|
18
|
+
const example = (0, parseExample_js_1.parseExample)({
|
|
19
|
+
value: unparsedExample,
|
|
20
|
+
context,
|
|
21
|
+
parent: value,
|
|
22
|
+
nullable,
|
|
23
|
+
check: isPresent,
|
|
24
|
+
toMessage: item => `Removed invalid example. Expected a non-null value, got: ${item}`,
|
|
25
|
+
stackTrail
|
|
26
|
+
});
|
|
27
|
+
const defaultValue = (0, parseDefault_js_1.parseDefault)({
|
|
28
|
+
value: unparsedDefaultValue,
|
|
29
|
+
context,
|
|
30
|
+
parent: value,
|
|
31
|
+
nullable,
|
|
32
|
+
check: isPresent,
|
|
33
|
+
toMessage: item => `Removed invalid default. Expected a non-null value, got: ${item}`,
|
|
34
|
+
stackTrail
|
|
35
|
+
});
|
|
36
|
+
const extensionFields = (0, toSpecificationExtensionsV3_js_1.toSpecificationExtensionsV3)({
|
|
37
|
+
skipped,
|
|
38
|
+
parent: value,
|
|
39
|
+
context,
|
|
40
|
+
stackTrail,
|
|
41
|
+
parentType: 'schema:allOf'
|
|
42
|
+
});
|
|
43
|
+
// A member with no shape of its own (`{ description }`) is any value: the
|
|
44
|
+
// parser must not guess a type from its `example`.
|
|
45
|
+
const membersParsed = members.map(keptIntersection_js_1.withKeywordType).map((member, index) => stackTrail.trace(`${index}`, st => (0, refFns_js_1.isRef)(member) || (0, anyOfSystem_js_1.hasShapeKeyword)(member) || 'anyOf' in member || 'not' in member
|
|
46
|
+
? (0, toSchemasV3_js_1.toSchemaV3)({ schema: member, stackTrail: st, context })
|
|
47
|
+
: (0, toUnknown_js_1.toUnknown)({ value: member, stackTrail: st, context })));
|
|
48
|
+
return context.withStackTrail(stackTrail, () => new Intersection_js_1.OasIntersection({
|
|
49
|
+
title,
|
|
50
|
+
description,
|
|
51
|
+
externalDocs: stackTrail.trace('externalDocs', st => (0, toExternalDocs_js_1.toExternalDocs)({ externalDocs, stackTrail: st, context })),
|
|
52
|
+
nullable,
|
|
53
|
+
readOnly,
|
|
54
|
+
writeOnly,
|
|
55
|
+
deprecated,
|
|
56
|
+
default: defaultValue,
|
|
57
|
+
members: membersParsed,
|
|
58
|
+
example,
|
|
59
|
+
extensionFields
|
|
60
|
+
}, context));
|
|
61
|
+
};
|
|
62
|
+
exports.toIntersection = toIntersection;
|
|
63
|
+
// A value matches every member, so without resolving them the most we can
|
|
64
|
+
// check is that a present default/example is not `null` on a non-nullable schema.
|
|
65
|
+
const isPresent = (value) => value !== null && value !== undefined;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ParseContextType } from '../../../context/parseTypes.js';
|
|
2
|
+
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
3
|
+
import type { ComponentsEntry } from '../../../oas/components/Components.js';
|
|
4
|
+
import type { OasRefData } from '../../../oas/ref/ref-types.js';
|
|
5
|
+
/** What {@link toRefTargetV3} parses. */
|
|
6
|
+
export type ToRefTargetArgs = {
|
|
7
|
+
/** The kind of component the ref is written for. */
|
|
8
|
+
refType: OasRefData['refType'];
|
|
9
|
+
/** The last segment of the target's pointer, unescaped: the key it parses under. */
|
|
10
|
+
name: string;
|
|
11
|
+
/** The raw value at the pointer. */
|
|
12
|
+
value: Record<string, unknown>;
|
|
13
|
+
/** The trail of the target's parent, so the target parses at its own position. */
|
|
14
|
+
stackTrail: StackTrail;
|
|
15
|
+
context: ParseContextType;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Parses the target of a ref that does not point at a component
|
|
19
|
+
* (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
|
|
20
|
+
* at its own position, with the parser that components of its kind use. Gives
|
|
21
|
+
* `undefined` when the target does not parse (the parser has logged why).
|
|
22
|
+
*/
|
|
23
|
+
export declare const toRefTargetV3: ({ refType, name, value, stackTrail, context }: ToRefTargetArgs) => ComponentsEntry | undefined;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toRefTargetV3 = void 0;
|
|
4
|
+
const isPlainObject_js_1 = require("../../isPlainObject.js");
|
|
5
|
+
const toSchemasV3_js_1 = require("../schema/toSchemasV3.js");
|
|
6
|
+
const toParameterV3_js_1 = require("../parameter/toParameterV3.js");
|
|
7
|
+
const toResponseV3_js_1 = require("../response/toResponseV3.js");
|
|
8
|
+
const toRequestBodiesV3_js_1 = require("../requestBody/toRequestBodiesV3.js");
|
|
9
|
+
const toHeadersV3_js_1 = require("../header/toHeadersV3.js");
|
|
10
|
+
const toLinksV3_js_1 = require("../link/toLinksV3.js");
|
|
11
|
+
const toExamplesV3_js_1 = require("../example/toExamplesV3.js");
|
|
12
|
+
const toSecuritySchemes_js_1 = require("../securitySchemes/toSecuritySchemes.js");
|
|
13
|
+
const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
|
|
14
|
+
/**
|
|
15
|
+
* The raw value read as the OpenAPI type its parser takes, as the components
|
|
16
|
+
* parser reads `documentObject.components`: the parser checks what it reads.
|
|
17
|
+
*/
|
|
18
|
+
const isRawEntry = (value) => (0, isPlainObject_js_1.isPlainObject)(value);
|
|
19
|
+
/**
|
|
20
|
+
* Parses the target of a ref that does not point at a component
|
|
21
|
+
* (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
|
|
22
|
+
* at its own position, with the parser that components of its kind use. Gives
|
|
23
|
+
* `undefined` when the target does not parse (the parser has logged why).
|
|
24
|
+
*/
|
|
25
|
+
const toRefTargetV3 = ({ refType, name, value, stackTrail, context }) => {
|
|
26
|
+
switch (refType) {
|
|
27
|
+
case 'schema':
|
|
28
|
+
return isRawEntry(value)
|
|
29
|
+
? (0, toSchemasV3_js_1.toOptionalSchemasV3)({ schemas: { [name]: value }, stackTrail, context })?.[name]
|
|
30
|
+
: undefined;
|
|
31
|
+
case 'parameter':
|
|
32
|
+
return isRawEntry(value)
|
|
33
|
+
? (0, toParameterV3_js_1.toOptionalParametersV3)({ parameters: { [name]: value }, stackTrail, context })?.[name]
|
|
34
|
+
: undefined;
|
|
35
|
+
case 'response':
|
|
36
|
+
return isRawEntry(value)
|
|
37
|
+
? (0, toResponseV3_js_1.toOptionalResponsesV3)({ responses: { [name]: value }, stackTrail, context })?.[name]
|
|
38
|
+
: undefined;
|
|
39
|
+
case 'requestBody':
|
|
40
|
+
return isRawEntry(value)
|
|
41
|
+
? (0, toRequestBodiesV3_js_1.toRequestBodiesV3)({ requestBodies: { [name]: value }, stackTrail, context })?.[name]
|
|
42
|
+
: undefined;
|
|
43
|
+
case 'header':
|
|
44
|
+
return isRawEntry(value)
|
|
45
|
+
? (0, toHeadersV3_js_1.toComponentHeadersV3)({ headers: { [name]: value }, stackTrail, context })?.[name]
|
|
46
|
+
: undefined;
|
|
47
|
+
case 'link':
|
|
48
|
+
return isRawEntry(value)
|
|
49
|
+
? (0, toLinksV3_js_1.toLinksV3)({ links: { [name]: value }, stackTrail, context })?.[name]
|
|
50
|
+
: undefined;
|
|
51
|
+
case 'example':
|
|
52
|
+
// No components parser reads a single example by key, so the target
|
|
53
|
+
// is parsed as `toExamplesV3` parses each entry, under `tryParseAt`.
|
|
54
|
+
return isRawEntry(value)
|
|
55
|
+
? (0, tryParseAt_js_1.tryParseAt)({
|
|
56
|
+
stackTrail,
|
|
57
|
+
key: name,
|
|
58
|
+
context,
|
|
59
|
+
type: 'INVALID_EXAMPLE',
|
|
60
|
+
parent: value,
|
|
61
|
+
fn: st => (0, toExamplesV3_js_1.toExampleV3)({ example: value, stackTrail: st, context })
|
|
62
|
+
})
|
|
63
|
+
: undefined;
|
|
64
|
+
case 'securityScheme':
|
|
65
|
+
return isRawEntry(value)
|
|
66
|
+
? (0, toSecuritySchemes_js_1.toSecuritySchemesV3)({ securitySchemes: { [name]: value }, stackTrail, context })?.[name]
|
|
67
|
+
: undefined;
|
|
68
|
+
default: {
|
|
69
|
+
const _exhaustive = refType;
|
|
70
|
+
throw new Error(`Unhandled ref type: ${_exhaustive}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
exports.toRefTargetV3 = toRefTargetV3;
|
|
@@ -13,6 +13,8 @@ const toBoolean_js_1 = require("../boolean/toBoolean.js");
|
|
|
13
13
|
const toString_js_1 = require("../string/toString.js");
|
|
14
14
|
const toUnknown_js_1 = require("../unknown/toUnknown.js");
|
|
15
15
|
const toUnion_js_1 = require("../union/toUnion.js");
|
|
16
|
+
const toIntersection_js_1 = require("../intersection/toIntersection.js");
|
|
17
|
+
const keptIntersection_js_1 = require("../../keptIntersection.js");
|
|
16
18
|
const refFns_js_2 = require("../../../helpers/refFns.js");
|
|
17
19
|
const toSiblingKeywords_js_1 = require("../../toSiblingKeywords.js");
|
|
18
20
|
const allOfSystem_js_1 = require("../../allOfSystem.js");
|
|
@@ -187,7 +189,17 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
187
189
|
});
|
|
188
190
|
(0, allOfSystem_js_1.logAllOfContradictions)({ system, stackTrail, parent: schema, context });
|
|
189
191
|
(0, anyOfSystem_js_1.logMergedUnknownAnyOf)({ system, stackTrail, parent: schema, context });
|
|
190
|
-
|
|
192
|
+
const parts = system.keptRefs && (0, keptIntersection_js_1.toIntersectionParts)(merged, system.keptRefs);
|
|
193
|
+
if (parts === undefined) {
|
|
194
|
+
return (0, exports.toSchemaV3)({ schema: merged, stackTrail: st, context });
|
|
195
|
+
}
|
|
196
|
+
const { own, members: kept } = (0, keptIntersection_js_1.toSiteIntersection)(parts);
|
|
197
|
+
const [only] = kept;
|
|
198
|
+
if (kept.length > 1 || only === undefined) {
|
|
199
|
+
return (0, toIntersection_js_1.toIntersection)({ value: own, members: kept, stackTrail: st, context });
|
|
200
|
+
}
|
|
201
|
+
// An intersection of one ref is that ref with the keywords beside it.
|
|
202
|
+
return (0, exports.toSchemaV3)({ schema: (0, isEmpty_js_1.isEmpty)(own) ? only : { ...own, allOf: [only] }, stackTrail: st, context });
|
|
191
203
|
});
|
|
192
204
|
}
|
|
193
205
|
if ('oneOf' in schema && Array.isArray(schema.oneOf)) {
|
|
@@ -3,18 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.mergeIntersection = void 0;
|
|
4
4
|
const decompose_intersection_js_1 = require("./decompose-intersection.js");
|
|
5
5
|
const merge_js_1 = require("./merge.js");
|
|
6
|
+
const isEmpty_js_1 = require("../../../helpers/isEmpty.js");
|
|
7
|
+
const keptIntersection_js_1 = require("../../keptIntersection.js");
|
|
6
8
|
const mergeIntersection = ({ schema, getRef, normalize, system }) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
// Where a ref stays a ref, the wrapper's own keywords stay beside the `allOf`.
|
|
10
|
+
const { own, rest } = system.keptRefs?.holds(schema) ? (0, keptIntersection_js_1.splitOwnKeywords)(schema) : { own: {}, rest: schema };
|
|
11
|
+
const decomposed = (0, decompose_intersection_js_1.decomposeIntersection)({ schema: rest });
|
|
12
|
+
if (decomposed.length === 1 && (0, isEmpty_js_1.isEmpty)(own)) {
|
|
9
13
|
return decomposed[0];
|
|
10
14
|
}
|
|
11
15
|
const dereffed = decomposed.map(decomposed => {
|
|
12
|
-
return '$ref' in decomposed ? getRef(decomposed) : decomposed;
|
|
16
|
+
return '$ref' in decomposed && !system.keptRefs?.has(decomposed) ? getRef(decomposed) : decomposed;
|
|
13
17
|
});
|
|
14
18
|
const result = dereffed.reduce((acc, decomposed) => {
|
|
15
19
|
const merged = (0, merge_js_1.mergeSchemasOrRefs)({ first: acc, second: decomposed, getRef, normalize, system });
|
|
16
20
|
return merged;
|
|
17
21
|
}, {});
|
|
18
|
-
return result;
|
|
22
|
+
return (0, keptIntersection_js_1.withOwnKeywords)(result, own);
|
|
19
23
|
};
|
|
20
24
|
exports.mergeIntersection = mergeIntersection;
|
|
@@ -106,7 +106,13 @@ const mergeCrossProduct = ({ first, second, getRef, normalize, system, groupType
|
|
|
106
106
|
secondGroup.length !== secondMembers.length;
|
|
107
107
|
const mergedGroup = mergePairs({
|
|
108
108
|
pairs: (0, cross_product_js_1.crossProduct)(withGroupSiblings({ schema: first, members: firstGroup, getRef, normalize, system, groupType }), withGroupSiblings({ schema: second, members: secondGroup, getRef, normalize, system, groupType })),
|
|
109
|
-
merge: ([firstItem, secondItem], pairSystem) =>
|
|
109
|
+
merge: ([firstItem, secondItem], pairSystem) => {
|
|
110
|
+
// A kept ref is not read into the merge, so its type is compared here.
|
|
111
|
+
if (pairSystem.allOf === 'strict' && system.keptRefs?.contradict(firstItem, secondItem)) {
|
|
112
|
+
throw new Error('Cannot merge schemas: a member has another type than the reference');
|
|
113
|
+
}
|
|
114
|
+
return (0, merge_js_1.mergeSchemasOrRefs)({ first: firstItem, second: secondItem, getRef, normalize, system: pairSystem });
|
|
115
|
+
},
|
|
110
116
|
system
|
|
111
117
|
});
|
|
112
118
|
// A nested group is spread into this one below; its `nullable` carries over.
|
|
@@ -20,6 +20,7 @@ const merge_intersection_js_1 = require("./merge-intersection.js");
|
|
|
20
20
|
const merge_union_js_1 = require("./merge-union.js");
|
|
21
21
|
const isEmpty_js_1 = require("../../../helpers/isEmpty.js");
|
|
22
22
|
const nullable_merge_js_1 = require("./nullable-merge.js");
|
|
23
|
+
const keptIntersection_js_1 = require("../../keptIntersection.js");
|
|
23
24
|
const anyOfSystem_js_1 = require("../../anyOfSystem.js");
|
|
24
25
|
const mergeSchemasOrRefs = ({ first: inputFirst, second: inputSecond, getRef, normalize, system }) => {
|
|
25
26
|
const first = (0, refFns_js_1.isRef)(inputFirst)
|
|
@@ -28,6 +29,18 @@ const mergeSchemasOrRefs = ({ first: inputFirst, second: inputSecond, getRef, no
|
|
|
28
29
|
const second = (0, refFns_js_1.isRef)(inputSecond)
|
|
29
30
|
? inputSecond
|
|
30
31
|
: (0, merge_union_js_1.collapseNullOnlyUnion)(normalize(inputSecond), normalize);
|
|
32
|
+
const { keptRefs } = system;
|
|
33
|
+
if (keptRefs && ((0, keptIntersection_js_1.toIntersectionParts)(first, keptRefs) || (0, keptIntersection_js_1.toIntersectionParts)(second, keptRefs))) {
|
|
34
|
+
return (0, keptIntersection_js_1.mergeKept)({
|
|
35
|
+
first,
|
|
36
|
+
second,
|
|
37
|
+
keptRefs,
|
|
38
|
+
merge: (a, b) => (0, exports.mergeSchemasOrRefs)({ first: a, second: b, getRef, normalize, system }),
|
|
39
|
+
mergeAllOf: schema => (0, merge_intersection_js_1.mergeIntersection)({ schema, getRef, normalize, system: (0, merge_union_js_1.toOwnSystem)(system) }),
|
|
40
|
+
readRef: ref => normalize(getRef(ref)),
|
|
41
|
+
normalize
|
|
42
|
+
});
|
|
43
|
+
}
|
|
31
44
|
if (containsRef(first, second)) {
|
|
32
45
|
return mergeWithRef({ first, second, getRef, normalize, system });
|
|
33
46
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
2
2
|
import * as v from 'valibot';
|
|
3
|
+
import type { KeptRefs } from '../../keptRefs.js';
|
|
3
4
|
export type GetRefFn = (ref: OpenAPIV3.ReferenceObject) => OpenAPIV3.SchemaObject;
|
|
4
5
|
/**
|
|
5
6
|
* Maps a schema the merge reads (a member, a nested property or item schema,
|
|
@@ -28,6 +29,8 @@ export type MergeSystem = {
|
|
|
28
29
|
anyOf?: 'union' | 'unknown';
|
|
29
30
|
/** The keywords the merge read as any value: `anyOf` under `system.anyOf: unknown`. */
|
|
30
31
|
unknown?: Set<string>;
|
|
32
|
+
/** The refs that stay refs (`system.intersections`). Left out: every ref is followed. */
|
|
33
|
+
keptRefs?: KeptRefs;
|
|
31
34
|
};
|
|
32
35
|
export type OneOfObject = {
|
|
33
36
|
oneOf?: (OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject)[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { OpenAPIV3 } from 'openapi-types';
|
|
2
|
+
import type { ParseContextType } from '../../../context/parseTypes.js';
|
|
3
|
+
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
4
|
+
import { OasIntersection } from '../../../oas/intersection/Intersection.js';
|
|
5
|
+
export type ToIntersectionArgs = {
|
|
6
|
+
/** The intersection's own keywords, without `allOf`. */
|
|
7
|
+
value: OpenAPIV3.SchemaObject;
|
|
8
|
+
members: (OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject)[];
|
|
9
|
+
stackTrail: StackTrail;
|
|
10
|
+
context: ParseContextType;
|
|
11
|
+
};
|
|
12
|
+
export declare const toIntersection: ({ value, members, stackTrail, context }: ToIntersectionArgs) => OasIntersection;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toIntersection = void 0;
|
|
4
|
+
const Intersection_js_1 = require("../../../oas/intersection/Intersection.js");
|
|
5
|
+
const refFns_js_1 = require("../../../helpers/refFns.js");
|
|
6
|
+
const anyOfSystem_js_1 = require("../../anyOfSystem.js");
|
|
7
|
+
const keptIntersection_js_1 = require("../../keptIntersection.js");
|
|
8
|
+
const toSchemasV3_js_1 = require("../schema/toSchemasV3.js");
|
|
9
|
+
const toUnknown_js_1 = require("../unknown/toUnknown.js");
|
|
10
|
+
const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
|
|
11
|
+
const parseNullable_js_1 = require("../_helpers/parseNullable.js");
|
|
12
|
+
const parseExample_js_1 = require("../_helpers/parseExample.js");
|
|
13
|
+
const parseDefault_js_1 = require("../_helpers/parseDefault.js");
|
|
14
|
+
const toExternalDocs_js_1 = require("../externalDocs/toExternalDocs.js");
|
|
15
|
+
const toIntersection = ({ value, members, stackTrail, context }) => {
|
|
16
|
+
const { nullable, value: valueWithoutNullable } = (0, parseNullable_js_1.parseNullable)({ value, context, stackTrail });
|
|
17
|
+
const { title, description, externalDocs, readOnly, writeOnly, deprecated, example: unparsedExample, default: unparsedDefaultValue, ...skipped } = valueWithoutNullable;
|
|
18
|
+
const example = (0, parseExample_js_1.parseExample)({
|
|
19
|
+
value: unparsedExample,
|
|
20
|
+
context,
|
|
21
|
+
parent: value,
|
|
22
|
+
nullable,
|
|
23
|
+
check: isPresent,
|
|
24
|
+
toMessage: item => `Removed invalid example. Expected a non-null value, got: ${item}`,
|
|
25
|
+
stackTrail
|
|
26
|
+
});
|
|
27
|
+
const defaultValue = (0, parseDefault_js_1.parseDefault)({
|
|
28
|
+
value: unparsedDefaultValue,
|
|
29
|
+
context,
|
|
30
|
+
parent: value,
|
|
31
|
+
nullable,
|
|
32
|
+
check: isPresent,
|
|
33
|
+
toMessage: item => `Removed invalid default. Expected a non-null value, got: ${item}`,
|
|
34
|
+
stackTrail
|
|
35
|
+
});
|
|
36
|
+
const extensionFields = (0, toSpecificationExtensionsV3_js_1.toSpecificationExtensionsV3)({
|
|
37
|
+
skipped,
|
|
38
|
+
parent: value,
|
|
39
|
+
context,
|
|
40
|
+
stackTrail,
|
|
41
|
+
parentType: 'schema:allOf'
|
|
42
|
+
});
|
|
43
|
+
// A member with no shape of its own (`{ description }`) is any value: the
|
|
44
|
+
// parser must not guess a type from its `example`.
|
|
45
|
+
const membersParsed = members.map(keptIntersection_js_1.withKeywordType).map((member, index) => stackTrail.trace(`${index}`, st => (0, refFns_js_1.isRef)(member) || (0, anyOfSystem_js_1.hasShapeKeyword)(member) || 'anyOf' in member || 'not' in member
|
|
46
|
+
? (0, toSchemasV3_js_1.toSchemaV3)({ schema: member, stackTrail: st, context })
|
|
47
|
+
: (0, toUnknown_js_1.toUnknown)({ value: member, stackTrail: st, context })));
|
|
48
|
+
return context.withStackTrail(stackTrail, () => new Intersection_js_1.OasIntersection({
|
|
49
|
+
title,
|
|
50
|
+
description,
|
|
51
|
+
externalDocs: stackTrail.trace('externalDocs', st => (0, toExternalDocs_js_1.toExternalDocs)({ externalDocs, stackTrail: st, context })),
|
|
52
|
+
nullable,
|
|
53
|
+
readOnly,
|
|
54
|
+
writeOnly,
|
|
55
|
+
deprecated,
|
|
56
|
+
default: defaultValue,
|
|
57
|
+
members: membersParsed,
|
|
58
|
+
example,
|
|
59
|
+
extensionFields
|
|
60
|
+
}, context));
|
|
61
|
+
};
|
|
62
|
+
exports.toIntersection = toIntersection;
|
|
63
|
+
// A value matches every member, so without resolving them the most we can
|
|
64
|
+
// check is that a present default/example is not `null` on a non-nullable schema.
|
|
65
|
+
const isPresent = (value) => value !== null && value !== undefined;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ParseContextType } from '../../../context/parseTypes.js';
|
|
2
|
+
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
3
|
+
import type { ComponentsEntry } from '../../../oas/components/Components.js';
|
|
4
|
+
import type { OasRefData } from '../../../oas/ref/ref-types.js';
|
|
5
|
+
/** What {@link toRefTargetV3} parses. */
|
|
6
|
+
export type ToRefTargetArgs = {
|
|
7
|
+
/** The kind of component the ref is written for. */
|
|
8
|
+
refType: OasRefData['refType'];
|
|
9
|
+
/** The last segment of the target's pointer, unescaped: the key it parses under. */
|
|
10
|
+
name: string;
|
|
11
|
+
/** The raw value at the pointer. */
|
|
12
|
+
value: Record<string, unknown>;
|
|
13
|
+
/** The trail of the target's parent, so the target parses at its own position. */
|
|
14
|
+
stackTrail: StackTrail;
|
|
15
|
+
context: ParseContextType;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Parses the target of a ref that does not point at a component
|
|
19
|
+
* (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
|
|
20
|
+
* at its own position, with the parser that components of its kind use. Gives
|
|
21
|
+
* `undefined` when the target does not parse (the parser has logged why).
|
|
22
|
+
*/
|
|
23
|
+
export declare const toRefTargetV3: ({ refType, name, value, stackTrail, context }: ToRefTargetArgs) => ComponentsEntry | undefined;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toRefTargetV3 = void 0;
|
|
4
|
+
const isPlainObject_js_1 = require("../../isPlainObject.js");
|
|
5
|
+
const toSchemasV3_js_1 = require("../schema/toSchemasV3.js");
|
|
6
|
+
const toParameterV3_js_1 = require("../parameter/toParameterV3.js");
|
|
7
|
+
const toResponseV3_js_1 = require("../response/toResponseV3.js");
|
|
8
|
+
const toRequestBodiesV3_js_1 = require("../requestBody/toRequestBodiesV3.js");
|
|
9
|
+
const toHeadersV3_js_1 = require("../header/toHeadersV3.js");
|
|
10
|
+
const toLinksV3_js_1 = require("../link/toLinksV3.js");
|
|
11
|
+
const toExamplesV3_js_1 = require("../example/toExamplesV3.js");
|
|
12
|
+
const toSecuritySchemes_js_1 = require("../securitySchemes/toSecuritySchemes.js");
|
|
13
|
+
const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
|
|
14
|
+
/**
|
|
15
|
+
* The raw value read as the OpenAPI type its parser takes, as the components
|
|
16
|
+
* parser reads `documentObject.components`: the parser checks what it reads.
|
|
17
|
+
*/
|
|
18
|
+
const isRawEntry = (value) => (0, isPlainObject_js_1.isPlainObject)(value);
|
|
19
|
+
/**
|
|
20
|
+
* Parses the target of a ref that does not point at a component
|
|
21
|
+
* (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
|
|
22
|
+
* at its own position, with the parser that components of its kind use. Gives
|
|
23
|
+
* `undefined` when the target does not parse (the parser has logged why).
|
|
24
|
+
*/
|
|
25
|
+
const toRefTargetV3 = ({ refType, name, value, stackTrail, context }) => {
|
|
26
|
+
switch (refType) {
|
|
27
|
+
case 'schema':
|
|
28
|
+
return isRawEntry(value)
|
|
29
|
+
? (0, toSchemasV3_js_1.toOptionalSchemasV3)({ schemas: { [name]: value }, stackTrail, context })?.[name]
|
|
30
|
+
: undefined;
|
|
31
|
+
case 'parameter':
|
|
32
|
+
return isRawEntry(value)
|
|
33
|
+
? (0, toParameterV3_js_1.toOptionalParametersV3)({ parameters: { [name]: value }, stackTrail, context })?.[name]
|
|
34
|
+
: undefined;
|
|
35
|
+
case 'response':
|
|
36
|
+
return isRawEntry(value)
|
|
37
|
+
? (0, toResponseV3_js_1.toOptionalResponsesV3)({ responses: { [name]: value }, stackTrail, context })?.[name]
|
|
38
|
+
: undefined;
|
|
39
|
+
case 'requestBody':
|
|
40
|
+
return isRawEntry(value)
|
|
41
|
+
? (0, toRequestBodiesV3_js_1.toRequestBodiesV3)({ requestBodies: { [name]: value }, stackTrail, context })?.[name]
|
|
42
|
+
: undefined;
|
|
43
|
+
case 'header':
|
|
44
|
+
return isRawEntry(value)
|
|
45
|
+
? (0, toHeadersV3_js_1.toComponentHeadersV3)({ headers: { [name]: value }, stackTrail, context })?.[name]
|
|
46
|
+
: undefined;
|
|
47
|
+
case 'link':
|
|
48
|
+
return isRawEntry(value)
|
|
49
|
+
? (0, toLinksV3_js_1.toLinksV3)({ links: { [name]: value }, stackTrail, context })?.[name]
|
|
50
|
+
: undefined;
|
|
51
|
+
case 'example':
|
|
52
|
+
// No components parser reads a single example by key, so the target
|
|
53
|
+
// is parsed as `toExamplesV3` parses each entry, under `tryParseAt`.
|
|
54
|
+
return isRawEntry(value)
|
|
55
|
+
? (0, tryParseAt_js_1.tryParseAt)({
|
|
56
|
+
stackTrail,
|
|
57
|
+
key: name,
|
|
58
|
+
context,
|
|
59
|
+
type: 'INVALID_EXAMPLE',
|
|
60
|
+
parent: value,
|
|
61
|
+
fn: st => (0, toExamplesV3_js_1.toExampleV3)({ example: value, stackTrail: st, context })
|
|
62
|
+
})
|
|
63
|
+
: undefined;
|
|
64
|
+
case 'securityScheme':
|
|
65
|
+
return isRawEntry(value)
|
|
66
|
+
? (0, toSecuritySchemes_js_1.toSecuritySchemesV3)({ securitySchemes: { [name]: value }, stackTrail, context })?.[name]
|
|
67
|
+
: undefined;
|
|
68
|
+
default: {
|
|
69
|
+
const _exhaustive = refType;
|
|
70
|
+
throw new Error(`Unhandled ref type: ${_exhaustive}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
exports.toRefTargetV3 = toRefTargetV3;
|
|
@@ -13,6 +13,8 @@ const toBoolean_js_1 = require("../boolean/toBoolean.js");
|
|
|
13
13
|
const toString_js_1 = require("../string/toString.js");
|
|
14
14
|
const toUnknown_js_1 = require("../unknown/toUnknown.js");
|
|
15
15
|
const toUnion_js_1 = require("../union/toUnion.js");
|
|
16
|
+
const toIntersection_js_1 = require("../intersection/toIntersection.js");
|
|
17
|
+
const keptIntersection_js_1 = require("../../keptIntersection.js");
|
|
16
18
|
const refFns_js_2 = require("../../../helpers/refFns.js");
|
|
17
19
|
const toSiblingKeywords_js_1 = require("../../toSiblingKeywords.js");
|
|
18
20
|
const allOfSystem_js_1 = require("../../allOfSystem.js");
|
|
@@ -137,8 +139,9 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
137
139
|
});
|
|
138
140
|
}
|
|
139
141
|
const members = Array.isArray(allOf) ? allOf : [];
|
|
142
|
+
const bareRef = context.keptRefs?.copy(schema, { $ref }) ?? { $ref };
|
|
140
143
|
return Object.keys(keywords).length > 0
|
|
141
|
-
? (0, exports.toSchemaV3)({ schema: { ...keywords, allOf: [
|
|
144
|
+
? (0, exports.toSchemaV3)({ schema: { ...keywords, allOf: [bareRef, ...members] }, stackTrail, context })
|
|
142
145
|
: (0, toRefV31_js_1.toRefV31)({ ref: schema, refType: 'schema', stackTrail, context });
|
|
143
146
|
}
|
|
144
147
|
// OpenAPI `not` has no faithful TypeScript representation: a generated type
|
|
@@ -240,7 +243,17 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
240
243
|
});
|
|
241
244
|
(0, allOfSystem_js_1.logAllOfContradictions)({ system, stackTrail, parent: schema, context });
|
|
242
245
|
(0, anyOfSystem_js_1.logMergedUnknownAnyOf)({ system, stackTrail, parent: schema, context });
|
|
243
|
-
|
|
246
|
+
const parts = system.keptRefs && (0, keptIntersection_js_1.toIntersectionParts)(merged, system.keptRefs);
|
|
247
|
+
if (parts === undefined) {
|
|
248
|
+
return (0, exports.toSchemaV3)({ schema: merged, stackTrail: st, context });
|
|
249
|
+
}
|
|
250
|
+
const { own, members: kept } = (0, keptIntersection_js_1.toSiteIntersection)(parts);
|
|
251
|
+
const [only] = kept;
|
|
252
|
+
if (kept.length > 1 || only === undefined) {
|
|
253
|
+
return (0, toIntersection_js_1.toIntersection)({ value: own, members: kept, stackTrail: st, context });
|
|
254
|
+
}
|
|
255
|
+
// An intersection of one ref is that ref with the keywords beside it.
|
|
256
|
+
return (0, exports.toSchemaV3)({ schema: (0, isEmpty_js_1.isEmpty)(own) ? only : { ...own, allOf: [only] }, stackTrail: st, context });
|
|
244
257
|
});
|
|
245
258
|
}
|
|
246
259
|
// A `oneOf`/`anyOf` of only null members reads as nullable, not as an
|
|
@@ -3,18 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.mergeIntersection = void 0;
|
|
4
4
|
const decompose_intersection_js_1 = require("./decompose-intersection.js");
|
|
5
5
|
const merge_js_1 = require("./merge.js");
|
|
6
|
+
const isEmpty_js_1 = require("../../../helpers/isEmpty.js");
|
|
7
|
+
const keptIntersection_js_1 = require("../../keptIntersection.js");
|
|
6
8
|
const mergeIntersection = ({ schema, getRef, normalize, system }) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
// Where a ref stays a ref, the wrapper's own keywords stay beside the `allOf`.
|
|
10
|
+
const { own, rest } = system.keptRefs?.holds(schema) ? (0, keptIntersection_js_1.splitOwnKeywords)(schema) : { own: {}, rest: schema };
|
|
11
|
+
const decomposed = (0, decompose_intersection_js_1.decomposeIntersection)({ schema: rest });
|
|
12
|
+
if (decomposed.length === 1 && (0, isEmpty_js_1.isEmpty)(own)) {
|
|
9
13
|
return decomposed[0];
|
|
10
14
|
}
|
|
11
15
|
const dereffed = decomposed.map(decomposed => {
|
|
12
|
-
return '$ref' in decomposed ? getRef(decomposed) : decomposed;
|
|
16
|
+
return '$ref' in decomposed && !system.keptRefs?.has(decomposed) ? getRef(decomposed) : decomposed;
|
|
13
17
|
});
|
|
14
18
|
const result = dereffed.reduce((acc, decomposed) => {
|
|
15
19
|
const merged = (0, merge_js_1.mergeSchemasOrRefs)({ first: acc, second: decomposed, getRef, normalize, system });
|
|
16
20
|
return merged;
|
|
17
21
|
}, {});
|
|
18
|
-
return result;
|
|
22
|
+
return (0, keptIntersection_js_1.withOwnKeywords)(result, own);
|
|
19
23
|
};
|
|
20
24
|
exports.mergeIntersection = mergeIntersection;
|
|
@@ -106,7 +106,13 @@ const mergeCrossProduct = ({ first, second, getRef, normalize, system, groupType
|
|
|
106
106
|
secondGroup.length !== secondMembers.length;
|
|
107
107
|
const mergedGroup = mergePairs({
|
|
108
108
|
pairs: (0, cross_product_js_1.crossProduct)(withGroupSiblings({ schema: first, members: firstGroup, getRef, normalize, system, groupType }), withGroupSiblings({ schema: second, members: secondGroup, getRef, normalize, system, groupType })),
|
|
109
|
-
merge: ([firstItem, secondItem], pairSystem) =>
|
|
109
|
+
merge: ([firstItem, secondItem], pairSystem) => {
|
|
110
|
+
// A kept ref is not read into the merge, so its type is compared here.
|
|
111
|
+
if (pairSystem.allOf === 'strict' && system.keptRefs?.contradict(firstItem, secondItem)) {
|
|
112
|
+
throw new Error('Cannot merge schemas: a member has another type than the reference');
|
|
113
|
+
}
|
|
114
|
+
return (0, merge_js_1.mergeSchemasOrRefs)({ first: firstItem, second: secondItem, getRef, normalize, system: pairSystem });
|
|
115
|
+
},
|
|
110
116
|
system
|
|
111
117
|
});
|
|
112
118
|
// A nested group is spread into this one below; its `nullable` carries over.
|
|
@@ -20,6 +20,7 @@ const merge_intersection_js_1 = require("./merge-intersection.js");
|
|
|
20
20
|
const merge_union_js_1 = require("./merge-union.js");
|
|
21
21
|
const isEmpty_js_1 = require("../../../helpers/isEmpty.js");
|
|
22
22
|
const nullable_merge_js_1 = require("./nullable-merge.js");
|
|
23
|
+
const keptIntersection_js_1 = require("../../keptIntersection.js");
|
|
23
24
|
const anyOfSystem_js_1 = require("../../anyOfSystem.js");
|
|
24
25
|
const mergeSchemasOrRefs = ({ first: inputFirst, second: inputSecond, getRef, normalize, system }) => {
|
|
25
26
|
const first = (0, refFns_js_1.isRef)(inputFirst)
|
|
@@ -28,6 +29,18 @@ const mergeSchemasOrRefs = ({ first: inputFirst, second: inputSecond, getRef, no
|
|
|
28
29
|
const second = (0, refFns_js_1.isRef)(inputSecond)
|
|
29
30
|
? inputSecond
|
|
30
31
|
: (0, merge_union_js_1.collapseNullOnlyUnion)(normalize(inputSecond), normalize);
|
|
32
|
+
const { keptRefs } = system;
|
|
33
|
+
if (keptRefs && ((0, keptIntersection_js_1.toIntersectionParts)(first, keptRefs) || (0, keptIntersection_js_1.toIntersectionParts)(second, keptRefs))) {
|
|
34
|
+
return (0, keptIntersection_js_1.mergeKept)({
|
|
35
|
+
first,
|
|
36
|
+
second,
|
|
37
|
+
keptRefs,
|
|
38
|
+
merge: (a, b) => (0, exports.mergeSchemasOrRefs)({ first: a, second: b, getRef, normalize, system }),
|
|
39
|
+
mergeAllOf: schema => (0, merge_intersection_js_1.mergeIntersection)({ schema, getRef, normalize, system: (0, merge_union_js_1.toOwnSystem)(system) }),
|
|
40
|
+
readRef: ref => normalize(getRef(ref)),
|
|
41
|
+
normalize
|
|
42
|
+
});
|
|
43
|
+
}
|
|
31
44
|
if (containsRef(first, second)) {
|
|
32
45
|
return mergeWithRef({ first, second, getRef, normalize, system });
|
|
33
46
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
2
2
|
import * as v from 'valibot';
|
|
3
|
+
import type { KeptRefs } from '../../keptRefs.js';
|
|
3
4
|
export type GetRefFn = (ref: OpenAPIV3.ReferenceObject) => OpenAPIV3.SchemaObject;
|
|
4
5
|
/**
|
|
5
6
|
* Maps a schema the merge reads (a member, a nested property or item schema,
|
|
@@ -28,6 +29,8 @@ export type MergeSystem = {
|
|
|
28
29
|
anyOf?: 'union' | 'unknown';
|
|
29
30
|
/** The keywords the merge read as any value: `anyOf` under `system.anyOf: unknown`. */
|
|
30
31
|
unknown?: Set<string>;
|
|
32
|
+
/** The refs that stay refs (`system.intersections`). Left out: every ref is followed. */
|
|
33
|
+
keptRefs?: KeptRefs;
|
|
31
34
|
};
|
|
32
35
|
export type OneOfObject = {
|
|
33
36
|
oneOf?: (OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject)[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { OpenAPIV3 } from 'openapi-types';
|
|
2
|
+
import type { ParseContextType } from '../../../context/parseTypes.js';
|
|
3
|
+
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
4
|
+
import { OasIntersection } from '../../../oas/intersection/Intersection.js';
|
|
5
|
+
export type ToIntersectionArgs = {
|
|
6
|
+
/** The intersection's own keywords, without `allOf`. */
|
|
7
|
+
value: OpenAPIV3.SchemaObject;
|
|
8
|
+
members: (OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject)[];
|
|
9
|
+
stackTrail: StackTrail;
|
|
10
|
+
context: ParseContextType;
|
|
11
|
+
};
|
|
12
|
+
export declare const toIntersection: ({ value, members, stackTrail, context }: ToIntersectionArgs) => OasIntersection;
|