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

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

Initial commit

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