source: node_modules/@swagger-api/apidom-ns-openapi-3-1/cjs/refractor/plugins/normalize-security-requirements.cjs

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.8 KB
Line 
1"use strict";
2
3exports.__esModule = true;
4exports.default = void 0;
5var _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 */
18const 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 */
52var _default = exports.default = plugin;
Note: See TracBrowser for help on using the repository browser.