@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
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _OasDocument_fields;
|
|
13
|
+
var _OasDocument_fields, _OasDocument_refTargets;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.OasDocument = void 0;
|
|
16
16
|
require("../../_dnt.polyfills.js");
|
|
@@ -142,8 +142,50 @@ class OasDocument {
|
|
|
142
142
|
});
|
|
143
143
|
/** @internal Private fields storage */
|
|
144
144
|
_OasDocument_fields.set(this, void 0);
|
|
145
|
+
/**
|
|
146
|
+
* The targets of refs that do not point at a component, such as
|
|
147
|
+
* `#/components/schemas/Pet/properties/tag` or
|
|
148
|
+
* `#/paths/~1pets/get/responses/200/content/application~1json/schema`.
|
|
149
|
+
* Each is parsed once, at its own position, and kept under its whole
|
|
150
|
+
* pointer (`toRefPointer`). The model sweep does not visit them: a
|
|
151
|
+
* generator reaches one through a ref.
|
|
152
|
+
*/
|
|
153
|
+
_OasDocument_refTargets.set(this, new Map()
|
|
154
|
+
/**
|
|
155
|
+
* Creates a new OasDocument instance.
|
|
156
|
+
*
|
|
157
|
+
* The document is typically created with undefined fields and populated
|
|
158
|
+
* later during the parsing process. This allows for lazy initialization
|
|
159
|
+
* and proper error handling during document processing.
|
|
160
|
+
*
|
|
161
|
+
* @param fields - Optional document fields (usually set later during parsing)
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* // Usually created without fields during parsing
|
|
166
|
+
* const document = new OasDocument();
|
|
167
|
+
*
|
|
168
|
+
* // Fields are set later by the parser
|
|
169
|
+
* document.fields = parsedDocumentFields;
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
);
|
|
145
173
|
__classPrivateFieldSet(this, _OasDocument_fields, fields, "f");
|
|
146
174
|
}
|
|
175
|
+
/** The parsed target of a ref that does not point at a component, by its whole pointer. */
|
|
176
|
+
toRefTarget(pointer) {
|
|
177
|
+
return __classPrivateFieldGet(this, _OasDocument_refTargets, "f").get(pointer);
|
|
178
|
+
}
|
|
179
|
+
/** Keeps the parsed target of a ref that does not point at a component, under its whole pointer. */
|
|
180
|
+
setRefTarget(pointer, target) {
|
|
181
|
+
__classPrivateFieldGet(this, _OasDocument_refTargets, "f").set(pointer, target);
|
|
182
|
+
}
|
|
183
|
+
/** Removes a ref target, as {@link removeItem} removes a component, and returns it. */
|
|
184
|
+
removeRefTarget(pointer) {
|
|
185
|
+
const target = __classPrivateFieldGet(this, _OasDocument_refTargets, "f").get(pointer);
|
|
186
|
+
__classPrivateFieldGet(this, _OasDocument_refTargets, "f").delete(pointer);
|
|
187
|
+
return target;
|
|
188
|
+
}
|
|
147
189
|
/**
|
|
148
190
|
* Removes an item from the document based on a stack trail path.
|
|
149
191
|
*
|
|
@@ -336,4 +378,4 @@ class OasDocument {
|
|
|
336
378
|
}
|
|
337
379
|
}
|
|
338
380
|
exports.OasDocument = OasDocument;
|
|
339
|
-
_OasDocument_fields = new WeakMap();
|
|
381
|
+
_OasDocument_fields = new WeakMap(), _OasDocument_refTargets = new WeakMap();
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { OasUnknown } from '../unknown/Unknown.js';
|
|
2
|
+
import type { SchemaPath } from '../../types/SchemaPath.js';
|
|
3
|
+
import type { OasExternalDocs } from '../externalDocs/ExternalDocs.js';
|
|
4
|
+
import type { OasSchema, ToJsonSchemaOptions } from '../schema/Schema.js';
|
|
5
|
+
import type { OasRef } from '../ref/Ref.js';
|
|
6
|
+
import type { OpenAPIV3 } from 'openapi-types';
|
|
7
|
+
import { OasBase } from '../../types/OasBase.js';
|
|
8
|
+
import type { ParseContextType } from '../../context/parseTypes.js';
|
|
9
|
+
/**
|
|
10
|
+
* Constructor fields for {@link OasIntersection}.
|
|
11
|
+
*/
|
|
12
|
+
export type IntersectionFields = {
|
|
13
|
+
/** A short summary of the intersection */
|
|
14
|
+
title?: string;
|
|
15
|
+
/** A description of the intersection */
|
|
16
|
+
description?: string;
|
|
17
|
+
/** External documentation for the intersection */
|
|
18
|
+
externalDocs?: OasExternalDocs | undefined;
|
|
19
|
+
/** Whether the value can be null */
|
|
20
|
+
nullable?: boolean;
|
|
21
|
+
/** Whether the value is sent by the API only */
|
|
22
|
+
readOnly?: boolean;
|
|
23
|
+
/** Whether the value is sent in a request only */
|
|
24
|
+
writeOnly?: boolean;
|
|
25
|
+
/** Whether the value is deprecated */
|
|
26
|
+
deprecated?: boolean;
|
|
27
|
+
/** Example value */
|
|
28
|
+
example?: unknown;
|
|
29
|
+
/** Default value */
|
|
30
|
+
default?: unknown;
|
|
31
|
+
/** The schemas a value matches all of */
|
|
32
|
+
members: (OasSchema | OasRef<'schema'>)[];
|
|
33
|
+
/** Custom extension fields (x-* properties) */
|
|
34
|
+
extensionFields?: Record<string, unknown>;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* An `allOf` that keeps at least one reference: a value matches every member.
|
|
38
|
+
*
|
|
39
|
+
* Core merges the members of an `allOf` into one schema. A reference that
|
|
40
|
+
* `client.json` `system.intersections` keeps is not merged: the schema is an
|
|
41
|
+
* `OasIntersection` of the kept references, and at most one other member, which
|
|
42
|
+
* the other members of the `allOf` merge into. By default those are the
|
|
43
|
+
* references that close a cycle.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* // LineString: { allOf: [{ $ref: Geometry }, { properties: { coordinates } }] },
|
|
48
|
+
* // where a property of Geometry leads back to LineString
|
|
49
|
+
* lineString.members // [OasRef Geometry, OasObject { coordinates }]
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare class OasIntersection extends OasBase {
|
|
53
|
+
#private;
|
|
54
|
+
/**
|
|
55
|
+
* Object is part the 'schema' set which is used
|
|
56
|
+
* to define data types in an OpenAPI document.
|
|
57
|
+
*/
|
|
58
|
+
oasType: "schema";
|
|
59
|
+
/**
|
|
60
|
+
* Constant value 'intersection' useful for type narrowing and tagged unions.
|
|
61
|
+
*/
|
|
62
|
+
type: "intersection";
|
|
63
|
+
/** A short summary of the intersection. */
|
|
64
|
+
title: string | undefined;
|
|
65
|
+
/** A description of the intersection. */
|
|
66
|
+
description: string | undefined;
|
|
67
|
+
/** External documentation for the intersection. */
|
|
68
|
+
externalDocs: OasExternalDocs | undefined;
|
|
69
|
+
/** Indicates whether the value can be null. */
|
|
70
|
+
nullable: boolean | undefined;
|
|
71
|
+
/** Whether the value is sent by the API only. */
|
|
72
|
+
readOnly: boolean | undefined;
|
|
73
|
+
/** Whether the value is sent in a request only. */
|
|
74
|
+
writeOnly: boolean | undefined;
|
|
75
|
+
/** Whether the value is deprecated. */
|
|
76
|
+
deprecated: boolean | undefined;
|
|
77
|
+
/** The schemas, or references to schemas, that a value matches all of. */
|
|
78
|
+
members: (OasSchema | OasRef<'schema'>)[];
|
|
79
|
+
/** Specification Extension fields */
|
|
80
|
+
extensionFields: Record<string, unknown> | undefined;
|
|
81
|
+
/** An example of the value. */
|
|
82
|
+
example?: unknown;
|
|
83
|
+
/** The default value. */
|
|
84
|
+
default?: unknown;
|
|
85
|
+
/**
|
|
86
|
+
* The schema's `not`, kept as an `OasUnknown` under `client.json`
|
|
87
|
+
* `system.not: unknown`. `undefined` otherwise.
|
|
88
|
+
*/
|
|
89
|
+
not: OasUnknown | undefined;
|
|
90
|
+
constructor(fields: IntersectionFields, context?: ParseContextType);
|
|
91
|
+
isRef(): this is OasRef<'schema'>;
|
|
92
|
+
/** Whether the value is `readOnly`: the intersection or one of its members is. */
|
|
93
|
+
isReadOnly(): boolean;
|
|
94
|
+
/** Whether the value is `writeOnly`: the intersection or one of its members is. */
|
|
95
|
+
isWriteOnly(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* The schemas a value matches all of, with each reference resolved and each
|
|
98
|
+
* intersection inside replaced by its own members. Each is given once, so a
|
|
99
|
+
* member that leads back to an intersection ends. A reference that names
|
|
100
|
+
* nothing is left out.
|
|
101
|
+
*/
|
|
102
|
+
toParts(): Exclude<OasSchema, OasIntersection>[];
|
|
103
|
+
/**
|
|
104
|
+
* {@link toParts} without the keywords next to the references. `clone` reads
|
|
105
|
+
* these while a reference to this intersection resolves, so no reference may
|
|
106
|
+
* be resolved with its keywords here.
|
|
107
|
+
*/
|
|
108
|
+
toTargetParts(): Exclude<OasSchema, OasIntersection>[];
|
|
109
|
+
/**
|
|
110
|
+
* A copy of this schema with what `ref` adds at its site applied, as
|
|
111
|
+
* {@link OasUnion.clone} does: the keywords that this type takes, a
|
|
112
|
+
* sibling's value winning. The keywords of an object next to `ref`
|
|
113
|
+
* (`properties`, `required`) are one more member, unless the members say
|
|
114
|
+
* the same. This schema does not
|
|
115
|
+
* change, and the copy shares its members.
|
|
116
|
+
*/
|
|
117
|
+
clone(ref?: OasRef<'schema'>): OasIntersection;
|
|
118
|
+
traverse(path: SchemaPath): OasSchema | OasRef<'schema'>;
|
|
119
|
+
resolve(): OasIntersection;
|
|
120
|
+
resolveOnce(): OasIntersection;
|
|
121
|
+
toJsonSchema(options: ToJsonSchemaOptions): OpenAPIV3.NonArraySchemaObject;
|
|
122
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _OasIntersection_instances, _OasIntersection_toMembersInside;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.OasIntersection = void 0;
|
|
10
|
+
const traverseSchema_js_1 = require("../schemaPath/traverseSchema.js");
|
|
11
|
+
const Object_js_1 = require("../object/Object.js");
|
|
12
|
+
const siblings_js_1 = require("../schema/siblings.js");
|
|
13
|
+
const OasBase_js_1 = require("../../types/OasBase.js");
|
|
14
|
+
const DanglingRefError_js_1 = require("../ref/DanglingRefError.js");
|
|
15
|
+
/**
|
|
16
|
+
* An `allOf` that keeps at least one reference: a value matches every member.
|
|
17
|
+
*
|
|
18
|
+
* Core merges the members of an `allOf` into one schema. A reference that
|
|
19
|
+
* `client.json` `system.intersections` keeps is not merged: the schema is an
|
|
20
|
+
* `OasIntersection` of the kept references, and at most one other member, which
|
|
21
|
+
* the other members of the `allOf` merge into. By default those are the
|
|
22
|
+
* references that close a cycle.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // LineString: { allOf: [{ $ref: Geometry }, { properties: { coordinates } }] },
|
|
27
|
+
* // where a property of Geometry leads back to LineString
|
|
28
|
+
* lineString.members // [OasRef Geometry, OasObject { coordinates }]
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
class OasIntersection extends OasBase_js_1.OasBase {
|
|
32
|
+
constructor(fields, context) {
|
|
33
|
+
super(context);
|
|
34
|
+
_OasIntersection_instances.add(this);
|
|
35
|
+
/**
|
|
36
|
+
* Object is part the 'schema' set which is used
|
|
37
|
+
* to define data types in an OpenAPI document.
|
|
38
|
+
*/
|
|
39
|
+
Object.defineProperty(this, "oasType", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
writable: true,
|
|
43
|
+
value: 'schema'
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* Constant value 'intersection' useful for type narrowing and tagged unions.
|
|
47
|
+
*/
|
|
48
|
+
Object.defineProperty(this, "type", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
configurable: true,
|
|
51
|
+
writable: true,
|
|
52
|
+
value: 'intersection'
|
|
53
|
+
});
|
|
54
|
+
/** A short summary of the intersection. */
|
|
55
|
+
Object.defineProperty(this, "title", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
configurable: true,
|
|
58
|
+
writable: true,
|
|
59
|
+
value: void 0
|
|
60
|
+
});
|
|
61
|
+
/** A description of the intersection. */
|
|
62
|
+
Object.defineProperty(this, "description", {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
writable: true,
|
|
66
|
+
value: void 0
|
|
67
|
+
});
|
|
68
|
+
/** External documentation for the intersection. */
|
|
69
|
+
Object.defineProperty(this, "externalDocs", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true,
|
|
73
|
+
value: void 0
|
|
74
|
+
});
|
|
75
|
+
/** Indicates whether the value can be null. */
|
|
76
|
+
Object.defineProperty(this, "nullable", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
configurable: true,
|
|
79
|
+
writable: true,
|
|
80
|
+
value: void 0
|
|
81
|
+
});
|
|
82
|
+
/** Whether the value is sent by the API only. */
|
|
83
|
+
Object.defineProperty(this, "readOnly", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
configurable: true,
|
|
86
|
+
writable: true,
|
|
87
|
+
value: void 0
|
|
88
|
+
});
|
|
89
|
+
/** Whether the value is sent in a request only. */
|
|
90
|
+
Object.defineProperty(this, "writeOnly", {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
configurable: true,
|
|
93
|
+
writable: true,
|
|
94
|
+
value: void 0
|
|
95
|
+
});
|
|
96
|
+
/** Whether the value is deprecated. */
|
|
97
|
+
Object.defineProperty(this, "deprecated", {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
configurable: true,
|
|
100
|
+
writable: true,
|
|
101
|
+
value: void 0
|
|
102
|
+
});
|
|
103
|
+
/** The schemas, or references to schemas, that a value matches all of. */
|
|
104
|
+
Object.defineProperty(this, "members", {
|
|
105
|
+
enumerable: true,
|
|
106
|
+
configurable: true,
|
|
107
|
+
writable: true,
|
|
108
|
+
value: void 0
|
|
109
|
+
});
|
|
110
|
+
/** Specification Extension fields */
|
|
111
|
+
Object.defineProperty(this, "extensionFields", {
|
|
112
|
+
enumerable: true,
|
|
113
|
+
configurable: true,
|
|
114
|
+
writable: true,
|
|
115
|
+
value: void 0
|
|
116
|
+
});
|
|
117
|
+
/** An example of the value. */
|
|
118
|
+
Object.defineProperty(this, "example", {
|
|
119
|
+
enumerable: true,
|
|
120
|
+
configurable: true,
|
|
121
|
+
writable: true,
|
|
122
|
+
value: void 0
|
|
123
|
+
});
|
|
124
|
+
/** The default value. */
|
|
125
|
+
Object.defineProperty(this, "default", {
|
|
126
|
+
enumerable: true,
|
|
127
|
+
configurable: true,
|
|
128
|
+
writable: true,
|
|
129
|
+
value: void 0
|
|
130
|
+
});
|
|
131
|
+
/**
|
|
132
|
+
* The schema's `not`, kept as an `OasUnknown` under `client.json`
|
|
133
|
+
* `system.not: unknown`. `undefined` otherwise.
|
|
134
|
+
*/
|
|
135
|
+
Object.defineProperty(this, "not", {
|
|
136
|
+
enumerable: true,
|
|
137
|
+
configurable: true,
|
|
138
|
+
writable: true,
|
|
139
|
+
value: undefined
|
|
140
|
+
});
|
|
141
|
+
this.title = fields.title;
|
|
142
|
+
this.description = fields.description;
|
|
143
|
+
this.externalDocs = fields.externalDocs;
|
|
144
|
+
this.nullable = fields.nullable;
|
|
145
|
+
this.readOnly = fields.readOnly;
|
|
146
|
+
this.writeOnly = fields.writeOnly;
|
|
147
|
+
this.deprecated = fields.deprecated;
|
|
148
|
+
this.members = fields.members;
|
|
149
|
+
this.extensionFields = fields.extensionFields;
|
|
150
|
+
this.example = fields.example;
|
|
151
|
+
this.default = fields.default;
|
|
152
|
+
}
|
|
153
|
+
isRef() {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
/** Whether the value is `readOnly`: the intersection or one of its members is. */
|
|
157
|
+
isReadOnly() {
|
|
158
|
+
return __classPrivateFieldGet(this, _OasIntersection_instances, "m", _OasIntersection_toMembersInside).call(this).some(member => member.isRef() || member.type === 'intersection' ? member.readOnly === true : member.isReadOnly());
|
|
159
|
+
}
|
|
160
|
+
/** Whether the value is `writeOnly`: the intersection or one of its members is. */
|
|
161
|
+
isWriteOnly() {
|
|
162
|
+
return __classPrivateFieldGet(this, _OasIntersection_instances, "m", _OasIntersection_toMembersInside).call(this).some(member => member.isRef() || member.type === 'intersection' ? member.writeOnly === true : member.isWriteOnly());
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The schemas a value matches all of, with each reference resolved and each
|
|
166
|
+
* intersection inside replaced by its own members. Each is given once, so a
|
|
167
|
+
* member that leads back to an intersection ends. A reference that names
|
|
168
|
+
* nothing is left out.
|
|
169
|
+
*/
|
|
170
|
+
toParts() {
|
|
171
|
+
return __classPrivateFieldGet(this, _OasIntersection_instances, "m", _OasIntersection_toMembersInside).call(this).filter(isPart);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* {@link toParts} without the keywords next to the references. `clone` reads
|
|
175
|
+
* these while a reference to this intersection resolves, so no reference may
|
|
176
|
+
* be resolved with its keywords here.
|
|
177
|
+
*/
|
|
178
|
+
toTargetParts() {
|
|
179
|
+
return __classPrivateFieldGet(this, _OasIntersection_instances, "m", _OasIntersection_toMembersInside).call(this, ref => ref.resolveOnce()).filter(isPart);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* A copy of this schema with what `ref` adds at its site applied, as
|
|
183
|
+
* {@link OasUnion.clone} does: the keywords that this type takes, a
|
|
184
|
+
* sibling's value winning. The keywords of an object next to `ref`
|
|
185
|
+
* (`properties`, `required`) are one more member, unless the members say
|
|
186
|
+
* the same. This schema does not
|
|
187
|
+
* change, and the copy shares its members.
|
|
188
|
+
*/
|
|
189
|
+
clone(ref) {
|
|
190
|
+
const copy = new OasIntersection({
|
|
191
|
+
...(0, siblings_js_1.toSiblingAnnotations)(this, ref),
|
|
192
|
+
example: ref?.example ?? this.example,
|
|
193
|
+
externalDocs: this.externalDocs,
|
|
194
|
+
nullable: this.nullable || ref?.nullable || undefined,
|
|
195
|
+
readOnly: this.readOnly || ref?.readOnly || undefined,
|
|
196
|
+
writeOnly: this.writeOnly || ref?.writeOnly || undefined,
|
|
197
|
+
deprecated: ref?.deprecated ?? this.deprecated,
|
|
198
|
+
members: ref !== undefined && (0, siblings_js_1.toChangedObjectKeywords)(this, ref).length > 0 ? [...this.members, toSiblingMember(ref)] : this.members,
|
|
199
|
+
default: ref?.default ?? this.default
|
|
200
|
+
});
|
|
201
|
+
copy.stackTrail = this.stackTrail;
|
|
202
|
+
copy.not = this.not;
|
|
203
|
+
return copy;
|
|
204
|
+
}
|
|
205
|
+
traverse(path) {
|
|
206
|
+
return (0, traverseSchema_js_1.traverseSchema)(this, path);
|
|
207
|
+
}
|
|
208
|
+
resolve() {
|
|
209
|
+
return this;
|
|
210
|
+
}
|
|
211
|
+
resolveOnce() {
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
toJsonSchema(options) {
|
|
215
|
+
return {
|
|
216
|
+
title: this.title,
|
|
217
|
+
description: this.description,
|
|
218
|
+
nullable: this.nullable,
|
|
219
|
+
readOnly: this.readOnly,
|
|
220
|
+
writeOnly: this.writeOnly,
|
|
221
|
+
deprecated: this.deprecated,
|
|
222
|
+
example: this.example,
|
|
223
|
+
default: this.default,
|
|
224
|
+
allOf: this.members.map(member => member.toJsonSchema(options))
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
exports.OasIntersection = OasIntersection;
|
|
229
|
+
_OasIntersection_instances = new WeakSet(), _OasIntersection_toMembersInside = function _OasIntersection_toMembersInside(follow = ref => ref.resolve()) {
|
|
230
|
+
const found = new Set();
|
|
231
|
+
const visit = (item) => {
|
|
232
|
+
if (item === undefined || found.has(item)) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
found.add(item);
|
|
236
|
+
if (item.isRef()) {
|
|
237
|
+
visit(toTarget(() => follow(item)));
|
|
238
|
+
}
|
|
239
|
+
else if (item.type === 'intersection') {
|
|
240
|
+
item.members.forEach(visit);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
visit(this);
|
|
244
|
+
return [...found];
|
|
245
|
+
};
|
|
246
|
+
/** The keywords of an object next to a reference, as an object. */
|
|
247
|
+
const toSiblingMember = (ref) => {
|
|
248
|
+
const member = new Object_js_1.OasObject({
|
|
249
|
+
properties: ref.properties,
|
|
250
|
+
required: ref.required,
|
|
251
|
+
additionalProperties: ref.additionalProperties,
|
|
252
|
+
minProperties: ref.minProperties,
|
|
253
|
+
maxProperties: ref.maxProperties
|
|
254
|
+
});
|
|
255
|
+
member.stackTrail = ref.stackTrail;
|
|
256
|
+
return member;
|
|
257
|
+
};
|
|
258
|
+
const isPart = (member) => !member.isRef() && member.type !== 'intersection';
|
|
259
|
+
/** What following a reference gives, or `undefined` when it names nothing. */
|
|
260
|
+
const toTarget = (follow) => {
|
|
261
|
+
try {
|
|
262
|
+
return follow();
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
if (DanglingRefError_js_1.DanglingRefError.is(error)) {
|
|
266
|
+
return undefined;
|
|
267
|
+
}
|
|
268
|
+
throw error;
|
|
269
|
+
}
|
|
270
|
+
};
|
|
@@ -40,7 +40,7 @@ export type JsonContent = {
|
|
|
40
40
|
* Choose the media type a body is read from: `application/json` exactly when
|
|
41
41
|
* it is a key, else the first JSON-like key in document order (see
|
|
42
42
|
* {@link isJsonMediaType}), else the `*\/*` key when its schema is an object,
|
|
43
|
-
* array, union or `$ref`. `*\/*` admits JSON, and documents use it for JSON
|
|
43
|
+
* array, union, intersection or `$ref`. `*\/*` admits JSON, and documents use it for JSON
|
|
44
44
|
* bodies (springdoc writes it for every response); the parser logs
|
|
45
45
|
* `WILDCARD_MEDIA_TYPE` for every body read this way. `undefined` otherwise:
|
|
46
46
|
* there is no fall back to a specific non-JSON type, to a narrower range such
|
|
@@ -33,16 +33,16 @@ const isAnyMediaType = (mediaType) => (0, exports.toMediaTypeEssence)(mediaType)
|
|
|
33
33
|
exports.isAnyMediaType = isAnyMediaType;
|
|
34
34
|
/**
|
|
35
35
|
* True when a schema under `*\/*` can be read as one JSON value: an object,
|
|
36
|
-
* array, union or `$ref`. A scalar is not: under `*\/*` a `string` is usually
|
|
36
|
+
* array, union, intersection or `$ref`. A scalar is not: under `*\/*` a `string` is usually
|
|
37
37
|
* a text body, and `string` with `format: binary` a file.
|
|
38
38
|
*/
|
|
39
39
|
const isJsonShaped = (schema) => schema !== undefined &&
|
|
40
|
-
(schema.isRef() ||
|
|
40
|
+
(schema.isRef() || ['object', 'array', 'union', 'intersection'].includes(schema.type));
|
|
41
41
|
/**
|
|
42
42
|
* Choose the media type a body is read from: `application/json` exactly when
|
|
43
43
|
* it is a key, else the first JSON-like key in document order (see
|
|
44
44
|
* {@link isJsonMediaType}), else the `*\/*` key when its schema is an object,
|
|
45
|
-
* array, union or `$ref`. `*\/*` admits JSON, and documents use it for JSON
|
|
45
|
+
* array, union, intersection or `$ref`. `*\/*` admits JSON, and documents use it for JSON
|
|
46
46
|
* bodies (springdoc writes it for every response); the parser logs
|
|
47
47
|
* `WILDCARD_MEDIA_TYPE` for every body read this way. `undefined` otherwise:
|
|
48
48
|
* there is no fall back to a specific non-JSON type, to a narrower range such
|
|
@@ -7,10 +7,13 @@ type DanglingRefErrorOptions = {
|
|
|
7
7
|
* `['#/components/schemas/B', '#/components/schemas/A']`.
|
|
8
8
|
*/
|
|
9
9
|
loop?: string[];
|
|
10
|
+
/** The `$ref` points outside the document, which core does not fetch. */
|
|
11
|
+
remote?: boolean;
|
|
10
12
|
};
|
|
11
13
|
/**
|
|
12
14
|
* Thrown when a reference that names nothing in the document is resolved:
|
|
13
|
-
* no component has its name,
|
|
15
|
+
* no component has its name, it points outside the document (core does not
|
|
16
|
+
* fetch), or its chain of `$ref`s comes back to one it
|
|
14
17
|
* has passed (`A` is a `$ref` to `B`, and `B` to `A`), so it never reaches a
|
|
15
18
|
* component.
|
|
16
19
|
*
|
|
@@ -25,7 +28,7 @@ export declare class DanglingRefError extends Error {
|
|
|
25
28
|
ref: string;
|
|
26
29
|
/** When the chain of `$ref`s loops: see {@link DanglingRefErrorOptions.loop}. */
|
|
27
30
|
loop: string[] | undefined;
|
|
28
|
-
constructor(ref: string, { loop }?: DanglingRefErrorOptions);
|
|
31
|
+
constructor(ref: string, { loop, remote }?: DanglingRefErrorOptions);
|
|
29
32
|
/**
|
|
30
33
|
* True when `error` is a `DanglingRefError`. It reads the error's name,
|
|
31
34
|
* not its class, so it is also true for one thrown by another copy of
|
|
@@ -4,7 +4,8 @@ exports.DanglingRefError = void 0;
|
|
|
4
4
|
require("../../_dnt.polyfills.js");
|
|
5
5
|
/**
|
|
6
6
|
* Thrown when a reference that names nothing in the document is resolved:
|
|
7
|
-
* no component has its name,
|
|
7
|
+
* no component has its name, it points outside the document (core does not
|
|
8
|
+
* fetch), or its chain of `$ref`s comes back to one it
|
|
8
9
|
* has passed (`A` is a `$ref` to `B`, and `B` to `A`), so it never reaches a
|
|
9
10
|
* component.
|
|
10
11
|
*
|
|
@@ -15,9 +16,9 @@ require("../../_dnt.polyfills.js");
|
|
|
15
16
|
* {@link DanglingRefError.is}, not `instanceof`.
|
|
16
17
|
*/
|
|
17
18
|
class DanglingRefError extends Error {
|
|
18
|
-
constructor(ref, { loop } = {}) {
|
|
19
|
+
constructor(ref, { loop, remote = false } = {}) {
|
|
19
20
|
super(loop === undefined
|
|
20
|
-
? `Ref "${ref}" names nothing in the document`
|
|
21
|
+
? `Ref "${ref}" ${remote ? 'points outside the document; bundle the files into one document first' : 'names nothing in the document'}`
|
|
21
22
|
: `Ref "${ref}" leads into a loop of $refs (${[...loop, ...loop.slice(0, 1)].join(' → ')}) and never reaches a component`);
|
|
22
23
|
/** The `$ref`, or the component name, that names nothing. */
|
|
23
24
|
Object.defineProperty(this, "ref", {
|
package/script/oas/ref/Ref.d.ts
CHANGED
|
@@ -92,8 +92,8 @@ export type RefFields<T extends OasRefData['refType']> = SiblingKeywords & {
|
|
|
92
92
|
* function processSchemaOrRef(schema: OasSchema | OasRef<'schema'>) {
|
|
93
93
|
* if (schema.isRef()) {
|
|
94
94
|
* // Handle reference
|
|
95
|
-
* const refName = schema
|
|
96
|
-
* console.log(`Processing reference: ${refName}`);
|
|
95
|
+
* const { refName, refPath } = schema;
|
|
96
|
+
* console.log(`Processing reference: ${refName} in ${refPath}`);
|
|
97
97
|
*
|
|
98
98
|
* // Resolve only when needed
|
|
99
99
|
* const resolved = schema.resolve();
|
|
@@ -128,8 +128,25 @@ export declare class OasRef<T extends OasRefData['refType']> extends OasBase {
|
|
|
128
128
|
type: 'ref';
|
|
129
129
|
/** The kind of component the reference points to. */
|
|
130
130
|
refType: T;
|
|
131
|
-
/**
|
|
131
|
+
/**
|
|
132
|
+
* The JSON Reference, as written: a component (`#/components/<bucket>/<name>`)
|
|
133
|
+
* or any other place in the document (`#/components/schemas/Pet/properties/tag`).
|
|
134
|
+
*/
|
|
132
135
|
$ref: string;
|
|
136
|
+
/**
|
|
137
|
+
* The last segment of the `$ref`'s pointer, unescaped: `Pet` for
|
|
138
|
+
* `#/components/schemas/Pet`, `schema0` for
|
|
139
|
+
* `#/components/schemas/__sharedInput/$defs/schema0`. Empty for a `$ref`
|
|
140
|
+
* that ends in `/`, which names nothing.
|
|
141
|
+
*/
|
|
142
|
+
refName: RefName;
|
|
143
|
+
/**
|
|
144
|
+
* The pointer before {@link refName}, with no percent escapes: `#/components/schemas`
|
|
145
|
+
* for a schema component, `#/components/schemas/__sharedInput/$defs` for
|
|
146
|
+
* the `$defs` entry above. A generator that names by {@link refName} alone
|
|
147
|
+
* may ignore it.
|
|
148
|
+
*/
|
|
149
|
+
refPath: string;
|
|
133
150
|
/**
|
|
134
151
|
* Use-site nullability (see {@link SiblingKeywords.nullable}). Assigned
|
|
135
152
|
* even when `undefined`, so `'nullable' in ref` is always true and the
|
|
@@ -241,8 +258,9 @@ export declare class OasRef<T extends OasRefData['refType']> extends OasBase {
|
|
|
241
258
|
toLoop(): OasRef<T>[] | undefined;
|
|
242
259
|
/**
|
|
243
260
|
* Resolves this reference one level. Dispatches on the document's
|
|
244
|
-
* protocol — OAS reads from `document.components.<bucket
|
|
245
|
-
*
|
|
261
|
+
* protocol — OAS reads a component from `document.components.<bucket>`,
|
|
262
|
+
* and any other target from the targets the parser kept by pointer
|
|
263
|
+
* (`OasDocument.toRefTarget`); GQL reads from `document.registry.schemas`.
|
|
246
264
|
*
|
|
247
265
|
* @returns Either the resolved component or another reference in the chain
|
|
248
266
|
* @throws {DanglingRefError} when the reference names nothing in the
|
|
@@ -252,13 +270,6 @@ export declare class OasRef<T extends OasRefData['refType']> extends OasBase {
|
|
|
252
270
|
* `requestBody` ref to `#/components/schemas/…`
|
|
253
271
|
*/
|
|
254
272
|
resolveOnce(): OasRef<T> | ResolvedRef<T>;
|
|
255
|
-
/**
|
|
256
|
-
* The component name the reference looks up.
|
|
257
|
-
*
|
|
258
|
-
* @throws {DanglingRefError} when the `$ref` has no name, such as
|
|
259
|
-
* `#/components/schemas/`: it names nothing
|
|
260
|
-
*/
|
|
261
|
-
toRefName(): RefName;
|
|
262
273
|
/**
|
|
263
274
|
* Narrows this reference to a schema reference.
|
|
264
275
|
*
|