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: responses:
'201': '201':
description: example description description: example description
security:
- scheme1: []
scheme2: []
- scheme3: []
scheme4: []
components: components:
schemas: schemas:
some-property: some-property:

View File

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

View File

@@ -39,6 +39,11 @@ paths:
responses: responses:
'200': '200':
description: example description 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: tags:
- foo_other - foo_other
/pets/{petId}: /pets/{petId}:
@@ -48,6 +53,11 @@ paths:
responses: responses:
'201': '201':
description: example description 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: tags:
- bar_other - bar_other
components: components:

View File

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