@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");
|
|
@@ -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
|
|
@@ -43,7 +43,7 @@ import type { ModelEntry } from '../dsl/model/toModelEntry.js';
|
|
|
43
43
|
*
|
|
44
44
|
* const modelEntry = toModelEntry({
|
|
45
45
|
* id: 'typescript-models',
|
|
46
|
-
* transform: ({ context,
|
|
46
|
+
* transform: ({ context, ref }) => {}
|
|
47
47
|
* });
|
|
48
48
|
* // modelEntry.type === 'model'
|
|
49
49
|
* ```
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @fileoverview Caller options for projections.
|
|
3
3
|
*
|
|
4
4
|
* Options are typed data the CALLING generator passes when it inserts a
|
|
5
|
-
* peer: `context.insertModel(Peer,
|
|
5
|
+
* peer: `context.insertModel(Peer, ref, { options })`. Enrichments are
|
|
6
6
|
* the user's per-subject configuration and a variant selects one of them;
|
|
7
7
|
* options belong to the caller.
|
|
8
8
|
*
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @fileoverview Caller options for projections.
|
|
4
4
|
*
|
|
5
5
|
* Options are typed data the CALLING generator passes when it inserts a
|
|
6
|
-
* peer: `context.insertModel(Peer,
|
|
6
|
+
* peer: `context.insertModel(Peer, ref, { options })`. Enrichments are
|
|
7
7
|
* the user's per-subject configuration and a variant selects one of them;
|
|
8
8
|
* options belong to the caller.
|
|
9
9
|
*
|
|
@@ -99,14 +99,14 @@ import type { Brand } from './Brand.js';
|
|
|
99
99
|
* @example In generator contexts
|
|
100
100
|
* ```typescript
|
|
101
101
|
* class ModelGenerator extends ModelProjectionBase {
|
|
102
|
-
* constructor(args: {
|
|
102
|
+
* constructor(args: { ref: RefParts; ... }) {
|
|
103
103
|
* super(args);
|
|
104
|
-
* // this.refName is
|
|
104
|
+
* // this.ref.refName is the name of the model's ref
|
|
105
105
|
* }
|
|
106
106
|
*
|
|
107
107
|
* toDefinition(): Definition {
|
|
108
108
|
* // RefName ensures we're working with valid schema identifiers
|
|
109
|
-
* const schemaName = this.refName; // Type: RefName
|
|
109
|
+
* const schemaName = this.ref.refName; // Type: RefName
|
|
110
110
|
* return new Definition({
|
|
111
111
|
* identifier: createType(schemaName),
|
|
112
112
|
* // ...
|
|
@@ -470,6 +470,15 @@ export type SystemSettings = {
|
|
|
470
470
|
* default, `[]`, lists none.
|
|
471
471
|
*/
|
|
472
472
|
danglingRefs?: DanglingRefKind[];
|
|
473
|
+
/**
|
|
474
|
+
* The `$ref`s that stay refs where core would merge their target in: the
|
|
475
|
+
* members of an `allOf`, and the members of a `oneOf` or `anyOf` with a
|
|
476
|
+
* keyword beside it that merges into each member. The schema is then an
|
|
477
|
+
* `OasIntersection` of the refs and one schema that the other members merge
|
|
478
|
+
* into. `cycles` (the default): a `$ref` whose target leads back to the
|
|
479
|
+
* schema that holds it. `all`: each one. `merge`: none.
|
|
480
|
+
*/
|
|
481
|
+
intersections?: 'merge' | 'cycles' | 'all';
|
|
473
482
|
};
|
|
474
483
|
export type ClientSettings = {
|
|
475
484
|
/** Base output path for generated files */
|
package/script/types/Settings.js
CHANGED
|
@@ -228,7 +228,8 @@ exports.systemSettings = v.object({
|
|
|
228
228
|
responseContradictions: v.optional(v.picklist(['strict', 'unknown'])),
|
|
229
229
|
not: v.optional(v.picklist(['strict', 'unknown'])),
|
|
230
230
|
anyOf: v.optional(v.picklist(['union', 'unknown'])),
|
|
231
|
-
danglingRefs: v.optional(v.array(v.picklist(exports.danglingRefKinds)))
|
|
231
|
+
danglingRefs: v.optional(v.array(v.picklist(exports.danglingRefKinds))),
|
|
232
|
+
intersections: v.optional(v.picklist(['merge', 'cycles', 'all']))
|
|
232
233
|
});
|
|
233
234
|
exports.clientSettings = v.object({
|
|
234
235
|
basePath: v.optional(v.pipe(v.string(), v.check(basePath => !(0, normalizeWorkspacePath_js_1.isAbsolutePath)(basePath), 'basePath must be relative to the SKMTC root (the directory containing .skmtc/); ' +
|
|
@@ -7,7 +7,7 @@ import type { GenerateContextType } from '../context/generateTypes.js';
|
|
|
7
7
|
import type { CustomValue } from '../dsl/CustomValue.js';
|
|
8
8
|
import type { OasVoid } from '../oas/void/Void.js';
|
|
9
9
|
import type { GeneratorKey } from '../dsl/GeneratorKeys.js';
|
|
10
|
-
import type {
|
|
10
|
+
import type { RefParts } from '../helpers/refFns.js';
|
|
11
11
|
/**
|
|
12
12
|
* Union type representing all possible type system values in the SKMTC code generation system.
|
|
13
13
|
*
|
|
@@ -19,7 +19,7 @@ import type { RefName } from './RefName.js';
|
|
|
19
19
|
* ## Type Categories
|
|
20
20
|
*
|
|
21
21
|
* - **Primitive Types**: `string`, `number`, `integer`, `boolean`, `null`
|
|
22
|
-
* - **Complex Types**: `array`, `object`, `union`
|
|
22
|
+
* - **Complex Types**: `array`, `object`, `union`, `intersection`
|
|
23
23
|
* - **Special Types**: `void`, `never`, `unknown`, `custom`
|
|
24
24
|
* - **Reference Types**: `ref` for schema references
|
|
25
25
|
*
|
|
@@ -63,7 +63,7 @@ import type { RefName } from './RefName.js';
|
|
|
63
63
|
* }
|
|
64
64
|
* ```
|
|
65
65
|
*/
|
|
66
|
-
export type TypeSystemValue = TypeSystemArray | TypeSystemObject | TypeSystemUnion | TypeSystemString | TypeSystemNumber | TypeSystemInteger | TypeSystemBoolean | TypeSystemUnknown | TypeSystemVoid | TypeSystemNever | TypeSystemRef | TypeSystemNull | TypeSystemCustom;
|
|
66
|
+
export type TypeSystemValue = TypeSystemArray | TypeSystemObject | TypeSystemUnion | TypeSystemIntersection | TypeSystemString | TypeSystemNumber | TypeSystemInteger | TypeSystemBoolean | TypeSystemUnknown | TypeSystemVoid | TypeSystemNever | TypeSystemRef | TypeSystemNull | TypeSystemCustom;
|
|
67
67
|
/**
|
|
68
68
|
* Type system representation of a reference to another schema.
|
|
69
69
|
*
|
|
@@ -360,6 +360,17 @@ export type TypeSystemUnion = {
|
|
|
360
360
|
/** Optional generator-specific key for tracking */
|
|
361
361
|
generatorKey?: GeneratorKey;
|
|
362
362
|
};
|
|
363
|
+
/** Type system representation of an intersection: a value that is of every member's type. */
|
|
364
|
+
export type TypeSystemIntersection = {
|
|
365
|
+
/** Discriminator for the intersection type */
|
|
366
|
+
type: 'intersection';
|
|
367
|
+
/** The types a value has all of */
|
|
368
|
+
members: TypeSystemValue[];
|
|
369
|
+
/** Type modifiers (optional, nullable, etc.) */
|
|
370
|
+
modifiers: Modifiers;
|
|
371
|
+
/** Optional generator-specific key for tracking */
|
|
372
|
+
generatorKey?: GeneratorKey;
|
|
373
|
+
};
|
|
363
374
|
/**
|
|
364
375
|
* Type system representation of object types.
|
|
365
376
|
*
|
|
@@ -464,6 +475,10 @@ export type SchemaToTypeSystemMap = {
|
|
|
464
475
|
source: OasSchema;
|
|
465
476
|
output: TypeSystemUnion;
|
|
466
477
|
};
|
|
478
|
+
intersection: {
|
|
479
|
+
source: OasSchema;
|
|
480
|
+
output: TypeSystemIntersection;
|
|
481
|
+
};
|
|
467
482
|
custom: {
|
|
468
483
|
source: CustomValue;
|
|
469
484
|
output: TypeSystemCustom;
|
|
@@ -539,8 +554,8 @@ export type TypeSystemArgs<Schema extends SchemaType> = {
|
|
|
539
554
|
destinationPath: string;
|
|
540
555
|
/** The schema to transform */
|
|
541
556
|
schema: Schema;
|
|
542
|
-
/**
|
|
543
|
-
rootRef?:
|
|
557
|
+
/** The ref of the model whose value tree holds the schema */
|
|
558
|
+
rootRef?: RefParts;
|
|
544
559
|
/** Whether the schema field is required */
|
|
545
560
|
required: boolean | undefined;
|
|
546
561
|
};
|