@skmtc/core 0.43.0 → 0.44.1
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/ref/DanglingRefError.d.ts +18 -3
- package/esm/oas/ref/DanglingRefError.js +17 -4
- package/esm/oas/ref/Ref.d.ts +23 -13
- package/esm/oas/ref/Ref.js +56 -37
- package/esm/parse/anyOfSystem.js +6 -8
- package/esm/parse/securityRequirements.d.ts +6 -0
- package/esm/parse/securityRequirements.js +10 -3
- 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/ref/DanglingRefError.d.ts +18 -3
- package/script/oas/ref/DanglingRefError.js +17 -4
- package/script/oas/ref/Ref.d.ts +23 -13
- package/script/oas/ref/Ref.js +56 -37
- package/script/parse/anyOfSystem.js +6 -8
- package/script/parse/securityRequirements.d.ts +6 -0
- package/script/parse/securityRequirements.js +10 -3
- 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
|
@@ -229,7 +229,7 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
229
229
|
const system = toAllOfSystem(context);
|
|
230
230
|
const merged = mergeIntersection({
|
|
231
231
|
schema: wrapper,
|
|
232
|
-
getRef: toGetRef(context.documentObject,
|
|
232
|
+
getRef: toGetRef(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
233
233
|
normalize: normalizeMergeMember,
|
|
234
234
|
system
|
|
235
235
|
});
|
|
@@ -263,7 +263,7 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
263
263
|
schema: withoutNull,
|
|
264
264
|
// A member's own `allOf`, or a member merged with the keywords beside
|
|
265
265
|
// the `oneOf`, is merged here, so it follows `allOfMember` too.
|
|
266
|
-
getRef: toGetRef(context.documentObject,
|
|
266
|
+
getRef: toGetRef(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
267
267
|
normalize: normalizeMergeMember,
|
|
268
268
|
system,
|
|
269
269
|
groupType: 'oneOf'
|
|
@@ -345,7 +345,7 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
345
345
|
const merged = mergeUnion({
|
|
346
346
|
schema: withoutNull,
|
|
347
347
|
// As for `oneOf`: what is merged here follows `allOfMember`.
|
|
348
|
-
getRef: toGetRef(context.documentObject,
|
|
348
|
+
getRef: toGetRef(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
349
349
|
normalize: normalizeMergeMember,
|
|
350
350
|
system,
|
|
351
351
|
groupType: 'anyOf'
|
|
@@ -229,7 +229,7 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
229
229
|
const system = toAllOfSystem(context);
|
|
230
230
|
const merged = mergeIntersection({
|
|
231
231
|
schema: wrapper,
|
|
232
|
-
getRef: toGetRef(context.documentObject,
|
|
232
|
+
getRef: toGetRef(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
233
233
|
normalize: normalizeMergeMember,
|
|
234
234
|
system
|
|
235
235
|
});
|
|
@@ -263,7 +263,7 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
263
263
|
schema: withoutNull,
|
|
264
264
|
// A member's own `allOf`, or a member merged with the keywords beside
|
|
265
265
|
// the `oneOf`, is merged here, so it follows `allOfMember` too.
|
|
266
|
-
getRef: toGetRef(context.documentObject,
|
|
266
|
+
getRef: toGetRef(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
267
267
|
normalize: normalizeMergeMember,
|
|
268
268
|
system,
|
|
269
269
|
groupType: 'oneOf'
|
|
@@ -345,7 +345,7 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
345
345
|
const merged = mergeUnion({
|
|
346
346
|
schema: withoutNull,
|
|
347
347
|
// As for `oneOf`: what is merged here follows `allOfMember`.
|
|
348
|
-
getRef: toGetRef(context.documentObject,
|
|
348
|
+
getRef: toGetRef(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
349
349
|
normalize: normalizeMergeMember,
|
|
350
350
|
system,
|
|
351
351
|
groupType: 'anyOf'
|
package/package.json
CHANGED
|
@@ -30,6 +30,7 @@ import type { GqlParseOptions, LogAtArgs, LogIssueArgs, LogIssueAtArgs, LogIssue
|
|
|
30
30
|
import type { ParseIssue } from './ParseIssue.js';
|
|
31
31
|
import type { OasRef } from '../oas/ref/Ref.js';
|
|
32
32
|
import type { OasRefData } from '../oas/ref/ref-types.js';
|
|
33
|
+
import { DanglingRefError } from '../oas/ref/DanglingRefError.js';
|
|
33
34
|
export type { ParseIssue, GqlIssueType } from './ParseIssue.js';
|
|
34
35
|
export type { GqlParseOptions, LogAtArgs, LogIssueArgs, LogIssueAtArgs, LogIssueNoKeyArgs, LogSkippedValuesArgs, ParseContextType, ParseErrorInput, ParseIssueInput, ParseWarningInput } from './parseTypes.js';
|
|
35
36
|
type OasProtocolState = {
|
|
@@ -53,7 +54,8 @@ type GqlProtocolState = {
|
|
|
53
54
|
};
|
|
54
55
|
type ProtocolState = OasProtocolState | GqlProtocolState;
|
|
55
56
|
type ToDanglingAllOfMemberArgs = {
|
|
56
|
-
|
|
57
|
+
/** Why the member names nothing: no schema has its name, or its `$ref`s loop. */
|
|
58
|
+
error: DanglingRefError;
|
|
57
59
|
/** The schema that holds the `allOf`. */
|
|
58
60
|
stackTrail: StackTrail;
|
|
59
61
|
};
|
|
@@ -182,7 +184,7 @@ export declare class ParseContext {
|
|
|
182
184
|
* removed. It is separate from `schema`: here core decides, at parse, and
|
|
183
185
|
* the generator never sees the member.
|
|
184
186
|
*/
|
|
185
|
-
toDanglingAllOfMember({
|
|
187
|
+
toDanglingAllOfMember({ error, stackTrail }: ToDanglingAllOfMemberArgs): OpenAPIV3.SchemaObject;
|
|
186
188
|
/**
|
|
187
189
|
* Register an error against a ref key — typically called when the
|
|
188
190
|
* target of a `$ref` (or type reference) fails to parse. `undefined`
|
|
@@ -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 _ParseContext_instances, _ParseContext_refConsumers, _ParseContext_refErrors, _ParseContext_oasRefs, _ParseContext_rootFrames, _ParseContext_removeComponent, _ParseContext_removeConsumer, _ParseContext_removePathParameterConsumer, _ParseContext_toRawComponentParameter, _ParseContext_logDependencyIssue, _ParseContext_toDocumentTrail, _ParseContext_checkRefs, _ParseContext_removeHolder;
|
|
13
|
+
var _ParseContext_instances, _ParseContext_refConsumers, _ParseContext_refErrors, _ParseContext_oasRefs, _ParseContext_rootFrames, _ParseContext_removeComponent, _ParseContext_removeConsumer, _ParseContext_removePathParameterConsumer, _ParseContext_toRawComponentParameter, _ParseContext_logDependencyIssue, _ParseContext_toDocumentTrail, _ParseContext_checkRefs, _ParseContext_toRefError, _ParseContext_toLoopOf, _ParseContext_removeHolder;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.ParseContext = void 0;
|
|
16
16
|
/**
|
|
@@ -404,15 +404,14 @@ class ParseContext {
|
|
|
404
404
|
* removed. It is separate from `schema`: here core decides, at parse, and
|
|
405
405
|
* the generator never sees the member.
|
|
406
406
|
*/
|
|
407
|
-
toDanglingAllOfMember({
|
|
408
|
-
const error = new DanglingRefError_js_1.DanglingRefError($ref);
|
|
407
|
+
toDanglingAllOfMember({ error, stackTrail }) {
|
|
409
408
|
if (!this.system.danglingRefs?.includes('allOfMember')) {
|
|
410
409
|
throw error;
|
|
411
410
|
}
|
|
412
411
|
this.logIssueNoKey({
|
|
413
412
|
level: 'warning',
|
|
414
413
|
message: `${error.message}. It is left out of the allOf merge (system.danglingRefs lists 'allOfMember').`,
|
|
415
|
-
parent: { $ref },
|
|
414
|
+
parent: { $ref: error.ref },
|
|
416
415
|
stackTrail,
|
|
417
416
|
type: 'DANGLING_REF'
|
|
418
417
|
});
|
|
@@ -688,10 +687,8 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
688
687
|
if (__classPrivateFieldGet(this, _ParseContext_refErrors, "f").has(toRefKey(ref.$ref))) {
|
|
689
688
|
return;
|
|
690
689
|
}
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
}
|
|
694
|
-
catch (error) {
|
|
690
|
+
const error = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toRefError).call(this, ref);
|
|
691
|
+
if (error !== undefined) {
|
|
695
692
|
if (!DanglingRefError_js_1.DanglingRefError.is(error)) {
|
|
696
693
|
const message = error instanceof Error ? error.message : String(error);
|
|
697
694
|
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_removeHolder).call(this, {
|
|
@@ -722,6 +719,24 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
722
719
|
}
|
|
723
720
|
}
|
|
724
721
|
});
|
|
722
|
+
}, _ParseContext_toRefError = function _ParseContext_toRefError(ref) {
|
|
723
|
+
try {
|
|
724
|
+
ref.resolveOnce();
|
|
725
|
+
}
|
|
726
|
+
catch (error) {
|
|
727
|
+
return error;
|
|
728
|
+
}
|
|
729
|
+
const loop = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toLoopOf).call(this, ref);
|
|
730
|
+
return loop === undefined ? undefined : new DanglingRefError_js_1.DanglingRefError(ref.$ref, { loop: loop.map(({ $ref }) => $ref) });
|
|
731
|
+
}, _ParseContext_toLoopOf = function _ParseContext_toLoopOf(ref) {
|
|
732
|
+
try {
|
|
733
|
+
const loop = ref.toLoop();
|
|
734
|
+
return loop?.includes(ref) ? loop : undefined;
|
|
735
|
+
}
|
|
736
|
+
catch {
|
|
737
|
+
// A ref further on names nothing or the wrong kind: it reports that itself.
|
|
738
|
+
return undefined;
|
|
739
|
+
}
|
|
725
740
|
}, _ParseContext_removeHolder = function _ParseContext_removeHolder({ consumer, ref, error, type, message }) {
|
|
726
741
|
this.logIssueNoKey({
|
|
727
742
|
level: 'error',
|
|
@@ -185,8 +185,9 @@ export type AnyOasDocument = OpenAPIV2.Document | OpenAPIV3.Document | OpenAPIV3
|
|
|
185
185
|
* of two or more members as any value. The schema keeps its other keywords.
|
|
186
186
|
* One for each schema.
|
|
187
187
|
*
|
|
188
|
-
* `DANGLING_REF` — a `$ref` names nothing in the document
|
|
189
|
-
*
|
|
188
|
+
* `DANGLING_REF` — a `$ref` names nothing in the document: no component has
|
|
189
|
+
* its name, or it is part of a loop of `$ref`s (`A` is a `$ref` to `B`, and
|
|
190
|
+
* `B` to `A`). One for each place the `$ref` is written. A `warning` when `system.danglingRefs` lists
|
|
190
191
|
* the `$ref`'s kind: the ref stays, and resolving it throws
|
|
191
192
|
* `DanglingRefError`; with `allOfMember` listed, a `$ref` that core merges
|
|
192
193
|
* (in an `allOf`, or in a `oneOf` or `anyOf` member) is left out of the
|
|
@@ -2,6 +2,7 @@ import "../_dnt.polyfills.js";
|
|
|
2
2
|
import type { RefName } from '../types/RefName.js';
|
|
3
3
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
4
4
|
import type { ReferenceObject } from '../parse/v3-0/_merge-all-of/types.js';
|
|
5
|
+
import { DanglingRefError } from '../oas/ref/DanglingRefError.js';
|
|
5
6
|
/**
|
|
6
7
|
* Extracts a reference name from an OpenAPI $ref string.
|
|
7
8
|
*
|
|
@@ -121,7 +122,8 @@ export declare const isRef: (value: unknown) => value is Ref;
|
|
|
121
122
|
* @param oasDocument - The OpenAPI document containing the schemas to resolve against
|
|
122
123
|
* @returns A function that resolves reference objects to schema objects
|
|
123
124
|
*
|
|
124
|
-
* @throws {DanglingRefError} When a reference names no schema in the document
|
|
125
|
+
* @throws {DanglingRefError} When a reference names no schema in the document,
|
|
126
|
+
* or its chain of references loops, unless `onDangling` reads something in its place
|
|
125
127
|
*
|
|
126
128
|
* @example Basic usage
|
|
127
129
|
* ```typescript
|
|
@@ -172,6 +174,9 @@ export declare const isRef: (value: unknown) => value is Ref;
|
|
|
172
174
|
* ```
|
|
173
175
|
*/
|
|
174
176
|
export declare const toGetRef: (oasDocument: OpenAPIV3.Document, onDangling?: OnDangling) => ({ $ref }: ReferenceObject) => OpenAPIV3.SchemaObject;
|
|
175
|
-
/**
|
|
176
|
-
|
|
177
|
+
/**
|
|
178
|
+
* What a resolver reads in place of a `$ref` that names nothing: no schema
|
|
179
|
+
* has its name, or its chain of `$ref`s loops. It may throw `error`.
|
|
180
|
+
*/
|
|
181
|
+
type OnDangling = (error: DanglingRefError) => OpenAPIV3.SchemaObject;
|
|
177
182
|
export {};
|
package/script/helpers/refFns.js
CHANGED
|
@@ -143,7 +143,8 @@ exports.isRef = isRef;
|
|
|
143
143
|
* @param oasDocument - The OpenAPI document containing the schemas to resolve against
|
|
144
144
|
* @returns A function that resolves reference objects to schema objects
|
|
145
145
|
*
|
|
146
|
-
* @throws {DanglingRefError} When a reference names no schema in the document
|
|
146
|
+
* @throws {DanglingRefError} When a reference names no schema in the document,
|
|
147
|
+
* or its chain of references loops, unless `onDangling` reads something in its place
|
|
147
148
|
*
|
|
148
149
|
* @example Basic usage
|
|
149
150
|
* ```typescript
|
|
@@ -193,18 +194,34 @@ exports.isRef = isRef;
|
|
|
193
194
|
* }
|
|
194
195
|
* ```
|
|
195
196
|
*/
|
|
196
|
-
const toGetRef = (oasDocument, onDangling) => ({ $ref }) => {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
197
|
+
const toGetRef = (oasDocument, onDangling) => ({ $ref }) => toTargetSchema({ oasDocument, onDangling, $ref, followed: [] });
|
|
198
|
+
exports.toGetRef = toGetRef;
|
|
199
|
+
/**
|
|
200
|
+
* The schema at the end of the chain of `$ref`s. A `$ref` that names nothing,
|
|
201
|
+
* or a chain that comes back to a component it has passed (`A` is a `$ref`
|
|
202
|
+
* to `B`, and `B` to `A`), gives `onDangling` a `DanglingRefError`, or throws it.
|
|
203
|
+
*/
|
|
204
|
+
const toTargetSchema = ({ oasDocument, onDangling, $ref, followed }) => {
|
|
205
|
+
const item = oasDocument.components?.schemas?.[(0, exports.toRefName)($ref)];
|
|
206
|
+
if (!item) {
|
|
207
|
+
return toDangling(onDangling, new DanglingRefError_js_1.DanglingRefError($ref));
|
|
201
208
|
}
|
|
202
|
-
if (item) {
|
|
209
|
+
if (!(0, exports.isRef)(item)) {
|
|
203
210
|
return item;
|
|
204
211
|
}
|
|
212
|
+
const passed = [...followed, $ref];
|
|
213
|
+
const loopStart = passed.findIndex(each => (0, exports.toRefName)(each) === (0, exports.toRefName)(item.$ref));
|
|
214
|
+
if (loopStart === -1) {
|
|
215
|
+
return toTargetSchema({ oasDocument, onDangling, $ref: item.$ref, followed: passed });
|
|
216
|
+
}
|
|
217
|
+
// The `$ref`s written in the loop's components: each one after the `$ref`
|
|
218
|
+
// that first named one of them, as `OasRef.toLoop` gives them.
|
|
219
|
+
const loop = [...passed.slice(loopStart + 1), item.$ref];
|
|
220
|
+
return toDangling(onDangling, new DanglingRefError_js_1.DanglingRefError(passed[0] ?? $ref, { loop }));
|
|
221
|
+
};
|
|
222
|
+
const toDangling = (onDangling, error) => {
|
|
205
223
|
if (onDangling) {
|
|
206
|
-
return onDangling(
|
|
224
|
+
return onDangling(error);
|
|
207
225
|
}
|
|
208
|
-
throw
|
|
226
|
+
throw error;
|
|
209
227
|
};
|
|
210
|
-
exports.toGetRef = toGetRef;
|
|
@@ -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
|
|
@@ -303,18 +316,15 @@ export declare class OasRef<T extends OasRefData['refType']> extends OasBase {
|
|
|
303
316
|
* Whether the value is `readOnly` at this site, as Forge reads it: on this
|
|
304
317
|
* reference (`{ allOf: [{ $ref }], readOnly: true }`), or on what it points
|
|
305
318
|
* to, through any chain of references. A `readOnly: false` does not undo
|
|
306
|
-
* another's `true`. `false` for a reference to anything but a schema.
|
|
307
|
-
*
|
|
308
|
-
* @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.
|
|
309
321
|
*/
|
|
310
|
-
isReadOnly(
|
|
322
|
+
isReadOnly(): boolean;
|
|
311
323
|
/**
|
|
312
324
|
* Whether the value is `writeOnly` at this site: on this reference, or on
|
|
313
325
|
* what it points to, as {@link isReadOnly} reads `readOnly`.
|
|
314
|
-
*
|
|
315
|
-
* @param lookupsPerformed - Internal counter that stops a chain of references with no schema
|
|
316
326
|
*/
|
|
317
|
-
isWriteOnly(
|
|
327
|
+
isWriteOnly(): boolean;
|
|
318
328
|
/**
|
|
319
329
|
* Returns the discriminated parsed document this ref resolves
|
|
320
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
|
|
@@ -557,7 +571,7 @@ class OasRef extends OasBase_js_1.OasBase {
|
|
|
557
571
|
if (!this.hasSiblings()) {
|
|
558
572
|
return false;
|
|
559
573
|
}
|
|
560
|
-
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);
|
|
561
575
|
// Widened from the generic ResolvedRef<T>, so `oasType` narrows them.
|
|
562
576
|
const original = target;
|
|
563
577
|
const applied = resolved;
|
|
@@ -584,35 +598,18 @@ class OasRef extends OasBase_js_1.OasBase {
|
|
|
584
598
|
* Whether the value is `readOnly` at this site, as Forge reads it: on this
|
|
585
599
|
* reference (`{ allOf: [{ $ref }], readOnly: true }`), or on what it points
|
|
586
600
|
* to, through any chain of references. A `readOnly: false` does not undo
|
|
587
|
-
* another's `true`. `false` for a reference to anything but a schema.
|
|
588
|
-
*
|
|
589
|
-
* @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.
|
|
590
603
|
*/
|
|
591
|
-
isReadOnly(
|
|
592
|
-
|
|
593
|
-
return true;
|
|
594
|
-
}
|
|
595
|
-
if (lookupsPerformed >= MAX_LOOKUPS) {
|
|
596
|
-
return false;
|
|
597
|
-
}
|
|
598
|
-
const resolved = this.resolveOnce();
|
|
599
|
-
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() });
|
|
600
606
|
}
|
|
601
607
|
/**
|
|
602
608
|
* Whether the value is `writeOnly` at this site: on this reference, or on
|
|
603
609
|
* what it points to, as {@link isReadOnly} reads `readOnly`.
|
|
604
|
-
*
|
|
605
|
-
* @param lookupsPerformed - Internal counter that stops a chain of references with no schema
|
|
606
610
|
*/
|
|
607
|
-
isWriteOnly(
|
|
608
|
-
|
|
609
|
-
return true;
|
|
610
|
-
}
|
|
611
|
-
if (lookupsPerformed >= MAX_LOOKUPS) {
|
|
612
|
-
return false;
|
|
613
|
-
}
|
|
614
|
-
const resolved = this.resolveOnce();
|
|
615
|
-
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() });
|
|
616
613
|
}
|
|
617
614
|
/**
|
|
618
615
|
* Returns the discriminated parsed document this ref resolves
|
|
@@ -647,15 +644,21 @@ class OasRef extends OasBase_js_1.OasBase {
|
|
|
647
644
|
}
|
|
648
645
|
}
|
|
649
646
|
exports.OasRef = OasRef;
|
|
650
|
-
_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() {
|
|
651
648
|
if (__classPrivateFieldGet(this, _OasRef_resolution, "f") !== undefined) {
|
|
652
649
|
return __classPrivateFieldGet(this, _OasRef_resolution, "f");
|
|
653
650
|
}
|
|
654
|
-
|
|
655
|
-
|
|
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");
|
|
656
659
|
}
|
|
657
660
|
const resolved = this.resolveOnce();
|
|
658
|
-
const target = resolved.isRef() ? resolved
|
|
661
|
+
const target = resolved.isRef() ? __classPrivateFieldGet(resolved, _OasRef_instances, "m", _OasRef_toChainResolution).call(resolved).resolved : resolved;
|
|
659
662
|
const resolution = { target, resolved: __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toSiteSchema).call(this, target) };
|
|
660
663
|
__classPrivateFieldSet(this, _OasRef_resolution, resolution, "f");
|
|
661
664
|
return resolution;
|
|
@@ -671,6 +674,13 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
|
|
|
671
674
|
// A schema's copy is a schema of the same class. TypeScript cannot relate
|
|
672
675
|
// OasSchema to ResolvedRef<T> for a generic T, as in resolveOnce().
|
|
673
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);
|
|
674
684
|
}, _OasRef_resolveOasOnce = function _OasRef_resolveOasOnce(document, refName) {
|
|
675
685
|
// A `#/components/<bucket>/<name>` ref names its bucket. A request body
|
|
676
686
|
// that is a `$ref` to `#/components/schemas/Pet` names a schema, so it is
|
|
@@ -712,4 +722,13 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
|
|
|
712
722
|
// oasType check catch any caller that constructed a non-schema
|
|
713
723
|
// ref pointing at a GQL document.
|
|
714
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);
|
|
715
734
|
};
|
|
@@ -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
|
/**
|
|
@@ -22,6 +22,8 @@ export type SecurityCheck = {
|
|
|
22
22
|
declaredSchemes: string[];
|
|
23
23
|
/** Declared scheme names that failed to parse. */
|
|
24
24
|
failedSchemes: string[];
|
|
25
|
+
/** Declared scheme names of a valid type core does not parse yet (`mutualTLS`). */
|
|
26
|
+
unmodeledSchemes: string[];
|
|
25
27
|
context: ParseContextType;
|
|
26
28
|
};
|
|
27
29
|
export type ToSecurityCheckArgs = {
|
|
@@ -64,6 +66,10 @@ export type ToOperationsWithValidSecurityArgs<Item extends SecuredItem> = {
|
|
|
64
66
|
* of the scheme. When the parser removes the scheme later (one that is a
|
|
65
67
|
* `$ref` that names nothing), the item goes with it, and so is never kept
|
|
66
68
|
* without its auth.
|
|
69
|
+
*
|
|
70
|
+
* A scheme of a type core does not parse yet (`mutualTLS`) is not a
|
|
71
|
+
* dependency: it is never in the parsed document, and its
|
|
72
|
+
* `INVALID_SECURITY_SCHEME` error would remove every item that names it.
|
|
67
73
|
*/
|
|
68
74
|
export declare const toOperationsWithValidSecurity: <Item extends SecuredItem>({ items, check }: ToOperationsWithValidSecurityArgs<Item>) => Item[];
|
|
69
75
|
export {};
|