@skmtc/core 0.42.0 → 0.44.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/context/ParseContext.d.ts +4 -2
- package/esm/context/ParseContext.js +23 -8
- package/esm/context/generateTypes.d.ts +3 -2
- package/esm/helpers/refFns.d.ts +8 -3
- package/esm/helpers/refFns.js +26 -9
- package/esm/oas/operation/Operation.d.ts +19 -4
- package/esm/oas/operation/Operation.js +30 -10
- package/esm/oas/operation/toEffectiveParameters.d.ts +9 -0
- package/esm/oas/operation/toEffectiveParameters.js +27 -0
- package/esm/oas/ref/DanglingRefError.d.ts +18 -3
- package/esm/oas/ref/DanglingRefError.js +17 -4
- package/esm/oas/ref/Ref.d.ts +29 -13
- package/esm/oas/ref/Ref.js +63 -38
- package/esm/oas/webhook/Webhook.d.ts +10 -0
- package/esm/oas/webhook/Webhook.js +13 -1
- package/esm/parse/anyOfSystem.js +6 -8
- package/esm/parse/v3-0/schema/toSchemasV3.js +3 -3
- package/esm/parse/v3-1/schema/toSchemasV3.js +3 -3
- package/esm/parse/v3-2/schema/toSchemasV3.js +3 -3
- package/package.json +1 -1
- package/script/context/ParseContext.d.ts +4 -2
- package/script/context/ParseContext.js +23 -8
- package/script/context/generateTypes.d.ts +3 -2
- package/script/helpers/refFns.d.ts +8 -3
- package/script/helpers/refFns.js +27 -10
- package/script/oas/operation/Operation.d.ts +19 -4
- package/script/oas/operation/Operation.js +29 -9
- package/script/oas/operation/toEffectiveParameters.d.ts +9 -0
- package/script/oas/operation/toEffectiveParameters.js +29 -1
- package/script/oas/ref/DanglingRefError.d.ts +18 -3
- package/script/oas/ref/DanglingRefError.js +17 -4
- package/script/oas/ref/Ref.d.ts +29 -13
- package/script/oas/ref/Ref.js +63 -38
- package/script/oas/webhook/Webhook.d.ts +10 -0
- package/script/oas/webhook/Webhook.js +13 -1
- package/script/parse/anyOfSystem.js +6 -8
- package/script/parse/v3-0/schema/toSchemasV3.js +3 -3
- package/script/parse/v3-1/schema/toSchemasV3.js +3 -3
- package/script/parse/v3-2/schema/toSchemasV3.js +3 -3
|
@@ -7,6 +7,7 @@ const Object_js_1 = require("../object/Object.js");
|
|
|
7
7
|
const toPrimaryResponseCode_js_1 = require("../response/toPrimaryResponseCode.js");
|
|
8
8
|
const OasBase_js_1 = require("../../types/OasBase.js");
|
|
9
9
|
const toEffectiveParameters_js_1 = require("./toEffectiveParameters.js");
|
|
10
|
+
const DanglingRefError_js_1 = require("../ref/DanglingRefError.js");
|
|
10
11
|
class OasOperation extends OasBase_js_1.OasBase {
|
|
11
12
|
/**
|
|
12
13
|
* Creates a new OasOperation instance from operation field data.
|
|
@@ -222,17 +223,31 @@ class OasOperation extends OasBase_js_1.OasBase {
|
|
|
222
223
|
return (0, traverseSchema_js_1.traverseSchema)(rootSchema, rest);
|
|
223
224
|
}
|
|
224
225
|
/**
|
|
225
|
-
*
|
|
226
|
+
* The parameters that apply to this operation, as OpenAPI defines them: the
|
|
227
|
+
* path item's parameters apply to each of its operations, and an operation's
|
|
228
|
+
* own parameter with the same name and location replaces the path item's.
|
|
229
|
+
* The path item's come first.
|
|
226
230
|
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
231
|
+
* References stay references, so a caller can resolve each one on its own.
|
|
232
|
+
* A reference that names nothing (kept when `system.danglingRefs` lists
|
|
233
|
+
* `parameter`) keeps its place, and resolving it throws `DanglingRefError`.
|
|
234
|
+
* {@link OasOperation.toParams} resolves them all.
|
|
235
|
+
*
|
|
236
|
+
* @returns the parameters, path item's first
|
|
237
|
+
*/
|
|
238
|
+
toEffectiveParameters() {
|
|
239
|
+
return (0, toEffectiveParameters_js_1.toEffectiveParameters)({ own: this.parameters, shared: this.pathItem?.parameters });
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Resolve all parameters and optionally filter by location: the resolved
|
|
243
|
+
* {@link OasOperation.toEffectiveParameters}.
|
|
230
244
|
*
|
|
231
245
|
* @param filter - only include parameters from specified locations
|
|
232
246
|
* @returns
|
|
247
|
+
* @throws {DanglingRefError} when a parameter is a reference that names nothing
|
|
233
248
|
*/
|
|
234
249
|
toParams(filter) {
|
|
235
|
-
return
|
|
250
|
+
return this.toEffectiveParameters()
|
|
236
251
|
.map(param => param.resolve())
|
|
237
252
|
.filter(param => (filter?.length ? filter.includes(param.location) : true));
|
|
238
253
|
}
|
|
@@ -257,12 +272,17 @@ class OasOperation extends OasBase_js_1.OasBase {
|
|
|
257
272
|
*
|
|
258
273
|
* @param options - Conversion options for nested components
|
|
259
274
|
* @returns OpenAPI v3 operation object
|
|
275
|
+
* @throws {DanglingRefError} when a parameter is a reference that names
|
|
276
|
+
* nothing, as {@link OasOperation.toParams} does: there is no parameter to
|
|
277
|
+
* write, and the caller decides what to do
|
|
260
278
|
*/
|
|
261
279
|
toJsonSchema(options) {
|
|
262
|
-
const parameters =
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
280
|
+
const parameters = this.toEffectiveParameters();
|
|
281
|
+
for (const parameter of parameters) {
|
|
282
|
+
if (parameter.isRef() && (0, toEffectiveParameters_js_1.namesNothing)(parameter)) {
|
|
283
|
+
throw new DanglingRefError_js_1.DanglingRefError(parameter.$ref);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
266
286
|
return {
|
|
267
287
|
tags: this.tags,
|
|
268
288
|
summary: this.summary,
|
|
@@ -11,6 +11,15 @@ type ToEffectiveParametersArgs = {
|
|
|
11
11
|
* The parameters that apply to an operation or webhook, as OpenAPI defines
|
|
12
12
|
* them: the path item's first, then its own. An own parameter with the same
|
|
13
13
|
* name and location replaces the path item's. References stay references.
|
|
14
|
+
*
|
|
15
|
+
* A reference that names nothing (kept when `system.danglingRefs` lists
|
|
16
|
+
* `parameter`) has no name or location. It keeps its place, and only the
|
|
17
|
+
* same `$ref` replaces it.
|
|
14
18
|
*/
|
|
15
19
|
export declare const toEffectiveParameters: ({ own, shared }: ToEffectiveParametersArgs) => Parameter[];
|
|
20
|
+
/**
|
|
21
|
+
* True for a parameter `$ref` that names nothing in the document, which the
|
|
22
|
+
* parser keeps when `system.danglingRefs` lists `parameter`.
|
|
23
|
+
*/
|
|
24
|
+
export declare const namesNothing: (parameter: Parameter) => boolean;
|
|
16
25
|
export {};
|
|
@@ -1,17 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toEffectiveParameters = void 0;
|
|
3
|
+
exports.namesNothing = exports.toEffectiveParameters = void 0;
|
|
4
|
+
const DanglingRefError_js_1 = require("../ref/DanglingRefError.js");
|
|
4
5
|
/**
|
|
5
6
|
* The parameters that apply to an operation or webhook, as OpenAPI defines
|
|
6
7
|
* them: the path item's first, then its own. An own parameter with the same
|
|
7
8
|
* name and location replaces the path item's. References stay references.
|
|
9
|
+
*
|
|
10
|
+
* A reference that names nothing (kept when `system.danglingRefs` lists
|
|
11
|
+
* `parameter`) has no name or location. It keeps its place, and only the
|
|
12
|
+
* same `$ref` replaces it.
|
|
8
13
|
*/
|
|
9
14
|
const toEffectiveParameters = ({ own = [], shared = [] }) => {
|
|
10
15
|
const ownKeys = new Set(own.map(toParameterKey));
|
|
11
16
|
return [...shared.filter(parameter => !ownKeys.has(toParameterKey(parameter))), ...own];
|
|
12
17
|
};
|
|
13
18
|
exports.toEffectiveParameters = toEffectiveParameters;
|
|
19
|
+
/**
|
|
20
|
+
* True for a parameter `$ref` that names nothing in the document, which the
|
|
21
|
+
* parser keeps when `system.danglingRefs` lists `parameter`.
|
|
22
|
+
*/
|
|
23
|
+
const namesNothing = (parameter) => {
|
|
24
|
+
if (!parameter.isRef()) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
parameter.resolve();
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (DanglingRefError_js_1.DanglingRefError.is(error)) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.namesNothing = namesNothing;
|
|
14
39
|
const toParameterKey = (parameter) => {
|
|
40
|
+
if (parameter.isRef() && (0, exports.namesNothing)(parameter)) {
|
|
41
|
+
return `$ref:${parameter.$ref}`;
|
|
42
|
+
}
|
|
15
43
|
const { name, location } = parameter.resolve();
|
|
16
44
|
return `${location}:${name}`;
|
|
17
45
|
};
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
+
import "../../_dnt.polyfills.js";
|
|
2
|
+
type DanglingRefErrorOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* When the chain of `$ref`s from `ref` never reaches a component: the
|
|
5
|
+
* `$ref`s written in the loop it comes back to, in the order it follows
|
|
6
|
+
* them. `A` a `$ref` to `B`, and `B` to `A`, give
|
|
7
|
+
* `['#/components/schemas/B', '#/components/schemas/A']`.
|
|
8
|
+
*/
|
|
9
|
+
loop?: string[];
|
|
10
|
+
};
|
|
1
11
|
/**
|
|
2
|
-
* Thrown when a reference that names nothing in the document is resolved
|
|
12
|
+
* Thrown when a reference that names nothing in the document is resolved:
|
|
13
|
+
* no component has its name, or its chain of `$ref`s comes back to one it
|
|
14
|
+
* has passed (`A` is a `$ref` to `B`, and `B` to `A`), so it never reaches a
|
|
15
|
+
* component.
|
|
3
16
|
*
|
|
4
17
|
* By default the parser removes what holds such a reference, so a generator
|
|
5
18
|
* never meets one. When `client.json` `system.danglingRefs` lists the
|
|
@@ -7,11 +20,12 @@
|
|
|
7
20
|
* this error and render something else in its place. Test for it with
|
|
8
21
|
* {@link DanglingRefError.is}, not `instanceof`.
|
|
9
22
|
*/
|
|
10
|
-
import "../../_dnt.polyfills.js";
|
|
11
23
|
export declare class DanglingRefError extends Error {
|
|
12
24
|
/** The `$ref`, or the component name, that names nothing. */
|
|
13
25
|
ref: string;
|
|
14
|
-
|
|
26
|
+
/** When the chain of `$ref`s loops: see {@link DanglingRefErrorOptions.loop}. */
|
|
27
|
+
loop: string[] | undefined;
|
|
28
|
+
constructor(ref: string, { loop }?: DanglingRefErrorOptions);
|
|
15
29
|
/**
|
|
16
30
|
* True when `error` is a `DanglingRefError`. It reads the error's name,
|
|
17
31
|
* not its class, so it is also true for one thrown by another copy of
|
|
@@ -20,3 +34,4 @@ export declare class DanglingRefError extends Error {
|
|
|
20
34
|
*/
|
|
21
35
|
static is(error: unknown): error is DanglingRefError;
|
|
22
36
|
}
|
|
37
|
+
export {};
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DanglingRefError = void 0;
|
|
4
|
+
require("../../_dnt.polyfills.js");
|
|
4
5
|
/**
|
|
5
|
-
* Thrown when a reference that names nothing in the document is resolved
|
|
6
|
+
* Thrown when a reference that names nothing in the document is resolved:
|
|
7
|
+
* no component has its name, or its chain of `$ref`s comes back to one it
|
|
8
|
+
* has passed (`A` is a `$ref` to `B`, and `B` to `A`), so it never reaches a
|
|
9
|
+
* component.
|
|
6
10
|
*
|
|
7
11
|
* By default the parser removes what holds such a reference, so a generator
|
|
8
12
|
* never meets one. When `client.json` `system.danglingRefs` lists the
|
|
@@ -10,10 +14,11 @@ exports.DanglingRefError = void 0;
|
|
|
10
14
|
* this error and render something else in its place. Test for it with
|
|
11
15
|
* {@link DanglingRefError.is}, not `instanceof`.
|
|
12
16
|
*/
|
|
13
|
-
require("../../_dnt.polyfills.js");
|
|
14
17
|
class DanglingRefError extends Error {
|
|
15
|
-
constructor(ref) {
|
|
16
|
-
super(
|
|
18
|
+
constructor(ref, { loop } = {}) {
|
|
19
|
+
super(loop === undefined
|
|
20
|
+
? `Ref "${ref}" names nothing in the document`
|
|
21
|
+
: `Ref "${ref}" leads into a loop of $refs (${[...loop, ...loop.slice(0, 1)].join(' → ')}) and never reaches a component`);
|
|
17
22
|
/** The `$ref`, or the component name, that names nothing. */
|
|
18
23
|
Object.defineProperty(this, "ref", {
|
|
19
24
|
enumerable: true,
|
|
@@ -21,8 +26,16 @@ class DanglingRefError extends Error {
|
|
|
21
26
|
writable: true,
|
|
22
27
|
value: void 0
|
|
23
28
|
});
|
|
29
|
+
/** When the chain of `$ref`s loops: see {@link DanglingRefErrorOptions.loop}. */
|
|
30
|
+
Object.defineProperty(this, "loop", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
configurable: true,
|
|
33
|
+
writable: true,
|
|
34
|
+
value: void 0
|
|
35
|
+
});
|
|
24
36
|
this.name = 'DanglingRefError';
|
|
25
37
|
this.ref = ref;
|
|
38
|
+
this.loop = loop;
|
|
26
39
|
}
|
|
27
40
|
/**
|
|
28
41
|
* True when `error` is a `DanglingRefError`. It reads the error's name,
|
package/script/oas/ref/Ref.d.ts
CHANGED
|
@@ -46,7 +46,7 @@ export type RefFields<T extends OasRefData['refType']> = SiblingKeywords & {
|
|
|
46
46
|
* - **Type Safety**: Generic parameter ensures resolved types match the reference type
|
|
47
47
|
* - **Lazy Resolution**: References are resolved on-demand, not during construction
|
|
48
48
|
* - **Chain Resolution**: Handles references that point to other references
|
|
49
|
-
* - **
|
|
49
|
+
* - **Loop Detection**: A chain of references that loops names nothing ({@link OasRef.toLoop})
|
|
50
50
|
* - **Type Validation**: Ensures resolved objects match expected reference types
|
|
51
51
|
*
|
|
52
52
|
* @template T - The type of component this reference points to
|
|
@@ -210,8 +210,8 @@ export declare class OasRef<T extends OasRefData['refType']> extends OasBase {
|
|
|
210
210
|
/**
|
|
211
211
|
* Recursively resolves this reference to its final target component.
|
|
212
212
|
*
|
|
213
|
-
* Follows
|
|
214
|
-
*
|
|
213
|
+
* Follows the chain of references until it reaches a component that is
|
|
214
|
+
* not a reference. A schema reference returns the
|
|
215
215
|
* schema at this site: when the keywords next to it, or next to a
|
|
216
216
|
* reference on the chain ({@link SiblingKeywords}), change the target, a
|
|
217
217
|
* copy of the target with them applied. When they change nothing, the
|
|
@@ -221,11 +221,24 @@ export declare class OasRef<T extends OasRefData['refType']> extends OasBase {
|
|
|
221
221
|
* model every reference to it sees, and a copy is built once, kept on
|
|
222
222
|
* this reference, and returned on every call.
|
|
223
223
|
*
|
|
224
|
-
* @param lookupsPerformed - Internal counter to prevent infinite recursion
|
|
225
224
|
* @returns The resolved component
|
|
226
|
-
* @throws
|
|
225
|
+
* @throws {DanglingRefError} when a reference on the chain names nothing,
|
|
226
|
+
* or the chain loops ({@link toLoop}), so it never reaches a component.
|
|
227
|
+
* The parser keeps either one only when `system.danglingRefs` lists its kind.
|
|
228
|
+
* @throws Error when a reference on the chain names a component of another
|
|
229
|
+
* kind (see {@link resolveOnce})
|
|
227
230
|
*/
|
|
228
|
-
resolve(
|
|
231
|
+
resolve(): ResolvedRef<T>;
|
|
232
|
+
/**
|
|
233
|
+
* The references that form the loop this reference's chain comes back to,
|
|
234
|
+
* starting with the first one it comes back to, or `undefined` when the
|
|
235
|
+
* chain reaches a component. `A` a `$ref` to `B`, and `B` to `A`, form a
|
|
236
|
+
* loop: from `A` the chain goes to `B`, then to `A` again, and never
|
|
237
|
+
* reaches a component. A reference that leads into a loop is not part of it.
|
|
238
|
+
*
|
|
239
|
+
* @throws what {@link resolveOnce} throws, at any step of the chain
|
|
240
|
+
*/
|
|
241
|
+
toLoop(): OasRef<T>[] | undefined;
|
|
229
242
|
/**
|
|
230
243
|
* Resolves this reference one level. Dispatches on the document's
|
|
231
244
|
* protocol — OAS reads from `document.components.<bucket>`; GQL
|
|
@@ -239,6 +252,12 @@ export declare class OasRef<T extends OasRefData['refType']> extends OasBase {
|
|
|
239
252
|
* `requestBody` ref to `#/components/schemas/…`
|
|
240
253
|
*/
|
|
241
254
|
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
|
+
*/
|
|
242
261
|
toRefName(): RefName;
|
|
243
262
|
/**
|
|
244
263
|
* Narrows this reference to a schema reference.
|
|
@@ -297,18 +316,15 @@ export declare class OasRef<T extends OasRefData['refType']> extends OasBase {
|
|
|
297
316
|
* Whether the value is `readOnly` at this site, as Forge reads it: on this
|
|
298
317
|
* reference (`{ allOf: [{ $ref }], readOnly: true }`), or on what it points
|
|
299
318
|
* to, through any chain of references. A `readOnly: false` does not undo
|
|
300
|
-
* another's `true`. `false` for a reference to anything but a schema.
|
|
301
|
-
*
|
|
302
|
-
* @param lookupsPerformed - Internal counter that stops a chain of references with no schema
|
|
319
|
+
* another's `true`. `false` for a reference to anything but a schema. In a
|
|
320
|
+
* loop ({@link toLoop}), which reaches no schema, only the references count.
|
|
303
321
|
*/
|
|
304
|
-
isReadOnly(
|
|
322
|
+
isReadOnly(): boolean;
|
|
305
323
|
/**
|
|
306
324
|
* Whether the value is `writeOnly` at this site: on this reference, or on
|
|
307
325
|
* what it points to, as {@link isReadOnly} reads `readOnly`.
|
|
308
|
-
*
|
|
309
|
-
* @param lookupsPerformed - Internal counter that stops a chain of references with no schema
|
|
310
326
|
*/
|
|
311
|
-
isWriteOnly(
|
|
327
|
+
isWriteOnly(): boolean;
|
|
312
328
|
/**
|
|
313
329
|
* Returns the discriminated parsed document this ref resolves
|
|
314
330
|
* through. OAS variant carries the parent `OasDocument`; GQL variant
|
package/script/oas/ref/Ref.js
CHANGED
|
@@ -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 _OasRef_instances, _OasRef_document, _OasRef_resolution, _OasRef_toResolution, _OasRef_toSiteSchema, _OasRef_resolveOasOnce, _OasRef_resolveGqlOnce;
|
|
13
|
+
var _OasRef_instances, _OasRef_document, _OasRef_resolution, _OasRef_toResolution, _OasRef_toChainResolution, _OasRef_toSiteSchema, _OasRef_toLoop, _OasRef_resolveOasOnce, _OasRef_resolveGqlOnce, _OasRef_someOnChain;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.OasRef = void 0;
|
|
16
16
|
require("../../_dnt.polyfills.js");
|
|
@@ -19,7 +19,6 @@ const refFns_js_1 = require("../../helpers/refFns.js");
|
|
|
19
19
|
const OasBase_js_1 = require("../../types/OasBase.js");
|
|
20
20
|
const DanglingRefError_js_1 = require("./DanglingRefError.js");
|
|
21
21
|
const siblings_js_1 = require("../schema/siblings.js");
|
|
22
|
-
const MAX_LOOKUPS = 10;
|
|
23
22
|
/**
|
|
24
23
|
* Converts a ref type to its plural components path.
|
|
25
24
|
*/
|
|
@@ -71,7 +70,7 @@ const toLookupName = ($ref) => {
|
|
|
71
70
|
* - **Type Safety**: Generic parameter ensures resolved types match the reference type
|
|
72
71
|
* - **Lazy Resolution**: References are resolved on-demand, not during construction
|
|
73
72
|
* - **Chain Resolution**: Handles references that point to other references
|
|
74
|
-
* - **
|
|
73
|
+
* - **Loop Detection**: A chain of references that loops names nothing ({@link OasRef.toLoop})
|
|
75
74
|
* - **Type Validation**: Ensures resolved objects match expected reference types
|
|
76
75
|
*
|
|
77
76
|
* @template T - The type of component this reference points to
|
|
@@ -437,8 +436,8 @@ class OasRef extends OasBase_js_1.OasBase {
|
|
|
437
436
|
/**
|
|
438
437
|
* Recursively resolves this reference to its final target component.
|
|
439
438
|
*
|
|
440
|
-
* Follows
|
|
441
|
-
*
|
|
439
|
+
* Follows the chain of references until it reaches a component that is
|
|
440
|
+
* not a reference. A schema reference returns the
|
|
442
441
|
* schema at this site: when the keywords next to it, or next to a
|
|
443
442
|
* reference on the chain ({@link SiblingKeywords}), change the target, a
|
|
444
443
|
* copy of the target with them applied. When they change nothing, the
|
|
@@ -448,12 +447,27 @@ class OasRef extends OasBase_js_1.OasBase {
|
|
|
448
447
|
* model every reference to it sees, and a copy is built once, kept on
|
|
449
448
|
* this reference, and returned on every call.
|
|
450
449
|
*
|
|
451
|
-
* @param lookupsPerformed - Internal counter to prevent infinite recursion
|
|
452
450
|
* @returns The resolved component
|
|
453
|
-
* @throws
|
|
451
|
+
* @throws {DanglingRefError} when a reference on the chain names nothing,
|
|
452
|
+
* or the chain loops ({@link toLoop}), so it never reaches a component.
|
|
453
|
+
* The parser keeps either one only when `system.danglingRefs` lists its kind.
|
|
454
|
+
* @throws Error when a reference on the chain names a component of another
|
|
455
|
+
* kind (see {@link resolveOnce})
|
|
454
456
|
*/
|
|
455
|
-
resolve(
|
|
456
|
-
return __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toResolution).call(this
|
|
457
|
+
resolve() {
|
|
458
|
+
return __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toResolution).call(this).resolved;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* The references that form the loop this reference's chain comes back to,
|
|
462
|
+
* starting with the first one it comes back to, or `undefined` when the
|
|
463
|
+
* chain reaches a component. `A` a `$ref` to `B`, and `B` to `A`, form a
|
|
464
|
+
* loop: from `A` the chain goes to `B`, then to `A` again, and never
|
|
465
|
+
* reaches a component. A reference that leads into a loop is not part of it.
|
|
466
|
+
*
|
|
467
|
+
* @throws what {@link resolveOnce} throws, at any step of the chain
|
|
468
|
+
*/
|
|
469
|
+
toLoop() {
|
|
470
|
+
return __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toLoop).call(this, [this]);
|
|
457
471
|
}
|
|
458
472
|
/**
|
|
459
473
|
* Resolves this reference one level. Dispatches on the document's
|
|
@@ -487,8 +501,14 @@ class OasRef extends OasBase_js_1.OasBase {
|
|
|
487
501
|
}
|
|
488
502
|
return resolved;
|
|
489
503
|
}
|
|
504
|
+
/**
|
|
505
|
+
* The component name the reference looks up.
|
|
506
|
+
*
|
|
507
|
+
* @throws {DanglingRefError} when the `$ref` has no name, such as
|
|
508
|
+
* `#/components/schemas/`: it names nothing
|
|
509
|
+
*/
|
|
490
510
|
toRefName() {
|
|
491
|
-
return (
|
|
511
|
+
return toLookupName(this.$ref);
|
|
492
512
|
}
|
|
493
513
|
/**
|
|
494
514
|
* Narrows this reference to a schema reference.
|
|
@@ -551,7 +571,7 @@ class OasRef extends OasBase_js_1.OasBase {
|
|
|
551
571
|
if (!this.hasSiblings()) {
|
|
552
572
|
return false;
|
|
553
573
|
}
|
|
554
|
-
const { target, resolved } = __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toResolution).call(this
|
|
574
|
+
const { target, resolved } = __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toResolution).call(this);
|
|
555
575
|
// Widened from the generic ResolvedRef<T>, so `oasType` narrows them.
|
|
556
576
|
const original = target;
|
|
557
577
|
const applied = resolved;
|
|
@@ -578,35 +598,18 @@ class OasRef extends OasBase_js_1.OasBase {
|
|
|
578
598
|
* Whether the value is `readOnly` at this site, as Forge reads it: on this
|
|
579
599
|
* reference (`{ allOf: [{ $ref }], readOnly: true }`), or on what it points
|
|
580
600
|
* to, through any chain of references. A `readOnly: false` does not undo
|
|
581
|
-
* another's `true`. `false` for a reference to anything but a schema.
|
|
582
|
-
*
|
|
583
|
-
* @param lookupsPerformed - Internal counter that stops a chain of references with no schema
|
|
601
|
+
* another's `true`. `false` for a reference to anything but a schema. In a
|
|
602
|
+
* loop ({@link toLoop}), which reaches no schema, only the references count.
|
|
584
603
|
*/
|
|
585
|
-
isReadOnly(
|
|
586
|
-
|
|
587
|
-
return true;
|
|
588
|
-
}
|
|
589
|
-
if (lookupsPerformed >= MAX_LOOKUPS) {
|
|
590
|
-
return false;
|
|
591
|
-
}
|
|
592
|
-
const resolved = this.resolveOnce();
|
|
593
|
-
return resolved.isRef() ? resolved.isReadOnly(lookupsPerformed + 1) : resolved.isReadOnly();
|
|
604
|
+
isReadOnly() {
|
|
605
|
+
return __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_someOnChain).call(this, { onRef: ref => ref.readOnly === true, onTarget: target => target.isReadOnly() });
|
|
594
606
|
}
|
|
595
607
|
/**
|
|
596
608
|
* Whether the value is `writeOnly` at this site: on this reference, or on
|
|
597
609
|
* what it points to, as {@link isReadOnly} reads `readOnly`.
|
|
598
|
-
*
|
|
599
|
-
* @param lookupsPerformed - Internal counter that stops a chain of references with no schema
|
|
600
610
|
*/
|
|
601
|
-
isWriteOnly(
|
|
602
|
-
|
|
603
|
-
return true;
|
|
604
|
-
}
|
|
605
|
-
if (lookupsPerformed >= MAX_LOOKUPS) {
|
|
606
|
-
return false;
|
|
607
|
-
}
|
|
608
|
-
const resolved = this.resolveOnce();
|
|
609
|
-
return resolved.isRef() ? resolved.isWriteOnly(lookupsPerformed + 1) : resolved.isWriteOnly();
|
|
611
|
+
isWriteOnly() {
|
|
612
|
+
return __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_someOnChain).call(this, { onRef: ref => ref.writeOnly === true, onTarget: target => target.isWriteOnly() });
|
|
610
613
|
}
|
|
611
614
|
/**
|
|
612
615
|
* Returns the discriminated parsed document this ref resolves
|
|
@@ -641,15 +644,21 @@ class OasRef extends OasBase_js_1.OasBase {
|
|
|
641
644
|
}
|
|
642
645
|
}
|
|
643
646
|
exports.OasRef = OasRef;
|
|
644
|
-
_OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_instances = new WeakSet(), _OasRef_toResolution = function _OasRef_toResolution(
|
|
647
|
+
_OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_instances = new WeakSet(), _OasRef_toResolution = function _OasRef_toResolution() {
|
|
645
648
|
if (__classPrivateFieldGet(this, _OasRef_resolution, "f") !== undefined) {
|
|
646
649
|
return __classPrivateFieldGet(this, _OasRef_resolution, "f");
|
|
647
650
|
}
|
|
648
|
-
|
|
649
|
-
|
|
651
|
+
const loop = this.toLoop();
|
|
652
|
+
if (loop !== undefined) {
|
|
653
|
+
throw new DanglingRefError_js_1.DanglingRefError(this.$ref, { loop: loop.map(({ $ref }) => $ref) });
|
|
654
|
+
}
|
|
655
|
+
return __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toChainResolution).call(this);
|
|
656
|
+
}, _OasRef_toChainResolution = function _OasRef_toChainResolution() {
|
|
657
|
+
if (__classPrivateFieldGet(this, _OasRef_resolution, "f") !== undefined) {
|
|
658
|
+
return __classPrivateFieldGet(this, _OasRef_resolution, "f");
|
|
650
659
|
}
|
|
651
660
|
const resolved = this.resolveOnce();
|
|
652
|
-
const target = resolved.isRef() ? resolved
|
|
661
|
+
const target = resolved.isRef() ? __classPrivateFieldGet(resolved, _OasRef_instances, "m", _OasRef_toChainResolution).call(resolved).resolved : resolved;
|
|
653
662
|
const resolution = { target, resolved: __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toSiteSchema).call(this, target) };
|
|
654
663
|
__classPrivateFieldSet(this, _OasRef_resolution, resolution, "f");
|
|
655
664
|
return resolution;
|
|
@@ -665,6 +674,13 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
|
|
|
665
674
|
// A schema's copy is a schema of the same class. TypeScript cannot relate
|
|
666
675
|
// OasSchema to ResolvedRef<T> for a generic T, as in resolveOnce().
|
|
667
676
|
return (0, siblings_js_1.changesTarget)(copy, component, this) ? copy : target;
|
|
677
|
+
}, _OasRef_toLoop = function _OasRef_toLoop(followed) {
|
|
678
|
+
const next = this.resolveOnce();
|
|
679
|
+
if (!next.isRef()) {
|
|
680
|
+
return undefined;
|
|
681
|
+
}
|
|
682
|
+
const index = followed.indexOf(next);
|
|
683
|
+
return index === -1 ? __classPrivateFieldGet(next, _OasRef_instances, "m", _OasRef_toLoop).call(next, [...followed, next]) : followed.slice(index);
|
|
668
684
|
}, _OasRef_resolveOasOnce = function _OasRef_resolveOasOnce(document, refName) {
|
|
669
685
|
// A `#/components/<bucket>/<name>` ref names its bucket. A request body
|
|
670
686
|
// that is a `$ref` to `#/components/schemas/Pet` names a schema, so it is
|
|
@@ -706,4 +722,13 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
|
|
|
706
722
|
// oasType check catch any caller that constructed a non-schema
|
|
707
723
|
// ref pointing at a GQL document.
|
|
708
724
|
return document.registry.schemas[refName];
|
|
725
|
+
}, _OasRef_someOnChain = function _OasRef_someOnChain(check, passed = new Set()) {
|
|
726
|
+
if (check.onRef(this)) {
|
|
727
|
+
return true;
|
|
728
|
+
}
|
|
729
|
+
if (passed.has(this)) {
|
|
730
|
+
return false;
|
|
731
|
+
}
|
|
732
|
+
const next = this.resolveOnce();
|
|
733
|
+
return next.isRef() ? __classPrivateFieldGet(next, _OasRef_instances, "m", _OasRef_someOnChain).call(next, check, new Set([...passed, this])) : check.onTarget(next);
|
|
709
734
|
};
|
|
@@ -119,11 +119,21 @@ export declare class OasWebhook extends OasBase {
|
|
|
119
119
|
* `undefined` when there is no body or no schema for that media type.
|
|
120
120
|
*/
|
|
121
121
|
toPayloadSchema(mediaType?: string): OasSchema | OasRef<'schema'> | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* The inbound parameters that apply to this webhook, path item parameters
|
|
124
|
+
* included, with references unresolved. Mirrors
|
|
125
|
+
* {@link OasOperation.toEffectiveParameters}.
|
|
126
|
+
*
|
|
127
|
+
* @returns the parameters, path item's first
|
|
128
|
+
*/
|
|
129
|
+
toEffectiveParameters(): (OasParameter | OasRef<'parameter'>)[];
|
|
122
130
|
/**
|
|
123
131
|
* Resolve the inbound parameters (e.g. the signature/headers a handler
|
|
124
132
|
* receives), optionally filtered by location. Mirrors
|
|
125
133
|
* {@link OasOperation.toParams}, path item parameters included; the
|
|
126
134
|
* parameters carry the same shape, only their direction is inbound.
|
|
135
|
+
*
|
|
136
|
+
* @throws {DanglingRefError} when a parameter is a reference that names nothing
|
|
127
137
|
*/
|
|
128
138
|
toParams(filter?: OasParameterLocation[]): OasParameter[];
|
|
129
139
|
/**
|
|
@@ -169,14 +169,26 @@ class OasWebhook extends OasBase_js_1.OasBase {
|
|
|
169
169
|
toPayloadSchema(mediaType) {
|
|
170
170
|
return this.toPayload()?.toSchema(mediaType);
|
|
171
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* The inbound parameters that apply to this webhook, path item parameters
|
|
174
|
+
* included, with references unresolved. Mirrors
|
|
175
|
+
* {@link OasOperation.toEffectiveParameters}.
|
|
176
|
+
*
|
|
177
|
+
* @returns the parameters, path item's first
|
|
178
|
+
*/
|
|
179
|
+
toEffectiveParameters() {
|
|
180
|
+
return (0, toEffectiveParameters_js_1.toEffectiveParameters)({ own: this.parameters, shared: this.pathItem?.parameters });
|
|
181
|
+
}
|
|
172
182
|
/**
|
|
173
183
|
* Resolve the inbound parameters (e.g. the signature/headers a handler
|
|
174
184
|
* receives), optionally filtered by location. Mirrors
|
|
175
185
|
* {@link OasOperation.toParams}, path item parameters included; the
|
|
176
186
|
* parameters carry the same shape, only their direction is inbound.
|
|
187
|
+
*
|
|
188
|
+
* @throws {DanglingRefError} when a parameter is a reference that names nothing
|
|
177
189
|
*/
|
|
178
190
|
toParams(filter) {
|
|
179
|
-
return
|
|
191
|
+
return this.toEffectiveParameters()
|
|
180
192
|
.map(param => param.resolve())
|
|
181
193
|
.filter(param => (filter?.length ? filter.includes(param.location) : true));
|
|
182
194
|
}
|
|
@@ -34,13 +34,11 @@ const isScalarMember = (member) => {
|
|
|
34
34
|
return (Array.isArray(fields.enum) &&
|
|
35
35
|
fields.enum.every(value => value === null || SCALAR_VALUE_TYPES.includes(typeof value)));
|
|
36
36
|
};
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return steps < 10 ? toMemberSchema(getRef(member), getRef, steps + 1) : undefined;
|
|
43
|
-
};
|
|
37
|
+
/**
|
|
38
|
+
* The schema a member names. `getRef` follows the whole chain of `$ref`s, and
|
|
39
|
+
* a chain that loops names nothing, as in `toGetRef`.
|
|
40
|
+
*/
|
|
41
|
+
const toMemberSchema = (member, getRef) => ('$ref' in member ? getRef(member) : member);
|
|
44
42
|
/**
|
|
45
43
|
* Whether `system.anyOf: unknown` reads an `anyOf` as any value, as
|
|
46
44
|
* Cloudflare's `cf` reads it: when it has two or more members, not counting a
|
|
@@ -56,7 +54,7 @@ const isUnknownAnyOf = ({ members, setting, getRef }) => {
|
|
|
56
54
|
return false;
|
|
57
55
|
}
|
|
58
56
|
const values = members.filter(member => !isNullMember(member)).map(member => toMemberSchema(member, getRef));
|
|
59
|
-
return values.length > 1 && !values.every(
|
|
57
|
+
return values.length > 1 && !values.every(isScalarMember);
|
|
60
58
|
};
|
|
61
59
|
exports.isUnknownAnyOf = isUnknownAnyOf;
|
|
62
60
|
/**
|
|
@@ -182,7 +182,7 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
182
182
|
const system = (0, allOfSystem_js_1.toAllOfSystem)(context);
|
|
183
183
|
const merged = (0, merge_intersection_js_1.mergeIntersection)({
|
|
184
184
|
schema,
|
|
185
|
-
getRef: (0, refFns_js_2.toGetRef)(context.documentObject,
|
|
185
|
+
getRef: (0, refFns_js_2.toGetRef)(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
186
186
|
system
|
|
187
187
|
});
|
|
188
188
|
(0, allOfSystem_js_1.logAllOfContradictions)({ system, stackTrail, parent: schema, context });
|
|
@@ -198,7 +198,7 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
198
198
|
schema: withoutNullMembers(schema, 'oneOf'),
|
|
199
199
|
// A member's own `allOf`, or a member merged with the keywords beside
|
|
200
200
|
// the `oneOf`, is merged here, so it follows `allOfMember` too.
|
|
201
|
-
getRef: (0, refFns_js_2.toGetRef)(context.documentObject,
|
|
201
|
+
getRef: (0, refFns_js_2.toGetRef)(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
202
202
|
system,
|
|
203
203
|
groupType: 'oneOf'
|
|
204
204
|
});
|
|
@@ -267,7 +267,7 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
267
267
|
const merged = (0, merge_union_js_1.mergeUnion)({
|
|
268
268
|
schema: withoutNullMembers(schema, 'anyOf'),
|
|
269
269
|
// As for `oneOf`: what is merged here follows `allOfMember`.
|
|
270
|
-
getRef: (0, refFns_js_2.toGetRef)(context.documentObject,
|
|
270
|
+
getRef: (0, refFns_js_2.toGetRef)(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
271
271
|
system,
|
|
272
272
|
groupType: 'anyOf'
|
|
273
273
|
});
|
|
@@ -234,7 +234,7 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
234
234
|
const system = (0, allOfSystem_js_1.toAllOfSystem)(context);
|
|
235
235
|
const merged = (0, merge_intersection_js_1.mergeIntersection)({
|
|
236
236
|
schema: wrapper,
|
|
237
|
-
getRef: (0, refFns_js_2.toGetRef)(context.documentObject,
|
|
237
|
+
getRef: (0, refFns_js_2.toGetRef)(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
238
238
|
normalize: normalize_schema_shape_js_1.normalizeMergeMember,
|
|
239
239
|
system
|
|
240
240
|
});
|
|
@@ -268,7 +268,7 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
268
268
|
schema: withoutNull,
|
|
269
269
|
// A member's own `allOf`, or a member merged with the keywords beside
|
|
270
270
|
// the `oneOf`, is merged here, so it follows `allOfMember` too.
|
|
271
|
-
getRef: (0, refFns_js_2.toGetRef)(context.documentObject,
|
|
271
|
+
getRef: (0, refFns_js_2.toGetRef)(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
272
272
|
normalize: normalize_schema_shape_js_1.normalizeMergeMember,
|
|
273
273
|
system,
|
|
274
274
|
groupType: 'oneOf'
|
|
@@ -350,7 +350,7 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
350
350
|
const merged = (0, merge_union_js_1.mergeUnion)({
|
|
351
351
|
schema: withoutNull,
|
|
352
352
|
// As for `oneOf`: what is merged here follows `allOfMember`.
|
|
353
|
-
getRef: (0, refFns_js_2.toGetRef)(context.documentObject,
|
|
353
|
+
getRef: (0, refFns_js_2.toGetRef)(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
354
354
|
normalize: normalize_schema_shape_js_1.normalizeMergeMember,
|
|
355
355
|
system,
|
|
356
356
|
groupType: 'anyOf'
|