oas-toolkit 0.5.2 → 0.5.3
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/components.js +14 -5
- package/components.test.js +46 -0
- package/package.json +1 -1
package/components.js
CHANGED
|
@@ -28,14 +28,23 @@ function getReferencedComponents(oas) {
|
|
|
28
28
|
if (this.isLeaf && this.key == "$ref") {
|
|
29
29
|
acc.push(x.replace("#/", "").replace(/\//g, "."));
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
// Per-operation security schemes
|
|
33
|
+
if (this.node && this.node["operationId"] && this.node["security"]) {
|
|
34
|
+
for (let item of this.node["security"]) {
|
|
35
|
+
for (let key of Object.keys(item)) {
|
|
36
|
+
acc.push(`components.securitySchemes.${key}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
31
40
|
return acc;
|
|
32
41
|
}, []);
|
|
33
42
|
|
|
34
|
-
// Add security schemes
|
|
35
|
-
if (oas.security){
|
|
36
|
-
for (let item of oas.security){
|
|
37
|
-
for (let key of Object.keys(item)){
|
|
38
|
-
components.push(`components.securitySchemes.${key}`)
|
|
43
|
+
// Add global security schemes
|
|
44
|
+
if (oas.security) {
|
|
45
|
+
for (let item of oas.security) {
|
|
46
|
+
for (let key of Object.keys(item)) {
|
|
47
|
+
components.push(`components.securitySchemes.${key}`);
|
|
39
48
|
}
|
|
40
49
|
}
|
|
41
50
|
}
|
package/components.test.js
CHANGED
|
@@ -258,4 +258,50 @@ describe("#components", () => {
|
|
|
258
258
|
},
|
|
259
259
|
});
|
|
260
260
|
});
|
|
261
|
+
|
|
262
|
+
it("checks per-operation security schemas in addition to global", () => {
|
|
263
|
+
const securityOas = {
|
|
264
|
+
info: { title: "One" },
|
|
265
|
+
components: {
|
|
266
|
+
securitySchemes: {
|
|
267
|
+
personalAccessToken: {
|
|
268
|
+
type: "http",
|
|
269
|
+
scheme: "bearer",
|
|
270
|
+
},
|
|
271
|
+
systemAccessToken: {
|
|
272
|
+
type: "http",
|
|
273
|
+
scheme: "bearer",
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
paths: {
|
|
278
|
+
"/foo": {
|
|
279
|
+
post: {
|
|
280
|
+
operationId: "test-foo",
|
|
281
|
+
security: [{ systemAccessToken: {} }],
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
expect(c.removeUnusedComponents(securityOas)).toEqual({
|
|
288
|
+
info: { title: "One" },
|
|
289
|
+
paths: {
|
|
290
|
+
"/foo": {
|
|
291
|
+
post: {
|
|
292
|
+
operationId: "test-foo",
|
|
293
|
+
security: [{ systemAccessToken: {} }],
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
components: {
|
|
298
|
+
securitySchemes: {
|
|
299
|
+
systemAccessToken: {
|
|
300
|
+
type: "http",
|
|
301
|
+
scheme: "bearer",
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
});
|
|
306
|
+
});
|
|
261
307
|
});
|