@skmtc/core 0.41.0 → 0.43.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 +17 -0
- package/esm/context/ParseContext.js +50 -28
- package/esm/context/generateTypes.d.ts +10 -10
- package/esm/context/tryParseAt.d.ts +3 -3
- package/esm/context/tryParseAt.js +4 -4
- package/esm/helpers/refFns.d.ts +3 -1
- package/esm/helpers/refFns.js +5 -2
- package/esm/oas/operation/Operation.d.ts +19 -7
- package/esm/oas/operation/Operation.js +32 -13
- package/esm/oas/operation/toEffectiveParameters.d.ts +7 -6
- package/esm/oas/operation/toEffectiveParameters.js +21 -23
- package/esm/oas/ref/DanglingRefError.d.ts +3 -3
- package/esm/oas/ref/DanglingRefError.js +3 -3
- package/esm/oas/ref/Ref.d.ts +7 -1
- package/esm/oas/ref/Ref.js +8 -2
- package/esm/oas/union/Union.d.ts +1 -1
- package/esm/oas/union/Union.js +1 -1
- package/esm/oas/webhook/Webhook.d.ts +10 -0
- package/esm/oas/webhook/Webhook.js +16 -2
- package/esm/parse/v3-0/_merge-all-of/merge-union.js +9 -1
- package/esm/parse/v3-0/schema/toSchemasV3.js +6 -3
- package/esm/parse/v3-1/_merge-all-of/merge-union.js +16 -4
- package/esm/parse/v3-1/schema/toSchemasV3.js +6 -3
- package/esm/parse/v3-2/_merge-all-of/merge-union.js +16 -4
- package/esm/parse/v3-2/schema/toSchemasV3.js +6 -3
- package/esm/types/Settings.d.ts +19 -8
- package/esm/types/Settings.js +18 -1
- package/package.json +1 -1
- package/script/context/ParseContext.d.ts +17 -0
- package/script/context/ParseContext.js +50 -28
- package/script/context/generateTypes.d.ts +10 -10
- package/script/context/tryParseAt.d.ts +3 -3
- package/script/context/tryParseAt.js +4 -4
- package/script/helpers/refFns.d.ts +3 -1
- package/script/helpers/refFns.js +5 -2
- package/script/oas/operation/Operation.d.ts +19 -7
- package/script/oas/operation/Operation.js +31 -12
- package/script/oas/operation/toEffectiveParameters.d.ts +7 -6
- package/script/oas/operation/toEffectiveParameters.js +23 -25
- package/script/oas/ref/DanglingRefError.d.ts +3 -3
- package/script/oas/ref/DanglingRefError.js +3 -3
- package/script/oas/ref/Ref.d.ts +7 -1
- package/script/oas/ref/Ref.js +8 -2
- package/script/oas/union/Union.d.ts +1 -1
- package/script/oas/union/Union.js +1 -1
- package/script/oas/webhook/Webhook.d.ts +10 -0
- package/script/oas/webhook/Webhook.js +15 -1
- package/script/parse/v3-0/_merge-all-of/merge-union.js +9 -1
- package/script/parse/v3-0/schema/toSchemasV3.js +6 -3
- package/script/parse/v3-1/_merge-all-of/merge-union.js +16 -4
- package/script/parse/v3-1/schema/toSchemasV3.js +6 -3
- package/script/parse/v3-2/_merge-all-of/merge-union.js +16 -4
- package/script/parse/v3-2/schema/toSchemasV3.js +6 -3
- package/script/types/Settings.d.ts +19 -8
- package/script/types/Settings.js +19 -2
|
@@ -52,6 +52,11 @@ type GqlProtocolState = {
|
|
|
52
52
|
options: GqlParseOptions;
|
|
53
53
|
};
|
|
54
54
|
type ProtocolState = OasProtocolState | GqlProtocolState;
|
|
55
|
+
type ToDanglingAllOfMemberArgs = {
|
|
56
|
+
$ref: string;
|
|
57
|
+
/** The schema that holds the `allOf`. */
|
|
58
|
+
stackTrail: StackTrail;
|
|
59
|
+
};
|
|
55
60
|
type ConstructorArgs = {
|
|
56
61
|
input: SkmtcDocumentInput;
|
|
57
62
|
logger: Logger;
|
|
@@ -166,6 +171,18 @@ export declare class ParseContext {
|
|
|
166
171
|
* resolve it there.
|
|
167
172
|
*/
|
|
168
173
|
registerOasRef<T extends OasRefData['refType']>(consumer: StackTrail, ref: OasRef<T>): void;
|
|
174
|
+
/**
|
|
175
|
+
* What a merge reads in place of a `$ref` that names nothing: an `allOf`
|
|
176
|
+
* member, or in a `oneOf` or `anyOf`, a member's own `allOf` member or a
|
|
177
|
+
* member merged with the keywords beside the union. When
|
|
178
|
+
* `system.danglingRefs` lists `allOfMember`, it is `{}`, which
|
|
179
|
+
* adds nothing to the merge (`A & unknown` is `A`), and a `DANGLING_REF`
|
|
180
|
+
* warning at `stackTrail`: the model has no properties from that member.
|
|
181
|
+
* Otherwise it throws `DanglingRefError`, and what holds the `allOf` is
|
|
182
|
+
* removed. It is separate from `schema`: here core decides, at parse, and
|
|
183
|
+
* the generator never sees the member.
|
|
184
|
+
*/
|
|
185
|
+
toDanglingAllOfMember({ $ref, stackTrail }: ToDanglingAllOfMemberArgs): OpenAPIV3.SchemaObject;
|
|
169
186
|
/**
|
|
170
187
|
* Register an error against a ref key — typically called when the
|
|
171
188
|
* 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,
|
|
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;
|
|
13
13
|
/**
|
|
14
14
|
* Unified parse context for both OAS and GraphQL inputs.
|
|
15
15
|
*
|
|
@@ -390,6 +390,31 @@ export class ParseContext {
|
|
|
390
390
|
this.registerRef(consumer, toRefKey(ref.$ref));
|
|
391
391
|
__classPrivateFieldGet(this, _ParseContext_oasRefs, "f").push({ consumer, ref });
|
|
392
392
|
}
|
|
393
|
+
/**
|
|
394
|
+
* What a merge reads in place of a `$ref` that names nothing: an `allOf`
|
|
395
|
+
* member, or in a `oneOf` or `anyOf`, a member's own `allOf` member or a
|
|
396
|
+
* member merged with the keywords beside the union. When
|
|
397
|
+
* `system.danglingRefs` lists `allOfMember`, it is `{}`, which
|
|
398
|
+
* adds nothing to the merge (`A & unknown` is `A`), and a `DANGLING_REF`
|
|
399
|
+
* warning at `stackTrail`: the model has no properties from that member.
|
|
400
|
+
* Otherwise it throws `DanglingRefError`, and what holds the `allOf` is
|
|
401
|
+
* removed. It is separate from `schema`: here core decides, at parse, and
|
|
402
|
+
* the generator never sees the member.
|
|
403
|
+
*/
|
|
404
|
+
toDanglingAllOfMember({ $ref, stackTrail }) {
|
|
405
|
+
const error = new DanglingRefError($ref);
|
|
406
|
+
if (!this.system.danglingRefs?.includes('allOfMember')) {
|
|
407
|
+
throw error;
|
|
408
|
+
}
|
|
409
|
+
this.logIssueNoKey({
|
|
410
|
+
level: 'warning',
|
|
411
|
+
message: `${error.message}. It is left out of the allOf merge (system.danglingRefs lists 'allOfMember').`,
|
|
412
|
+
parent: { $ref },
|
|
413
|
+
stackTrail,
|
|
414
|
+
type: 'DANGLING_REF'
|
|
415
|
+
});
|
|
416
|
+
return {};
|
|
417
|
+
}
|
|
393
418
|
/**
|
|
394
419
|
* Register an error against a ref key — typically called when the
|
|
395
420
|
* target of a `$ref` (or type reference) fails to parse. `undefined`
|
|
@@ -663,48 +688,45 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
663
688
|
ref.resolveOnce();
|
|
664
689
|
}
|
|
665
690
|
catch (error) {
|
|
666
|
-
if (DanglingRefError.is(error)) {
|
|
667
|
-
|
|
691
|
+
if (!DanglingRefError.is(error)) {
|
|
692
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
693
|
+
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_removeHolder).call(this, {
|
|
694
|
+
consumer,
|
|
695
|
+
ref,
|
|
696
|
+
error,
|
|
697
|
+
type: 'REF_TYPE_MISMATCH',
|
|
698
|
+
message: `${message}, so what holds it is removed.`
|
|
699
|
+
});
|
|
668
700
|
}
|
|
669
|
-
else {
|
|
701
|
+
else if (this.system.danglingRefs?.includes(ref.refType)) {
|
|
670
702
|
this.logIssueNoKey({
|
|
671
703
|
level: 'warning',
|
|
672
|
-
message: `${error
|
|
704
|
+
message: `${error.message}. It is kept (system.danglingRefs lists '${ref.refType}'), and resolving it throws DanglingRefError.`,
|
|
673
705
|
parent: { $ref: ref.$ref },
|
|
674
706
|
stackTrail: consumer,
|
|
675
|
-
type: '
|
|
707
|
+
type: 'DANGLING_REF'
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
else {
|
|
711
|
+
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_removeHolder).call(this, {
|
|
712
|
+
consumer,
|
|
713
|
+
ref,
|
|
714
|
+
error,
|
|
715
|
+
type: 'DANGLING_REF',
|
|
716
|
+
message: `${error.message}, so what holds it is removed. To keep it, list '${ref.refType}' in system.danglingRefs.`
|
|
676
717
|
});
|
|
677
718
|
}
|
|
678
719
|
}
|
|
679
720
|
});
|
|
680
|
-
},
|
|
681
|
-
const exampleOrLink = ref.refType === 'example' || ref.refType === 'link';
|
|
682
|
-
if (exampleOrLink || this.system.danglingRefs === 'keep') {
|
|
683
|
-
this.logIssueNoKey({
|
|
684
|
-
level: 'warning',
|
|
685
|
-
message: exampleOrLink
|
|
686
|
-
? `${error.message}. It is kept, as a ref to an example or a link is in both system.danglingRefs modes, and resolving it throws DanglingRefError.`
|
|
687
|
-
: `${error.message}. It is kept (system.danglingRefs is keep), and resolving it throws DanglingRefError.`,
|
|
688
|
-
parent: { $ref: ref.$ref },
|
|
689
|
-
stackTrail: consumer,
|
|
690
|
-
type: 'DANGLING_REF'
|
|
691
|
-
});
|
|
692
|
-
return;
|
|
693
|
-
}
|
|
694
|
-
// An error inside a component removes that component, and what uses it
|
|
695
|
-
// (`removeErroredItems`).
|
|
721
|
+
}, _ParseContext_removeHolder = function _ParseContext_removeHolder({ consumer, ref, error, type, message }) {
|
|
696
722
|
this.logIssueNoKey({
|
|
697
723
|
level: 'error',
|
|
698
|
-
message
|
|
724
|
+
message,
|
|
699
725
|
cause: error,
|
|
700
726
|
parent: { $ref: ref.$ref },
|
|
701
727
|
stackTrail: consumer,
|
|
702
|
-
type
|
|
728
|
+
type
|
|
703
729
|
});
|
|
704
|
-
// What holds the ref outside the components (an operation, a webhook, a
|
|
705
|
-
// path-level parameter) is removed here. Its own location has the
|
|
706
|
-
// DANGLING_REF already; an operation that a path-level parameter applies
|
|
707
|
-
// to gets an INVALID_DEPENDENCY_REF.
|
|
708
730
|
const documentTrail = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toDocumentTrail).call(this, consumer);
|
|
709
731
|
if (documentTrail.toStackRef() !== undefined) {
|
|
710
732
|
return;
|
|
@@ -186,18 +186,18 @@ export type AnyOasDocument = OpenAPIV2.Document | OpenAPIV3.Document | OpenAPIV3
|
|
|
186
186
|
* One for each schema.
|
|
187
187
|
*
|
|
188
188
|
* `DANGLING_REF` — a `$ref` names nothing in the document. One for each
|
|
189
|
-
* place the `$ref` is written.
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
189
|
+
* place the `$ref` is written. A `warning` when `system.danglingRefs` lists
|
|
190
|
+
* the `$ref`'s kind: the ref stays, and resolving it throws
|
|
191
|
+
* `DanglingRefError`; with `allOfMember` listed, a `$ref` that core merges
|
|
192
|
+
* (in an `allOf`, or in a `oneOf` or `anyOf` member) is left out of the
|
|
193
|
+
* merge. Otherwise (the default lists none)
|
|
194
|
+
* an `error`: what holds the ref is removed, and each item that uses it gets
|
|
195
|
+
* an `INVALID_DEPENDENCY_REF`.
|
|
196
196
|
*
|
|
197
|
-
* `REF_TYPE_MISMATCH` (`
|
|
197
|
+
* `REF_TYPE_MISMATCH` (`error`) — a `$ref` names a component of the wrong
|
|
198
198
|
* kind, such as a request body that is a `$ref` to
|
|
199
|
-
* `#/components/schemas/Pet`. One for each place the `$ref` is written.
|
|
200
|
-
* ref
|
|
199
|
+
* `#/components/schemas/Pet`. One for each place the `$ref` is written. What
|
|
200
|
+
* holds the ref is removed; `system.danglingRefs` does not apply.
|
|
201
201
|
*
|
|
202
202
|
* `RUN_FAILED` (`error`) — the run itself failed outside the per-item
|
|
203
203
|
* catches. Its `location` names the entry and phase, for example
|
|
@@ -61,9 +61,9 @@ export type TryParseAtArgs<T> = {
|
|
|
61
61
|
*
|
|
62
62
|
* - logs a `level: 'error'` issue at the child location with the
|
|
63
63
|
* given `type` and the thrown value as `cause`. A `DanglingRefError`
|
|
64
|
-
* is logged as `DANGLING_REF`: core resolved a ref while it parsed (
|
|
65
|
-
*
|
|
66
|
-
* `system.danglingRefs`
|
|
64
|
+
* is logged as `DANGLING_REF`: core resolved a ref while it parsed (one
|
|
65
|
+
* it merges, in an `allOf` or a `oneOf` or `anyOf` member, when
|
|
66
|
+
* `system.danglingRefs` does not list `allOfMember`)
|
|
67
67
|
* - registers a ref error if `refKey` is provided
|
|
68
68
|
* - returns `undefined`
|
|
69
69
|
*
|
|
@@ -25,9 +25,9 @@ import { DanglingRefError } from '../oas/ref/DanglingRefError.js';
|
|
|
25
25
|
*
|
|
26
26
|
* - logs a `level: 'error'` issue at the child location with the
|
|
27
27
|
* given `type` and the thrown value as `cause`. A `DanglingRefError`
|
|
28
|
-
* is logged as `DANGLING_REF`: core resolved a ref while it parsed (
|
|
29
|
-
*
|
|
30
|
-
* `system.danglingRefs`
|
|
28
|
+
* is logged as `DANGLING_REF`: core resolved a ref while it parsed (one
|
|
29
|
+
* it merges, in an `allOf` or a `oneOf` or `anyOf` member, when
|
|
30
|
+
* `system.danglingRefs` does not list `allOfMember`)
|
|
31
31
|
* - registers a ref error if `refKey` is provided
|
|
32
32
|
* - returns `undefined`
|
|
33
33
|
*
|
|
@@ -49,7 +49,7 @@ export const tryParseAt = ({ stackTrail, key, context, type, parent, refKey, fn
|
|
|
49
49
|
stackTrail: childStack,
|
|
50
50
|
parent,
|
|
51
51
|
message: dangling
|
|
52
|
-
? `${normalized.message}. Core resolves it while it parses, so what holds it is removed
|
|
52
|
+
? `${normalized.message}. Core resolves it while it parses, so what holds it is removed.`
|
|
53
53
|
: normalized.message,
|
|
54
54
|
cause: normalized,
|
|
55
55
|
type: dangling ? 'DANGLING_REF' : type
|
package/esm/helpers/refFns.d.ts
CHANGED
|
@@ -171,5 +171,7 @@ export declare const isRef: (value: unknown) => value is Ref;
|
|
|
171
171
|
* }
|
|
172
172
|
* ```
|
|
173
173
|
*/
|
|
174
|
-
export declare const toGetRef: (oasDocument: OpenAPIV3.Document) => ({ $ref }: ReferenceObject) => OpenAPIV3.SchemaObject;
|
|
174
|
+
export declare const toGetRef: (oasDocument: OpenAPIV3.Document, onDangling?: OnDangling) => ({ $ref }: ReferenceObject) => OpenAPIV3.SchemaObject;
|
|
175
|
+
/** What a resolver reads in place of a `$ref` that names nothing; it may throw. */
|
|
176
|
+
type OnDangling = ($ref: string) => OpenAPIV3.SchemaObject;
|
|
175
177
|
export {};
|
package/esm/helpers/refFns.js
CHANGED
|
@@ -188,14 +188,17 @@ export const isRef = (value) => {
|
|
|
188
188
|
* }
|
|
189
189
|
* ```
|
|
190
190
|
*/
|
|
191
|
-
export const toGetRef = (oasDocument) => ({ $ref }) => {
|
|
191
|
+
export const toGetRef = (oasDocument, onDangling) => ({ $ref }) => {
|
|
192
192
|
const refName = toRefName($ref);
|
|
193
193
|
const item = oasDocument.components?.schemas?.[refName];
|
|
194
194
|
if (isRef(item)) {
|
|
195
|
-
return toGetRef(oasDocument)(item);
|
|
195
|
+
return toGetRef(oasDocument, onDangling)(item);
|
|
196
196
|
}
|
|
197
197
|
if (item) {
|
|
198
198
|
return item;
|
|
199
199
|
}
|
|
200
|
+
if (onDangling) {
|
|
201
|
+
return onDangling($ref);
|
|
202
|
+
}
|
|
200
203
|
throw new DanglingRefError($ref);
|
|
201
204
|
};
|
|
@@ -147,17 +147,26 @@ export declare class OasOperation extends OasBase {
|
|
|
147
147
|
*/
|
|
148
148
|
traverse(path: SchemaPath, mediaType?: string): OasSchema | OasRef<'schema'>;
|
|
149
149
|
/**
|
|
150
|
-
*
|
|
150
|
+
* The parameters that apply to this operation, as OpenAPI defines them: the
|
|
151
|
+
* path item's parameters apply to each of its operations, and an operation's
|
|
152
|
+
* own parameter with the same name and location replaces the path item's.
|
|
153
|
+
* The path item's come first.
|
|
151
154
|
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
155
|
+
* References stay references, so a caller can resolve each one on its own.
|
|
156
|
+
* A reference that names nothing (kept when `system.danglingRefs` lists
|
|
157
|
+
* `parameter`) keeps its place, and resolving it throws `DanglingRefError`.
|
|
158
|
+
* {@link OasOperation.toParams} resolves them all.
|
|
159
|
+
*
|
|
160
|
+
* @returns the parameters, path item's first
|
|
161
|
+
*/
|
|
162
|
+
toEffectiveParameters(): (OasParameter | OasRef<'parameter'>)[];
|
|
163
|
+
/**
|
|
164
|
+
* Resolve all parameters and optionally filter by location: the resolved
|
|
165
|
+
* {@link OasOperation.toEffectiveParameters}.
|
|
158
166
|
*
|
|
159
167
|
* @param filter - only include parameters from specified locations
|
|
160
168
|
* @returns
|
|
169
|
+
* @throws {DanglingRefError} when a parameter is a reference that names nothing
|
|
161
170
|
*/
|
|
162
171
|
toParams(filter?: OasParameterLocation[]): OasParameter[];
|
|
163
172
|
/**
|
|
@@ -172,6 +181,9 @@ export declare class OasOperation extends OasBase {
|
|
|
172
181
|
*
|
|
173
182
|
* @param options - Conversion options for nested components
|
|
174
183
|
* @returns OpenAPI v3 operation object
|
|
184
|
+
* @throws {DanglingRefError} when a parameter is a reference that names
|
|
185
|
+
* nothing, as {@link OasOperation.toParams} does: there is no parameter to
|
|
186
|
+
* write, and the caller decides what to do
|
|
175
187
|
*/
|
|
176
188
|
toJsonSchema(options: ToJsonSchemaOptions): OpenAPIV3.OperationObject;
|
|
177
189
|
/**
|
|
@@ -3,7 +3,8 @@ import { traverseSchema } from '../schemaPath/traverseSchema.js';
|
|
|
3
3
|
import { OasObject } from '../object/Object.js';
|
|
4
4
|
import { toPrimaryResponseCode } from '../response/toPrimaryResponseCode.js';
|
|
5
5
|
import { OasBase } from '../../types/OasBase.js';
|
|
6
|
-
import {
|
|
6
|
+
import { namesNothing, toEffectiveParameters } from './toEffectiveParameters.js';
|
|
7
|
+
import { DanglingRefError } from '../ref/DanglingRefError.js';
|
|
7
8
|
export class OasOperation extends OasBase {
|
|
8
9
|
/**
|
|
9
10
|
* Creates a new OasOperation instance from operation field data.
|
|
@@ -219,20 +220,33 @@ export class OasOperation extends OasBase {
|
|
|
219
220
|
return traverseSchema(rootSchema, rest);
|
|
220
221
|
}
|
|
221
222
|
/**
|
|
222
|
-
*
|
|
223
|
+
* The parameters that apply to this operation, as OpenAPI defines them: the
|
|
224
|
+
* path item's parameters apply to each of its operations, and an operation's
|
|
225
|
+
* own parameter with the same name and location replaces the path item's.
|
|
226
|
+
* The path item's come first.
|
|
223
227
|
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
228
|
+
* References stay references, so a caller can resolve each one on its own.
|
|
229
|
+
* A reference that names nothing (kept when `system.danglingRefs` lists
|
|
230
|
+
* `parameter`) keeps its place, and resolving it throws `DanglingRefError`.
|
|
231
|
+
* {@link OasOperation.toParams} resolves them all.
|
|
232
|
+
*
|
|
233
|
+
* @returns the parameters, path item's first
|
|
234
|
+
*/
|
|
235
|
+
toEffectiveParameters() {
|
|
236
|
+
return toEffectiveParameters({ own: this.parameters, shared: this.pathItem?.parameters });
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Resolve all parameters and optionally filter by location: the resolved
|
|
240
|
+
* {@link OasOperation.toEffectiveParameters}.
|
|
230
241
|
*
|
|
231
242
|
* @param filter - only include parameters from specified locations
|
|
232
243
|
* @returns
|
|
244
|
+
* @throws {DanglingRefError} when a parameter is a reference that names nothing
|
|
233
245
|
*/
|
|
234
246
|
toParams(filter) {
|
|
235
|
-
return
|
|
247
|
+
return this.toEffectiveParameters()
|
|
248
|
+
.map(param => param.resolve())
|
|
249
|
+
.filter(param => (filter?.length ? filter.includes(param.location) : true));
|
|
236
250
|
}
|
|
237
251
|
/**
|
|
238
252
|
* Creates an OAS object representation of operation parameters.
|
|
@@ -255,12 +269,17 @@ export class OasOperation extends OasBase {
|
|
|
255
269
|
*
|
|
256
270
|
* @param options - Conversion options for nested components
|
|
257
271
|
* @returns OpenAPI v3 operation object
|
|
272
|
+
* @throws {DanglingRefError} when a parameter is a reference that names
|
|
273
|
+
* nothing, as {@link OasOperation.toParams} does: there is no parameter to
|
|
274
|
+
* write, and the caller decides what to do
|
|
258
275
|
*/
|
|
259
276
|
toJsonSchema(options) {
|
|
260
|
-
const parameters = toEffectiveParameters(
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
277
|
+
const parameters = this.toEffectiveParameters();
|
|
278
|
+
for (const parameter of parameters) {
|
|
279
|
+
if (parameter.isRef() && namesNothing(parameter)) {
|
|
280
|
+
throw new DanglingRefError(parameter.$ref);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
264
283
|
return {
|
|
265
284
|
tags: this.tags,
|
|
266
285
|
summary: this.summary,
|
|
@@ -11,14 +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
|
-
*
|
|
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.
|
|
16
18
|
*/
|
|
17
19
|
export declare const toEffectiveParameters: ({ own, shared }: ToEffectiveParametersArgs) => Parameter[];
|
|
18
20
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* warning for it.
|
|
21
|
+
* True for a parameter `$ref` that names nothing in the document, which the
|
|
22
|
+
* parser keeps when `system.danglingRefs` lists `parameter`.
|
|
22
23
|
*/
|
|
23
|
-
export declare const
|
|
24
|
+
export declare const namesNothing: (parameter: Parameter) => boolean;
|
|
24
25
|
export {};
|
|
@@ -3,40 +3,38 @@ import { DanglingRefError } from '../ref/DanglingRefError.js';
|
|
|
3
3
|
* The parameters that apply to an operation or webhook, as OpenAPI defines
|
|
4
4
|
* them: the path item's first, then its own. An own parameter with the same
|
|
5
5
|
* name and location replaces the path item's. References stay references.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
*
|
|
7
|
+
* A reference that names nothing (kept when `system.danglingRefs` lists
|
|
8
|
+
* `parameter`) has no name or location. It keeps its place, and only the
|
|
9
|
+
* same `$ref` replaces it.
|
|
8
10
|
*/
|
|
9
11
|
export const toEffectiveParameters = ({ own = [], shared = [] }) => {
|
|
10
12
|
const ownKeys = new Set(own.map(toParameterKey));
|
|
11
|
-
return [
|
|
12
|
-
...shared.filter(parameter => {
|
|
13
|
-
const key = toParameterKey(parameter);
|
|
14
|
-
return key === undefined || !ownKeys.has(key);
|
|
15
|
-
}),
|
|
16
|
-
...own
|
|
17
|
-
];
|
|
13
|
+
return [...shared.filter(parameter => !ownKeys.has(toParameterKey(parameter))), ...own];
|
|
18
14
|
};
|
|
19
15
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* warning for it.
|
|
16
|
+
* True for a parameter `$ref` that names nothing in the document, which the
|
|
17
|
+
* parser keeps when `system.danglingRefs` lists `parameter`.
|
|
23
18
|
*/
|
|
24
|
-
export const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
const toParameterKey = (parameter) => {
|
|
29
|
-
const resolved = toResolvedParameter(parameter);
|
|
30
|
-
return resolved === undefined ? undefined : `${resolved.location}:${resolved.name}`;
|
|
31
|
-
};
|
|
32
|
-
const toResolvedParameter = (parameter) => {
|
|
19
|
+
export const namesNothing = (parameter) => {
|
|
20
|
+
if (!parameter.isRef()) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
33
23
|
try {
|
|
34
|
-
|
|
24
|
+
parameter.resolve();
|
|
25
|
+
return false;
|
|
35
26
|
}
|
|
36
27
|
catch (error) {
|
|
37
28
|
if (DanglingRefError.is(error)) {
|
|
38
|
-
return
|
|
29
|
+
return true;
|
|
39
30
|
}
|
|
40
31
|
throw error;
|
|
41
32
|
}
|
|
42
33
|
};
|
|
34
|
+
const toParameterKey = (parameter) => {
|
|
35
|
+
if (parameter.isRef() && namesNothing(parameter)) {
|
|
36
|
+
return `$ref:${parameter.$ref}`;
|
|
37
|
+
}
|
|
38
|
+
const { name, location } = parameter.resolve();
|
|
39
|
+
return `${location}:${name}`;
|
|
40
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Thrown when a reference that names nothing in the document is resolved.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* By default the parser removes what holds such a reference, so a generator
|
|
5
|
+
* never meets one. When `client.json` `system.danglingRefs` lists the
|
|
6
|
+
* reference's kind, it stays, and a generator that resolves it can catch
|
|
7
7
|
* this error and render something else in its place. Test for it with
|
|
8
8
|
* {@link DanglingRefError.is}, not `instanceof`.
|
|
9
9
|
*/
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Thrown when a reference that names nothing in the document is resolved.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* By default the parser removes what holds such a reference, so a generator
|
|
5
|
+
* never meets one. When `client.json` `system.danglingRefs` lists the
|
|
6
|
+
* reference's kind, it stays, and a generator that resolves it can catch
|
|
7
7
|
* this error and render something else in its place. Test for it with
|
|
8
8
|
* {@link DanglingRefError.is}, not `instanceof`.
|
|
9
9
|
*/
|
package/esm/oas/ref/Ref.d.ts
CHANGED
|
@@ -233,12 +233,18 @@ export declare class OasRef<T extends OasRefData['refType']> extends OasBase {
|
|
|
233
233
|
*
|
|
234
234
|
* @returns Either the resolved component or another reference in the chain
|
|
235
235
|
* @throws {DanglingRefError} when the reference names nothing in the
|
|
236
|
-
* document (kept
|
|
236
|
+
* document (kept when `client.json` `system.danglingRefs` lists its kind),
|
|
237
237
|
* including a `$ref` with no name, such as `#/components/schemas/`
|
|
238
238
|
* @throws Error when it names a component of another kind, such as a
|
|
239
239
|
* `requestBody` ref to `#/components/schemas/…`
|
|
240
240
|
*/
|
|
241
241
|
resolveOnce(): OasRef<T> | ResolvedRef<T>;
|
|
242
|
+
/**
|
|
243
|
+
* The component name the reference looks up.
|
|
244
|
+
*
|
|
245
|
+
* @throws {DanglingRefError} when the `$ref` has no name, such as
|
|
246
|
+
* `#/components/schemas/`: it names nothing
|
|
247
|
+
*/
|
|
242
248
|
toRefName(): RefName;
|
|
243
249
|
/**
|
|
244
250
|
* Narrows this reference to a schema reference.
|
package/esm/oas/ref/Ref.js
CHANGED
|
@@ -459,7 +459,7 @@ export class OasRef extends OasBase {
|
|
|
459
459
|
*
|
|
460
460
|
* @returns Either the resolved component or another reference in the chain
|
|
461
461
|
* @throws {DanglingRefError} when the reference names nothing in the
|
|
462
|
-
* document (kept
|
|
462
|
+
* document (kept when `client.json` `system.danglingRefs` lists its kind),
|
|
463
463
|
* including a `$ref` with no name, such as `#/components/schemas/`
|
|
464
464
|
* @throws Error when it names a component of another kind, such as a
|
|
465
465
|
* `requestBody` ref to `#/components/schemas/…`
|
|
@@ -484,8 +484,14 @@ export class OasRef extends OasBase {
|
|
|
484
484
|
}
|
|
485
485
|
return resolved;
|
|
486
486
|
}
|
|
487
|
+
/**
|
|
488
|
+
* The component name the reference looks up.
|
|
489
|
+
*
|
|
490
|
+
* @throws {DanglingRefError} when the `$ref` has no name, such as
|
|
491
|
+
* `#/components/schemas/`: it names nothing
|
|
492
|
+
*/
|
|
487
493
|
toRefName() {
|
|
488
|
-
return
|
|
494
|
+
return toLookupName(this.$ref);
|
|
489
495
|
}
|
|
490
496
|
/**
|
|
491
497
|
* Narrows this reference to a schema reference.
|
package/esm/oas/union/Union.d.ts
CHANGED
|
@@ -217,7 +217,7 @@ export declare class OasUnion extends OasBase {
|
|
|
217
217
|
* property, and that allows only string literals for it. No value may
|
|
218
218
|
* belong to two members. A member that is a union, or anything other than
|
|
219
219
|
* an object, makes it `false`, as does a reference on the way that names
|
|
220
|
-
* nothing in the document (kept
|
|
220
|
+
* nothing in the document (kept when `system.danglingRefs` lists `schema`).
|
|
221
221
|
*
|
|
222
222
|
* It reads the schemas only. A generator may refuse more: one that leaves
|
|
223
223
|
* out `readOnly` properties cannot discriminate on one.
|
package/esm/oas/union/Union.js
CHANGED
|
@@ -285,7 +285,7 @@ export class OasUnion extends OasBase {
|
|
|
285
285
|
* property, and that allows only string literals for it. No value may
|
|
286
286
|
* belong to two members. A member that is a union, or anything other than
|
|
287
287
|
* an object, makes it `false`, as does a reference on the way that names
|
|
288
|
-
* nothing in the document (kept
|
|
288
|
+
* nothing in the document (kept when `system.danglingRefs` lists `schema`).
|
|
289
289
|
*
|
|
290
290
|
* It reads the schemas only. A generator may refuse more: one that leaves
|
|
291
291
|
* out `readOnly` properties cannot discriminate on one.
|
|
@@ -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
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "../../_dnt.polyfills.js";
|
|
2
2
|
import { toPrimaryResponseCode } from '../response/toPrimaryResponseCode.js';
|
|
3
3
|
import { OasBase } from '../../types/OasBase.js';
|
|
4
|
-
import { toEffectiveParameters
|
|
4
|
+
import { toEffectiveParameters } from '../operation/toEffectiveParameters.js';
|
|
5
5
|
/**
|
|
6
6
|
* Represents an OpenAPI 3.1 webhook — a third OAS subject, peer to
|
|
7
7
|
* {@link OasOperation} and the schema/model subjects.
|
|
@@ -166,14 +166,28 @@ export class OasWebhook extends OasBase {
|
|
|
166
166
|
toPayloadSchema(mediaType) {
|
|
167
167
|
return this.toPayload()?.toSchema(mediaType);
|
|
168
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* The inbound parameters that apply to this webhook, path item parameters
|
|
171
|
+
* included, with references unresolved. Mirrors
|
|
172
|
+
* {@link OasOperation.toEffectiveParameters}.
|
|
173
|
+
*
|
|
174
|
+
* @returns the parameters, path item's first
|
|
175
|
+
*/
|
|
176
|
+
toEffectiveParameters() {
|
|
177
|
+
return toEffectiveParameters({ own: this.parameters, shared: this.pathItem?.parameters });
|
|
178
|
+
}
|
|
169
179
|
/**
|
|
170
180
|
* Resolve the inbound parameters (e.g. the signature/headers a handler
|
|
171
181
|
* receives), optionally filtered by location. Mirrors
|
|
172
182
|
* {@link OasOperation.toParams}, path item parameters included; the
|
|
173
183
|
* parameters carry the same shape, only their direction is inbound.
|
|
184
|
+
*
|
|
185
|
+
* @throws {DanglingRefError} when a parameter is a reference that names nothing
|
|
174
186
|
*/
|
|
175
187
|
toParams(filter) {
|
|
176
|
-
return
|
|
188
|
+
return this.toEffectiveParameters()
|
|
189
|
+
.map(param => param.resolve())
|
|
190
|
+
.filter(param => (filter?.length ? filter.includes(param.location) : true));
|
|
177
191
|
}
|
|
178
192
|
/**
|
|
179
193
|
* The status code of the primary acknowledgement response — the lowest 2xx
|