1 | "use strict";
|
---|
2 |
|
---|
3 | exports.__esModule = true;
|
---|
4 | exports.default = void 0;
|
---|
5 | var _apidomNsOpenapi = require("@swagger-api/apidom-ns-openapi-3-0");
|
---|
6 | /**
|
---|
7 | * Override of Security Requirement Objects.
|
---|
8 | *
|
---|
9 | * OpenAPI 3.1 specification excerpt that defines the override behavior:
|
---|
10 | *
|
---|
11 | * Operation.security definition overrides any declared top-level security.
|
---|
12 | * To remove a top-level security declaration, an empty array can be used.
|
---|
13 | * When a list of Security Requirement Objects is defined on the OpenAPI Object or Operation Object,
|
---|
14 | * only one of the Security Requirement Objects in the list needs to be satisfied to authorize the request.
|
---|
15 | */
|
---|
16 |
|
---|
17 | /* eslint-disable no-param-reassign */
|
---|
18 | const plugin = () => ({
|
---|
19 | predicates
|
---|
20 | }) => {
|
---|
21 | let topLevelSecurity;
|
---|
22 | return {
|
---|
23 | visitor: {
|
---|
24 | OpenApi3_1Element: {
|
---|
25 | enter(openapiElement) {
|
---|
26 | if (predicates.isArrayElement(openapiElement.security)) {
|
---|
27 | topLevelSecurity = openapiElement.security;
|
---|
28 | }
|
---|
29 | },
|
---|
30 | leave() {
|
---|
31 | topLevelSecurity = undefined;
|
---|
32 | }
|
---|
33 | },
|
---|
34 | OperationElement: {
|
---|
35 | leave(operationElement, key, parent, path, ancestors) {
|
---|
36 | // skip visiting this Operation
|
---|
37 | if (ancestors.some(predicates.isComponentsElement)) {
|
---|
38 | return;
|
---|
39 | }
|
---|
40 | const missingOperationLevelSecurity = typeof operationElement.security === 'undefined';
|
---|
41 | const hasTopLevelSecurity = typeof topLevelSecurity !== 'undefined';
|
---|
42 | if (missingOperationLevelSecurity && hasTopLevelSecurity) {
|
---|
43 | var _topLevelSecurity;
|
---|
44 | operationElement.security = new _apidomNsOpenapi.OperationSecurityElement((_topLevelSecurity = topLevelSecurity) == null ? void 0 : _topLevelSecurity.content);
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|
48 | }
|
---|
49 | };
|
---|
50 | };
|
---|
51 | /* eslint-enable */
|
---|
52 | var _default = exports.default = plugin; |
---|