fix: join command security schemas fix (#1439)

This commit is contained in:
Mateusz Lis
2024-02-16 16:38:42 +01:00
committed by GitHub
parent fc21cfdd64
commit 4b54bc8a15
5 changed files with 30 additions and 4 deletions

View File

@@ -0,0 +1,5 @@
---
"@redocly/cli": patch
---
Adds support for using logical AND for the security schema so that the `join` command generates the correct schema.

View File

@@ -19,7 +19,11 @@ paths:
responses:
'201':
description: example description
security:
- scheme1: []
scheme2: []
- scheme3: []
scheme4: []
components:
schemas:
some-property:

View File

@@ -27,7 +27,11 @@ paths:
responses:
'200':
description: example description
security:
- scheme1: []
scheme2: []
scheme3: []
scheme4: []
components:
schemas:
some-property:

View File

@@ -39,6 +39,11 @@ paths:
responses:
'200':
description: example description
security:
- Foo Example OpenAPI 3 definition foo._scheme1: []
Foo Example OpenAPI 3 definition foo._scheme2: []
Foo Example OpenAPI 3 definition foo._scheme3: []
Foo Example OpenAPI 3 definition foo._scheme4: []
tags:
- foo_other
/pets/{petId}:
@@ -48,6 +53,11 @@ paths:
responses:
'201':
description: example description
security:
- Bar Example OpenAPI 3 definition._scheme1: []
Bar Example OpenAPI 3 definition._scheme2: []
- Bar Example OpenAPI 3 definition._scheme3: []
Bar Example OpenAPI 3 definition._scheme4: []
tags:
- bar_other
components:

View File

@@ -756,8 +756,11 @@ function addComponentsPrefix(description: string, componentsPrefix: string) {
function addSecurityPrefix(security: any, componentsPrefix: string) {
return componentsPrefix
? security?.map((s: any) => {
const key = Object.keys(s)[0];
return { [componentsPrefix + '_' + key]: s[key] };
const joinedSecuritySchema = {};
for (const [key, value] of Object.entries(s)) {
Object.assign(joinedSecuritySchema, { [componentsPrefix + '_' + key]: value });
}
return joinedSecuritySchema;
})
: security;
}