@skmtc/core 0.42.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/oas/operation/Operation.d.ts +19 -4
- package/esm/oas/operation/Operation.js +30 -10
- package/esm/oas/operation/toEffectiveParameters.d.ts +9 -0
- package/esm/oas/operation/toEffectiveParameters.js +27 -0
- package/esm/oas/ref/Ref.d.ts +6 -0
- package/esm/oas/ref/Ref.js +7 -1
- package/esm/oas/webhook/Webhook.d.ts +10 -0
- package/esm/oas/webhook/Webhook.js +13 -1
- package/package.json +1 -1
- package/script/oas/operation/Operation.d.ts +19 -4
- package/script/oas/operation/Operation.js +29 -9
- package/script/oas/operation/toEffectiveParameters.d.ts +9 -0
- package/script/oas/operation/toEffectiveParameters.js +29 -1
- package/script/oas/ref/Ref.d.ts +6 -0
- package/script/oas/ref/Ref.js +7 -1
- package/script/oas/webhook/Webhook.d.ts +10 -0
- package/script/oas/webhook/Webhook.js +13 -1
|
@@ -147,14 +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
|
+
* 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}.
|
|
155
166
|
*
|
|
156
167
|
* @param filter - only include parameters from specified locations
|
|
157
168
|
* @returns
|
|
169
|
+
* @throws {DanglingRefError} when a parameter is a reference that names nothing
|
|
158
170
|
*/
|
|
159
171
|
toParams(filter?: OasParameterLocation[]): OasParameter[];
|
|
160
172
|
/**
|
|
@@ -169,6 +181,9 @@ export declare class OasOperation extends OasBase {
|
|
|
169
181
|
*
|
|
170
182
|
* @param options - Conversion options for nested components
|
|
171
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
|
|
172
187
|
*/
|
|
173
188
|
toJsonSchema(options: ToJsonSchemaOptions): OpenAPIV3.OperationObject;
|
|
174
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 { toEffectiveParameters } from './toEffectiveParameters.js';
|
|
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,17 +220,31 @@ 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
|
-
*
|
|
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}.
|
|
227
241
|
*
|
|
228
242
|
* @param filter - only include parameters from specified locations
|
|
229
243
|
* @returns
|
|
244
|
+
* @throws {DanglingRefError} when a parameter is a reference that names nothing
|
|
230
245
|
*/
|
|
231
246
|
toParams(filter) {
|
|
232
|
-
return toEffectiveParameters(
|
|
247
|
+
return this.toEffectiveParameters()
|
|
233
248
|
.map(param => param.resolve())
|
|
234
249
|
.filter(param => (filter?.length ? filter.includes(param.location) : true));
|
|
235
250
|
}
|
|
@@ -254,12 +269,17 @@ export class OasOperation extends OasBase {
|
|
|
254
269
|
*
|
|
255
270
|
* @param options - Conversion options for nested components
|
|
256
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
|
|
257
275
|
*/
|
|
258
276
|
toJsonSchema(options) {
|
|
259
|
-
const parameters = toEffectiveParameters(
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
+
}
|
|
263
283
|
return {
|
|
264
284
|
tags: this.tags,
|
|
265
285
|
summary: this.summary,
|
|
@@ -11,6 +11,15 @@ type ToEffectiveParametersArgs = {
|
|
|
11
11
|
* The parameters that apply to an operation or webhook, as OpenAPI defines
|
|
12
12
|
* them: the path item's first, then its own. An own parameter with the same
|
|
13
13
|
* name and location replaces the path item's. References stay references.
|
|
14
|
+
*
|
|
15
|
+
* A reference that names nothing (kept when `system.danglingRefs` lists
|
|
16
|
+
* `parameter`) has no name or location. It keeps its place, and only the
|
|
17
|
+
* same `$ref` replaces it.
|
|
14
18
|
*/
|
|
15
19
|
export declare const toEffectiveParameters: ({ own, shared }: ToEffectiveParametersArgs) => Parameter[];
|
|
20
|
+
/**
|
|
21
|
+
* True for a parameter `$ref` that names nothing in the document, which the
|
|
22
|
+
* parser keeps when `system.danglingRefs` lists `parameter`.
|
|
23
|
+
*/
|
|
24
|
+
export declare const namesNothing: (parameter: Parameter) => boolean;
|
|
16
25
|
export {};
|
|
@@ -1,13 +1,40 @@
|
|
|
1
|
+
import { DanglingRefError } from '../ref/DanglingRefError.js';
|
|
1
2
|
/**
|
|
2
3
|
* The parameters that apply to an operation or webhook, as OpenAPI defines
|
|
3
4
|
* them: the path item's first, then its own. An own parameter with the same
|
|
4
5
|
* name and location replaces the path item's. References stay references.
|
|
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.
|
|
5
10
|
*/
|
|
6
11
|
export const toEffectiveParameters = ({ own = [], shared = [] }) => {
|
|
7
12
|
const ownKeys = new Set(own.map(toParameterKey));
|
|
8
13
|
return [...shared.filter(parameter => !ownKeys.has(toParameterKey(parameter))), ...own];
|
|
9
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* True for a parameter `$ref` that names nothing in the document, which the
|
|
17
|
+
* parser keeps when `system.danglingRefs` lists `parameter`.
|
|
18
|
+
*/
|
|
19
|
+
export const namesNothing = (parameter) => {
|
|
20
|
+
if (!parameter.isRef()) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
parameter.resolve();
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (DanglingRefError.is(error)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
10
34
|
const toParameterKey = (parameter) => {
|
|
35
|
+
if (parameter.isRef() && namesNothing(parameter)) {
|
|
36
|
+
return `$ref:${parameter.$ref}`;
|
|
37
|
+
}
|
|
11
38
|
const { name, location } = parameter.resolve();
|
|
12
39
|
return `${location}:${name}`;
|
|
13
40
|
};
|
package/esm/oas/ref/Ref.d.ts
CHANGED
|
@@ -239,6 +239,12 @@ export declare class OasRef<T extends OasRefData['refType']> extends OasBase {
|
|
|
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
|
@@ -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.
|
|
@@ -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
|
/**
|
|
@@ -166,14 +166,26 @@ 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 toEffectiveParameters(
|
|
188
|
+
return this.toEffectiveParameters()
|
|
177
189
|
.map(param => param.resolve())
|
|
178
190
|
.filter(param => (filter?.length ? filter.includes(param.location) : true));
|
|
179
191
|
}
|
package/package.json
CHANGED
|
@@ -147,14 +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
|
+
* 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}.
|
|
155
166
|
*
|
|
156
167
|
* @param filter - only include parameters from specified locations
|
|
157
168
|
* @returns
|
|
169
|
+
* @throws {DanglingRefError} when a parameter is a reference that names nothing
|
|
158
170
|
*/
|
|
159
171
|
toParams(filter?: OasParameterLocation[]): OasParameter[];
|
|
160
172
|
/**
|
|
@@ -169,6 +181,9 @@ export declare class OasOperation extends OasBase {
|
|
|
169
181
|
*
|
|
170
182
|
* @param options - Conversion options for nested components
|
|
171
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
|
|
172
187
|
*/
|
|
173
188
|
toJsonSchema(options: ToJsonSchemaOptions): OpenAPIV3.OperationObject;
|
|
174
189
|
/**
|
|
@@ -7,6 +7,7 @@ const Object_js_1 = require("../object/Object.js");
|
|
|
7
7
|
const toPrimaryResponseCode_js_1 = require("../response/toPrimaryResponseCode.js");
|
|
8
8
|
const OasBase_js_1 = require("../../types/OasBase.js");
|
|
9
9
|
const toEffectiveParameters_js_1 = require("./toEffectiveParameters.js");
|
|
10
|
+
const DanglingRefError_js_1 = require("../ref/DanglingRefError.js");
|
|
10
11
|
class OasOperation extends OasBase_js_1.OasBase {
|
|
11
12
|
/**
|
|
12
13
|
* Creates a new OasOperation instance from operation field data.
|
|
@@ -222,17 +223,31 @@ class OasOperation extends OasBase_js_1.OasBase {
|
|
|
222
223
|
return (0, traverseSchema_js_1.traverseSchema)(rootSchema, rest);
|
|
223
224
|
}
|
|
224
225
|
/**
|
|
225
|
-
*
|
|
226
|
+
* The parameters that apply to this operation, as OpenAPI defines them: the
|
|
227
|
+
* path item's parameters apply to each of its operations, and an operation's
|
|
228
|
+
* own parameter with the same name and location replaces the path item's.
|
|
229
|
+
* The path item's come first.
|
|
226
230
|
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
231
|
+
* References stay references, so a caller can resolve each one on its own.
|
|
232
|
+
* A reference that names nothing (kept when `system.danglingRefs` lists
|
|
233
|
+
* `parameter`) keeps its place, and resolving it throws `DanglingRefError`.
|
|
234
|
+
* {@link OasOperation.toParams} resolves them all.
|
|
235
|
+
*
|
|
236
|
+
* @returns the parameters, path item's first
|
|
237
|
+
*/
|
|
238
|
+
toEffectiveParameters() {
|
|
239
|
+
return (0, toEffectiveParameters_js_1.toEffectiveParameters)({ own: this.parameters, shared: this.pathItem?.parameters });
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Resolve all parameters and optionally filter by location: the resolved
|
|
243
|
+
* {@link OasOperation.toEffectiveParameters}.
|
|
230
244
|
*
|
|
231
245
|
* @param filter - only include parameters from specified locations
|
|
232
246
|
* @returns
|
|
247
|
+
* @throws {DanglingRefError} when a parameter is a reference that names nothing
|
|
233
248
|
*/
|
|
234
249
|
toParams(filter) {
|
|
235
|
-
return
|
|
250
|
+
return this.toEffectiveParameters()
|
|
236
251
|
.map(param => param.resolve())
|
|
237
252
|
.filter(param => (filter?.length ? filter.includes(param.location) : true));
|
|
238
253
|
}
|
|
@@ -257,12 +272,17 @@ class OasOperation extends OasBase_js_1.OasBase {
|
|
|
257
272
|
*
|
|
258
273
|
* @param options - Conversion options for nested components
|
|
259
274
|
* @returns OpenAPI v3 operation object
|
|
275
|
+
* @throws {DanglingRefError} when a parameter is a reference that names
|
|
276
|
+
* nothing, as {@link OasOperation.toParams} does: there is no parameter to
|
|
277
|
+
* write, and the caller decides what to do
|
|
260
278
|
*/
|
|
261
279
|
toJsonSchema(options) {
|
|
262
|
-
const parameters =
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
280
|
+
const parameters = this.toEffectiveParameters();
|
|
281
|
+
for (const parameter of parameters) {
|
|
282
|
+
if (parameter.isRef() && (0, toEffectiveParameters_js_1.namesNothing)(parameter)) {
|
|
283
|
+
throw new DanglingRefError_js_1.DanglingRefError(parameter.$ref);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
266
286
|
return {
|
|
267
287
|
tags: this.tags,
|
|
268
288
|
summary: this.summary,
|
|
@@ -11,6 +11,15 @@ type ToEffectiveParametersArgs = {
|
|
|
11
11
|
* The parameters that apply to an operation or webhook, as OpenAPI defines
|
|
12
12
|
* them: the path item's first, then its own. An own parameter with the same
|
|
13
13
|
* name and location replaces the path item's. References stay references.
|
|
14
|
+
*
|
|
15
|
+
* A reference that names nothing (kept when `system.danglingRefs` lists
|
|
16
|
+
* `parameter`) has no name or location. It keeps its place, and only the
|
|
17
|
+
* same `$ref` replaces it.
|
|
14
18
|
*/
|
|
15
19
|
export declare const toEffectiveParameters: ({ own, shared }: ToEffectiveParametersArgs) => Parameter[];
|
|
20
|
+
/**
|
|
21
|
+
* True for a parameter `$ref` that names nothing in the document, which the
|
|
22
|
+
* parser keeps when `system.danglingRefs` lists `parameter`.
|
|
23
|
+
*/
|
|
24
|
+
export declare const namesNothing: (parameter: Parameter) => boolean;
|
|
16
25
|
export {};
|
|
@@ -1,17 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toEffectiveParameters = void 0;
|
|
3
|
+
exports.namesNothing = exports.toEffectiveParameters = void 0;
|
|
4
|
+
const DanglingRefError_js_1 = require("../ref/DanglingRefError.js");
|
|
4
5
|
/**
|
|
5
6
|
* The parameters that apply to an operation or webhook, as OpenAPI defines
|
|
6
7
|
* them: the path item's first, then its own. An own parameter with the same
|
|
7
8
|
* name and location replaces the path item's. References stay references.
|
|
9
|
+
*
|
|
10
|
+
* A reference that names nothing (kept when `system.danglingRefs` lists
|
|
11
|
+
* `parameter`) has no name or location. It keeps its place, and only the
|
|
12
|
+
* same `$ref` replaces it.
|
|
8
13
|
*/
|
|
9
14
|
const toEffectiveParameters = ({ own = [], shared = [] }) => {
|
|
10
15
|
const ownKeys = new Set(own.map(toParameterKey));
|
|
11
16
|
return [...shared.filter(parameter => !ownKeys.has(toParameterKey(parameter))), ...own];
|
|
12
17
|
};
|
|
13
18
|
exports.toEffectiveParameters = toEffectiveParameters;
|
|
19
|
+
/**
|
|
20
|
+
* True for a parameter `$ref` that names nothing in the document, which the
|
|
21
|
+
* parser keeps when `system.danglingRefs` lists `parameter`.
|
|
22
|
+
*/
|
|
23
|
+
const namesNothing = (parameter) => {
|
|
24
|
+
if (!parameter.isRef()) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
parameter.resolve();
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (DanglingRefError_js_1.DanglingRefError.is(error)) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.namesNothing = namesNothing;
|
|
14
39
|
const toParameterKey = (parameter) => {
|
|
40
|
+
if (parameter.isRef() && (0, exports.namesNothing)(parameter)) {
|
|
41
|
+
return `$ref:${parameter.$ref}`;
|
|
42
|
+
}
|
|
15
43
|
const { name, location } = parameter.resolve();
|
|
16
44
|
return `${location}:${name}`;
|
|
17
45
|
};
|
package/script/oas/ref/Ref.d.ts
CHANGED
|
@@ -239,6 +239,12 @@ export declare class OasRef<T extends OasRefData['refType']> extends OasBase {
|
|
|
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/script/oas/ref/Ref.js
CHANGED
|
@@ -487,8 +487,14 @@ class OasRef extends OasBase_js_1.OasBase {
|
|
|
487
487
|
}
|
|
488
488
|
return resolved;
|
|
489
489
|
}
|
|
490
|
+
/**
|
|
491
|
+
* The component name the reference looks up.
|
|
492
|
+
*
|
|
493
|
+
* @throws {DanglingRefError} when the `$ref` has no name, such as
|
|
494
|
+
* `#/components/schemas/`: it names nothing
|
|
495
|
+
*/
|
|
490
496
|
toRefName() {
|
|
491
|
-
return (
|
|
497
|
+
return toLookupName(this.$ref);
|
|
492
498
|
}
|
|
493
499
|
/**
|
|
494
500
|
* Narrows this reference to a schema reference.
|
|
@@ -119,11 +119,21 @@ export declare class OasWebhook extends OasBase {
|
|
|
119
119
|
* `undefined` when there is no body or no schema for that media type.
|
|
120
120
|
*/
|
|
121
121
|
toPayloadSchema(mediaType?: string): OasSchema | OasRef<'schema'> | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* The inbound parameters that apply to this webhook, path item parameters
|
|
124
|
+
* included, with references unresolved. Mirrors
|
|
125
|
+
* {@link OasOperation.toEffectiveParameters}.
|
|
126
|
+
*
|
|
127
|
+
* @returns the parameters, path item's first
|
|
128
|
+
*/
|
|
129
|
+
toEffectiveParameters(): (OasParameter | OasRef<'parameter'>)[];
|
|
122
130
|
/**
|
|
123
131
|
* Resolve the inbound parameters (e.g. the signature/headers a handler
|
|
124
132
|
* receives), optionally filtered by location. Mirrors
|
|
125
133
|
* {@link OasOperation.toParams}, path item parameters included; the
|
|
126
134
|
* parameters carry the same shape, only their direction is inbound.
|
|
135
|
+
*
|
|
136
|
+
* @throws {DanglingRefError} when a parameter is a reference that names nothing
|
|
127
137
|
*/
|
|
128
138
|
toParams(filter?: OasParameterLocation[]): OasParameter[];
|
|
129
139
|
/**
|
|
@@ -169,14 +169,26 @@ class OasWebhook extends OasBase_js_1.OasBase {
|
|
|
169
169
|
toPayloadSchema(mediaType) {
|
|
170
170
|
return this.toPayload()?.toSchema(mediaType);
|
|
171
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* The inbound parameters that apply to this webhook, path item parameters
|
|
174
|
+
* included, with references unresolved. Mirrors
|
|
175
|
+
* {@link OasOperation.toEffectiveParameters}.
|
|
176
|
+
*
|
|
177
|
+
* @returns the parameters, path item's first
|
|
178
|
+
*/
|
|
179
|
+
toEffectiveParameters() {
|
|
180
|
+
return (0, toEffectiveParameters_js_1.toEffectiveParameters)({ own: this.parameters, shared: this.pathItem?.parameters });
|
|
181
|
+
}
|
|
172
182
|
/**
|
|
173
183
|
* Resolve the inbound parameters (e.g. the signature/headers a handler
|
|
174
184
|
* receives), optionally filtered by location. Mirrors
|
|
175
185
|
* {@link OasOperation.toParams}, path item parameters included; the
|
|
176
186
|
* parameters carry the same shape, only their direction is inbound.
|
|
187
|
+
*
|
|
188
|
+
* @throws {DanglingRefError} when a parameter is a reference that names nothing
|
|
177
189
|
*/
|
|
178
190
|
toParams(filter) {
|
|
179
|
-
return
|
|
191
|
+
return this.toEffectiveParameters()
|
|
180
192
|
.map(param => param.resolve())
|
|
181
193
|
.filter(param => (filter?.length ? filter.includes(param.location) : true));
|
|
182
194
|
}
|