@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
|
@@ -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`
|
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
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");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
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;
|
|
12
|
+
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;
|
|
13
13
|
/**
|
|
14
14
|
* Unified parse context for both OAS and GraphQL inputs.
|
|
15
15
|
*
|
|
@@ -401,15 +401,14 @@ export class ParseContext {
|
|
|
401
401
|
* removed. It is separate from `schema`: here core decides, at parse, and
|
|
402
402
|
* the generator never sees the member.
|
|
403
403
|
*/
|
|
404
|
-
toDanglingAllOfMember({
|
|
405
|
-
const error = new DanglingRefError($ref);
|
|
404
|
+
toDanglingAllOfMember({ error, stackTrail }) {
|
|
406
405
|
if (!this.system.danglingRefs?.includes('allOfMember')) {
|
|
407
406
|
throw error;
|
|
408
407
|
}
|
|
409
408
|
this.logIssueNoKey({
|
|
410
409
|
level: 'warning',
|
|
411
410
|
message: `${error.message}. It is left out of the allOf merge (system.danglingRefs lists 'allOfMember').`,
|
|
412
|
-
parent: { $ref },
|
|
411
|
+
parent: { $ref: error.ref },
|
|
413
412
|
stackTrail,
|
|
414
413
|
type: 'DANGLING_REF'
|
|
415
414
|
});
|
|
@@ -684,10 +683,8 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
684
683
|
if (__classPrivateFieldGet(this, _ParseContext_refErrors, "f").has(toRefKey(ref.$ref))) {
|
|
685
684
|
return;
|
|
686
685
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
}
|
|
690
|
-
catch (error) {
|
|
686
|
+
const error = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toRefError).call(this, ref);
|
|
687
|
+
if (error !== undefined) {
|
|
691
688
|
if (!DanglingRefError.is(error)) {
|
|
692
689
|
const message = error instanceof Error ? error.message : String(error);
|
|
693
690
|
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_removeHolder).call(this, {
|
|
@@ -718,6 +715,24 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
718
715
|
}
|
|
719
716
|
}
|
|
720
717
|
});
|
|
718
|
+
}, _ParseContext_toRefError = function _ParseContext_toRefError(ref) {
|
|
719
|
+
try {
|
|
720
|
+
ref.resolveOnce();
|
|
721
|
+
}
|
|
722
|
+
catch (error) {
|
|
723
|
+
return error;
|
|
724
|
+
}
|
|
725
|
+
const loop = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toLoopOf).call(this, ref);
|
|
726
|
+
return loop === undefined ? undefined : new DanglingRefError(ref.$ref, { loop: loop.map(({ $ref }) => $ref) });
|
|
727
|
+
}, _ParseContext_toLoopOf = function _ParseContext_toLoopOf(ref) {
|
|
728
|
+
try {
|
|
729
|
+
const loop = ref.toLoop();
|
|
730
|
+
return loop?.includes(ref) ? loop : undefined;
|
|
731
|
+
}
|
|
732
|
+
catch {
|
|
733
|
+
// A ref further on names nothing or the wrong kind: it reports that itself.
|
|
734
|
+
return undefined;
|
|
735
|
+
}
|
|
721
736
|
}, _ParseContext_removeHolder = function _ParseContext_removeHolder({ consumer, ref, error, type, message }) {
|
|
722
737
|
this.logIssueNoKey({
|
|
723
738
|
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
|
package/esm/helpers/refFns.d.ts
CHANGED
|
@@ -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/esm/helpers/refFns.js
CHANGED
|
@@ -138,7 +138,8 @@ export const isRef = (value) => {
|
|
|
138
138
|
* @param oasDocument - The OpenAPI document containing the schemas to resolve against
|
|
139
139
|
* @returns A function that resolves reference objects to schema objects
|
|
140
140
|
*
|
|
141
|
-
* @throws {DanglingRefError} When a reference names no schema in the document
|
|
141
|
+
* @throws {DanglingRefError} When a reference names no schema in the document,
|
|
142
|
+
* or its chain of references loops, unless `onDangling` reads something in its place
|
|
142
143
|
*
|
|
143
144
|
* @example Basic usage
|
|
144
145
|
* ```typescript
|
|
@@ -188,17 +189,33 @@ export const isRef = (value) => {
|
|
|
188
189
|
* }
|
|
189
190
|
* ```
|
|
190
191
|
*/
|
|
191
|
-
export const toGetRef = (oasDocument, onDangling) => ({ $ref }) => {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
export const toGetRef = (oasDocument, onDangling) => ({ $ref }) => toTargetSchema({ oasDocument, onDangling, $ref, followed: [] });
|
|
193
|
+
/**
|
|
194
|
+
* The schema at the end of the chain of `$ref`s. A `$ref` that names nothing,
|
|
195
|
+
* or a chain that comes back to a component it has passed (`A` is a `$ref`
|
|
196
|
+
* to `B`, and `B` to `A`), gives `onDangling` a `DanglingRefError`, or throws it.
|
|
197
|
+
*/
|
|
198
|
+
const toTargetSchema = ({ oasDocument, onDangling, $ref, followed }) => {
|
|
199
|
+
const item = oasDocument.components?.schemas?.[toRefName($ref)];
|
|
200
|
+
if (!item) {
|
|
201
|
+
return toDangling(onDangling, new DanglingRefError($ref));
|
|
196
202
|
}
|
|
197
|
-
if (item) {
|
|
203
|
+
if (!isRef(item)) {
|
|
198
204
|
return item;
|
|
199
205
|
}
|
|
206
|
+
const passed = [...followed, $ref];
|
|
207
|
+
const loopStart = passed.findIndex(each => toRefName(each) === toRefName(item.$ref));
|
|
208
|
+
if (loopStart === -1) {
|
|
209
|
+
return toTargetSchema({ oasDocument, onDangling, $ref: item.$ref, followed: passed });
|
|
210
|
+
}
|
|
211
|
+
// The `$ref`s written in the loop's components: each one after the `$ref`
|
|
212
|
+
// that first named one of them, as `OasRef.toLoop` gives them.
|
|
213
|
+
const loop = [...passed.slice(loopStart + 1), item.$ref];
|
|
214
|
+
return toDangling(onDangling, new DanglingRefError(passed[0] ?? $ref, { loop }));
|
|
215
|
+
};
|
|
216
|
+
const toDangling = (onDangling, error) => {
|
|
200
217
|
if (onDangling) {
|
|
201
|
-
return onDangling(
|
|
218
|
+
return onDangling(error);
|
|
202
219
|
}
|
|
203
|
-
throw
|
|
220
|
+
throw error;
|
|
204
221
|
};
|
|
@@ -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,5 +1,9 @@
|
|
|
1
|
+
import "../../_dnt.polyfills.js";
|
|
1
2
|
/**
|
|
2
|
-
* Thrown when a reference that names nothing in the document is resolved
|
|
3
|
+
* Thrown when a reference that names nothing in the document is resolved:
|
|
4
|
+
* no component has its name, or its chain of `$ref`s comes back to one it
|
|
5
|
+
* has passed (`A` is a `$ref` to `B`, and `B` to `A`), so it never reaches a
|
|
6
|
+
* component.
|
|
3
7
|
*
|
|
4
8
|
* By default the parser removes what holds such a reference, so a generator
|
|
5
9
|
* never meets one. When `client.json` `system.danglingRefs` lists the
|
|
@@ -7,10 +11,11 @@
|
|
|
7
11
|
* this error and render something else in its place. Test for it with
|
|
8
12
|
* {@link DanglingRefError.is}, not `instanceof`.
|
|
9
13
|
*/
|
|
10
|
-
import "../../_dnt.polyfills.js";
|
|
11
14
|
export class DanglingRefError extends Error {
|
|
12
|
-
constructor(ref) {
|
|
13
|
-
super(
|
|
15
|
+
constructor(ref, { loop } = {}) {
|
|
16
|
+
super(loop === undefined
|
|
17
|
+
? `Ref "${ref}" names nothing in the document`
|
|
18
|
+
: `Ref "${ref}" leads into a loop of $refs (${[...loop, ...loop.slice(0, 1)].join(' → ')}) and never reaches a component`);
|
|
14
19
|
/** The `$ref`, or the component name, that names nothing. */
|
|
15
20
|
Object.defineProperty(this, "ref", {
|
|
16
21
|
enumerable: true,
|
|
@@ -18,8 +23,16 @@ export class DanglingRefError extends Error {
|
|
|
18
23
|
writable: true,
|
|
19
24
|
value: void 0
|
|
20
25
|
});
|
|
26
|
+
/** When the chain of `$ref`s loops: see {@link DanglingRefErrorOptions.loop}. */
|
|
27
|
+
Object.defineProperty(this, "loop", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: void 0
|
|
32
|
+
});
|
|
21
33
|
this.name = 'DanglingRefError';
|
|
22
34
|
this.ref = ref;
|
|
35
|
+
this.loop = loop;
|
|
23
36
|
}
|
|
24
37
|
/**
|
|
25
38
|
* True when `error` is a `DanglingRefError`. It reads the error's name,
|
package/esm/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/esm/oas/ref/Ref.js
CHANGED
|
@@ -9,14 +9,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
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");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _OasRef_instances, _OasRef_document, _OasRef_resolution, _OasRef_toResolution, _OasRef_toSiteSchema, _OasRef_resolveOasOnce, _OasRef_resolveGqlOnce;
|
|
12
|
+
var _OasRef_instances, _OasRef_document, _OasRef_resolution, _OasRef_toResolution, _OasRef_toChainResolution, _OasRef_toSiteSchema, _OasRef_toLoop, _OasRef_resolveOasOnce, _OasRef_resolveGqlOnce, _OasRef_someOnChain;
|
|
13
13
|
import "../../_dnt.polyfills.js";
|
|
14
14
|
import { traverseSchema } from '../schemaPath/traverseSchema.js';
|
|
15
15
|
import { toRefName } from '../../helpers/refFns.js';
|
|
16
16
|
import { OasBase } from '../../types/OasBase.js';
|
|
17
17
|
import { DanglingRefError } from './DanglingRefError.js';
|
|
18
18
|
import { changesTarget, changesValues, hasSiblingKeywords, mergeSiblingKeywords, toSkippedSiblings } from '../schema/siblings.js';
|
|
19
|
-
const MAX_LOOKUPS = 10;
|
|
20
19
|
/**
|
|
21
20
|
* Converts a ref type to its plural components path.
|
|
22
21
|
*/
|
|
@@ -68,7 +67,7 @@ const toLookupName = ($ref) => {
|
|
|
68
67
|
* - **Type Safety**: Generic parameter ensures resolved types match the reference type
|
|
69
68
|
* - **Lazy Resolution**: References are resolved on-demand, not during construction
|
|
70
69
|
* - **Chain Resolution**: Handles references that point to other references
|
|
71
|
-
* - **
|
|
70
|
+
* - **Loop Detection**: A chain of references that loops names nothing ({@link OasRef.toLoop})
|
|
72
71
|
* - **Type Validation**: Ensures resolved objects match expected reference types
|
|
73
72
|
*
|
|
74
73
|
* @template T - The type of component this reference points to
|
|
@@ -434,8 +433,8 @@ export class OasRef extends OasBase {
|
|
|
434
433
|
/**
|
|
435
434
|
* Recursively resolves this reference to its final target component.
|
|
436
435
|
*
|
|
437
|
-
* Follows
|
|
438
|
-
*
|
|
436
|
+
* Follows the chain of references until it reaches a component that is
|
|
437
|
+
* not a reference. A schema reference returns the
|
|
439
438
|
* schema at this site: when the keywords next to it, or next to a
|
|
440
439
|
* reference on the chain ({@link SiblingKeywords}), change the target, a
|
|
441
440
|
* copy of the target with them applied. When they change nothing, the
|
|
@@ -445,12 +444,27 @@ export class OasRef extends OasBase {
|
|
|
445
444
|
* model every reference to it sees, and a copy is built once, kept on
|
|
446
445
|
* this reference, and returned on every call.
|
|
447
446
|
*
|
|
448
|
-
* @param lookupsPerformed - Internal counter to prevent infinite recursion
|
|
449
447
|
* @returns The resolved component
|
|
450
|
-
* @throws
|
|
448
|
+
* @throws {DanglingRefError} when a reference on the chain names nothing,
|
|
449
|
+
* or the chain loops ({@link toLoop}), so it never reaches a component.
|
|
450
|
+
* The parser keeps either one only when `system.danglingRefs` lists its kind.
|
|
451
|
+
* @throws Error when a reference on the chain names a component of another
|
|
452
|
+
* kind (see {@link resolveOnce})
|
|
451
453
|
*/
|
|
452
|
-
resolve(
|
|
453
|
-
return __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toResolution).call(this
|
|
454
|
+
resolve() {
|
|
455
|
+
return __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toResolution).call(this).resolved;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* The references that form the loop this reference's chain comes back to,
|
|
459
|
+
* starting with the first one it comes back to, or `undefined` when the
|
|
460
|
+
* chain reaches a component. `A` a `$ref` to `B`, and `B` to `A`, form a
|
|
461
|
+
* loop: from `A` the chain goes to `B`, then to `A` again, and never
|
|
462
|
+
* reaches a component. A reference that leads into a loop is not part of it.
|
|
463
|
+
*
|
|
464
|
+
* @throws what {@link resolveOnce} throws, at any step of the chain
|
|
465
|
+
*/
|
|
466
|
+
toLoop() {
|
|
467
|
+
return __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toLoop).call(this, [this]);
|
|
454
468
|
}
|
|
455
469
|
/**
|
|
456
470
|
* Resolves this reference one level. Dispatches on the document's
|
|
@@ -554,7 +568,7 @@ export class OasRef extends OasBase {
|
|
|
554
568
|
if (!this.hasSiblings()) {
|
|
555
569
|
return false;
|
|
556
570
|
}
|
|
557
|
-
const { target, resolved } = __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toResolution).call(this
|
|
571
|
+
const { target, resolved } = __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toResolution).call(this);
|
|
558
572
|
// Widened from the generic ResolvedRef<T>, so `oasType` narrows them.
|
|
559
573
|
const original = target;
|
|
560
574
|
const applied = resolved;
|
|
@@ -581,35 +595,18 @@ export class OasRef extends OasBase {
|
|
|
581
595
|
* Whether the value is `readOnly` at this site, as Forge reads it: on this
|
|
582
596
|
* reference (`{ allOf: [{ $ref }], readOnly: true }`), or on what it points
|
|
583
597
|
* to, through any chain of references. A `readOnly: false` does not undo
|
|
584
|
-
* another's `true`. `false` for a reference to anything but a schema.
|
|
585
|
-
*
|
|
586
|
-
* @param lookupsPerformed - Internal counter that stops a chain of references with no schema
|
|
598
|
+
* another's `true`. `false` for a reference to anything but a schema. In a
|
|
599
|
+
* loop ({@link toLoop}), which reaches no schema, only the references count.
|
|
587
600
|
*/
|
|
588
|
-
isReadOnly(
|
|
589
|
-
|
|
590
|
-
return true;
|
|
591
|
-
}
|
|
592
|
-
if (lookupsPerformed >= MAX_LOOKUPS) {
|
|
593
|
-
return false;
|
|
594
|
-
}
|
|
595
|
-
const resolved = this.resolveOnce();
|
|
596
|
-
return resolved.isRef() ? resolved.isReadOnly(lookupsPerformed + 1) : resolved.isReadOnly();
|
|
601
|
+
isReadOnly() {
|
|
602
|
+
return __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_someOnChain).call(this, { onRef: ref => ref.readOnly === true, onTarget: target => target.isReadOnly() });
|
|
597
603
|
}
|
|
598
604
|
/**
|
|
599
605
|
* Whether the value is `writeOnly` at this site: on this reference, or on
|
|
600
606
|
* what it points to, as {@link isReadOnly} reads `readOnly`.
|
|
601
|
-
*
|
|
602
|
-
* @param lookupsPerformed - Internal counter that stops a chain of references with no schema
|
|
603
607
|
*/
|
|
604
|
-
isWriteOnly(
|
|
605
|
-
|
|
606
|
-
return true;
|
|
607
|
-
}
|
|
608
|
-
if (lookupsPerformed >= MAX_LOOKUPS) {
|
|
609
|
-
return false;
|
|
610
|
-
}
|
|
611
|
-
const resolved = this.resolveOnce();
|
|
612
|
-
return resolved.isRef() ? resolved.isWriteOnly(lookupsPerformed + 1) : resolved.isWriteOnly();
|
|
608
|
+
isWriteOnly() {
|
|
609
|
+
return __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_someOnChain).call(this, { onRef: ref => ref.writeOnly === true, onTarget: target => target.isWriteOnly() });
|
|
613
610
|
}
|
|
614
611
|
/**
|
|
615
612
|
* Returns the discriminated parsed document this ref resolves
|
|
@@ -643,15 +640,21 @@ export class OasRef extends OasBase {
|
|
|
643
640
|
};
|
|
644
641
|
}
|
|
645
642
|
}
|
|
646
|
-
_OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_instances = new WeakSet(), _OasRef_toResolution = function _OasRef_toResolution(
|
|
643
|
+
_OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_instances = new WeakSet(), _OasRef_toResolution = function _OasRef_toResolution() {
|
|
647
644
|
if (__classPrivateFieldGet(this, _OasRef_resolution, "f") !== undefined) {
|
|
648
645
|
return __classPrivateFieldGet(this, _OasRef_resolution, "f");
|
|
649
646
|
}
|
|
650
|
-
|
|
651
|
-
|
|
647
|
+
const loop = this.toLoop();
|
|
648
|
+
if (loop !== undefined) {
|
|
649
|
+
throw new DanglingRefError(this.$ref, { loop: loop.map(({ $ref }) => $ref) });
|
|
650
|
+
}
|
|
651
|
+
return __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toChainResolution).call(this);
|
|
652
|
+
}, _OasRef_toChainResolution = function _OasRef_toChainResolution() {
|
|
653
|
+
if (__classPrivateFieldGet(this, _OasRef_resolution, "f") !== undefined) {
|
|
654
|
+
return __classPrivateFieldGet(this, _OasRef_resolution, "f");
|
|
652
655
|
}
|
|
653
656
|
const resolved = this.resolveOnce();
|
|
654
|
-
const target = resolved.isRef() ? resolved
|
|
657
|
+
const target = resolved.isRef() ? __classPrivateFieldGet(resolved, _OasRef_instances, "m", _OasRef_toChainResolution).call(resolved).resolved : resolved;
|
|
655
658
|
const resolution = { target, resolved: __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toSiteSchema).call(this, target) };
|
|
656
659
|
__classPrivateFieldSet(this, _OasRef_resolution, resolution, "f");
|
|
657
660
|
return resolution;
|
|
@@ -667,6 +670,13 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
|
|
|
667
670
|
// A schema's copy is a schema of the same class. TypeScript cannot relate
|
|
668
671
|
// OasSchema to ResolvedRef<T> for a generic T, as in resolveOnce().
|
|
669
672
|
return changesTarget(copy, component, this) ? copy : target;
|
|
673
|
+
}, _OasRef_toLoop = function _OasRef_toLoop(followed) {
|
|
674
|
+
const next = this.resolveOnce();
|
|
675
|
+
if (!next.isRef()) {
|
|
676
|
+
return undefined;
|
|
677
|
+
}
|
|
678
|
+
const index = followed.indexOf(next);
|
|
679
|
+
return index === -1 ? __classPrivateFieldGet(next, _OasRef_instances, "m", _OasRef_toLoop).call(next, [...followed, next]) : followed.slice(index);
|
|
670
680
|
}, _OasRef_resolveOasOnce = function _OasRef_resolveOasOnce(document, refName) {
|
|
671
681
|
// A `#/components/<bucket>/<name>` ref names its bucket. A request body
|
|
672
682
|
// that is a `$ref` to `#/components/schemas/Pet` names a schema, so it is
|
|
@@ -708,4 +718,13 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
|
|
|
708
718
|
// oasType check catch any caller that constructed a non-schema
|
|
709
719
|
// ref pointing at a GQL document.
|
|
710
720
|
return document.registry.schemas[refName];
|
|
721
|
+
}, _OasRef_someOnChain = function _OasRef_someOnChain(check, passed = new Set()) {
|
|
722
|
+
if (check.onRef(this)) {
|
|
723
|
+
return true;
|
|
724
|
+
}
|
|
725
|
+
if (passed.has(this)) {
|
|
726
|
+
return false;
|
|
727
|
+
}
|
|
728
|
+
const next = this.resolveOnce();
|
|
729
|
+
return next.isRef() ? __classPrivateFieldGet(next, _OasRef_instances, "m", _OasRef_someOnChain).call(next, check, new Set([...passed, this])) : check.onTarget(next);
|
|
711
730
|
};
|
package/esm/parse/anyOfSystem.js
CHANGED
|
@@ -30,13 +30,11 @@ const isScalarMember = (member) => {
|
|
|
30
30
|
return (Array.isArray(fields.enum) &&
|
|
31
31
|
fields.enum.every(value => value === null || SCALAR_VALUE_TYPES.includes(typeof value)));
|
|
32
32
|
};
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return steps < 10 ? toMemberSchema(getRef(member), getRef, steps + 1) : undefined;
|
|
39
|
-
};
|
|
33
|
+
/**
|
|
34
|
+
* The schema a member names. `getRef` follows the whole chain of `$ref`s, and
|
|
35
|
+
* a chain that loops names nothing, as in `toGetRef`.
|
|
36
|
+
*/
|
|
37
|
+
const toMemberSchema = (member, getRef) => ('$ref' in member ? getRef(member) : member);
|
|
40
38
|
/**
|
|
41
39
|
* Whether `system.anyOf: unknown` reads an `anyOf` as any value, as
|
|
42
40
|
* Cloudflare's `cf` reads it: when it has two or more members, not counting a
|
|
@@ -52,7 +50,7 @@ export const isUnknownAnyOf = ({ members, setting, getRef }) => {
|
|
|
52
50
|
return false;
|
|
53
51
|
}
|
|
54
52
|
const values = members.filter(member => !isNullMember(member)).map(member => toMemberSchema(member, getRef));
|
|
55
|
-
return values.length > 1 && !values.every(
|
|
53
|
+
return values.length > 1 && !values.every(isScalarMember);
|
|
56
54
|
};
|
|
57
55
|
/**
|
|
58
56
|
* `schema` with its other keywords and without an `anyOf` that
|
|
@@ -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 {};
|
|
@@ -68,7 +68,8 @@ const capitalize = (text) => text.charAt(0).toUpperCase() + text.slice(1);
|
|
|
68
68
|
*/
|
|
69
69
|
export const toSecurityCheck = ({ parse, declared, parsed, stackTrail, context }) => {
|
|
70
70
|
const declaredSchemes = Object.keys(declared ?? {});
|
|
71
|
-
const
|
|
71
|
+
const unmodeledSchemes = declaredSchemes.filter(name => isUnmodeledScheme(declared?.[name]));
|
|
72
|
+
const failedSchemes = declaredSchemes.filter(name => !Object.hasOwn(parsed ?? {}, name) && !unmodeledSchemes.includes(name));
|
|
72
73
|
const logRootProblem = (problem) => context.logIssueNoKey({
|
|
73
74
|
stackTrail,
|
|
74
75
|
parent: undefined,
|
|
@@ -80,7 +81,7 @@ export const toSecurityCheck = ({ parse, declared, parsed, stackTrail, context }
|
|
|
80
81
|
const rootSecurity = parse();
|
|
81
82
|
const problems = toSchemeProblems(rootSecurity, { declaredSchemes, failedSchemes });
|
|
82
83
|
if (problems.length === 0) {
|
|
83
|
-
return { rootSecurity, rootProblem: undefined, declaredSchemes, failedSchemes, context };
|
|
84
|
+
return { rootSecurity, rootProblem: undefined, declaredSchemes, failedSchemes, unmodeledSchemes, context };
|
|
84
85
|
}
|
|
85
86
|
logRootProblem(`Root security ${problems.join(' and ')}`);
|
|
86
87
|
return {
|
|
@@ -88,6 +89,7 @@ export const toSecurityCheck = ({ parse, declared, parsed, stackTrail, context }
|
|
|
88
89
|
rootProblem: `Inherits root security, which ${problems.join(' and ')}`,
|
|
89
90
|
declaredSchemes,
|
|
90
91
|
failedSchemes,
|
|
92
|
+
unmodeledSchemes,
|
|
91
93
|
context
|
|
92
94
|
};
|
|
93
95
|
}
|
|
@@ -98,6 +100,7 @@ export const toSecurityCheck = ({ parse, declared, parsed, stackTrail, context }
|
|
|
98
100
|
rootProblem: 'Inherits root security, which is not a list of security requirement objects',
|
|
99
101
|
declaredSchemes,
|
|
100
102
|
failedSchemes,
|
|
103
|
+
unmodeledSchemes,
|
|
101
104
|
context
|
|
102
105
|
};
|
|
103
106
|
}
|
|
@@ -113,6 +116,10 @@ export const toSecurityCheck = ({ parse, declared, parsed, stackTrail, context }
|
|
|
113
116
|
* of the scheme. When the parser removes the scheme later (one that is a
|
|
114
117
|
* `$ref` that names nothing), the item goes with it, and so is never kept
|
|
115
118
|
* without its auth.
|
|
119
|
+
*
|
|
120
|
+
* A scheme of a type core does not parse yet (`mutualTLS`) is not a
|
|
121
|
+
* dependency: it is never in the parsed document, and its
|
|
122
|
+
* `INVALID_SECURITY_SCHEME` error would remove every item that names it.
|
|
116
123
|
*/
|
|
117
124
|
export const toOperationsWithValidSecurity = ({ items, check }) => {
|
|
118
125
|
return items.filter(item => {
|
|
@@ -121,7 +128,7 @@ export const toOperationsWithValidSecurity = ({ items, check }) => {
|
|
|
121
128
|
: check.rootProblem;
|
|
122
129
|
if (message === undefined) {
|
|
123
130
|
const names = (item.security ?? check.rootSecurity ?? []).flatMap(({ requirement }) => Object.keys(requirement));
|
|
124
|
-
new Set(names).forEach(name => check.context.registerRef(item.stackTrail.clone(), `#/components/securitySchemes/${name}`));
|
|
131
|
+
new Set(names.filter(name => !check.unmodeledSchemes.includes(name))).forEach(name => check.context.registerRef(item.stackTrail.clone(), `#/components/securitySchemes/${name}`));
|
|
125
132
|
return true;
|
|
126
133
|
}
|
|
127
134
|
check.context.logIssueNoKey({
|
|
@@ -177,7 +177,7 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
177
177
|
const system = toAllOfSystem(context);
|
|
178
178
|
const merged = mergeIntersection({
|
|
179
179
|
schema,
|
|
180
|
-
getRef: toGetRef(context.documentObject,
|
|
180
|
+
getRef: toGetRef(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
181
181
|
system
|
|
182
182
|
});
|
|
183
183
|
logAllOfContradictions({ system, stackTrail, parent: schema, context });
|
|
@@ -193,7 +193,7 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
193
193
|
schema: withoutNullMembers(schema, 'oneOf'),
|
|
194
194
|
// A member's own `allOf`, or a member merged with the keywords beside
|
|
195
195
|
// the `oneOf`, is merged here, so it follows `allOfMember` too.
|
|
196
|
-
getRef: toGetRef(context.documentObject,
|
|
196
|
+
getRef: toGetRef(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
197
197
|
system,
|
|
198
198
|
groupType: 'oneOf'
|
|
199
199
|
});
|
|
@@ -262,7 +262,7 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
262
262
|
const merged = mergeUnion({
|
|
263
263
|
schema: withoutNullMembers(schema, 'anyOf'),
|
|
264
264
|
// As for `oneOf`: what is merged here follows `allOfMember`.
|
|
265
|
-
getRef: toGetRef(context.documentObject,
|
|
265
|
+
getRef: toGetRef(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
266
266
|
system,
|
|
267
267
|
groupType: 'anyOf'
|
|
268
268
|
});
|