[INS-1668] handle multiple security requirement objects (#5047)

* [INS-1668] handle multiple security requirement objects

* Add fixtures to test out multiple api keys
This commit is contained in:
Filipe Freire 2022-08-05 12:01:38 +01:00 committed by GitHub
parent 623fe7fc13
commit 0435188220
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 278 additions and 7 deletions

View File

@ -0,0 +1,162 @@
openapi: 3.0.3
info:
description: "This is a sample server Petstore server."
version: 1.0.2
title: Swagger Petstore
termsOfService: http://swagger.io/terms/
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: http://swagger.io
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: ""
operationId: addPet
responses:
"200":
description: successful operation
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Pet"
security:
- apiKey: []
appId: []
- appSecret: []
/pet/findByStatus:
get:
tags:
- pet
summary: Finds Pets by status
description: Multiple status values can be provided with comma separated strings
operationId: findPetsByStatus
parameters:
- name: status
in: query
description: Status values that need to be considered for filter
required: true
explode: true
schema:
type: array
items:
type: string
enum:
- available
- pending
- sold
default: available
responses:
"200":
description: successful operation
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Pet"
"400":
description: Invalid status value
security:
- apiKey: []
- appId: []
- appSecret: []
externalDocs:
description: Find out more about Swagger
url: http://swagger.io
servers:
- url: https://petstore.swagger.io/v2
components:
securitySchemes:
apiKey:
type: apiKey
in: header
name: X-API-KEY
appId:
type: apiKey
in: header
name: X-APP-ID
appSecret:
type: apiKey
in: header
name: X-APP-SECRET
schemas:
Category:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
xml:
name: Category
Tag:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
xml:
name: Tag
Pet:
type: object
required:
- name
- photoUrls
properties:
id:
type: integer
format: int64
category:
$ref: "#/components/schemas/Category"
name:
type: string
example: doggie
photoUrls:
type: array
xml:
name: photoUrl
wrapped: true
items:
type: string
tags:
type: array
xml:
name: tag
wrapped: true
items:
$ref: "#/components/schemas/Tag"
status:
type: string
description: pet status in the store
enum:
- available
- pending
- sold
xml:
name: Pet
ApiResponse:
type: object
properties:
code:
type: integer
format: int32
type:
type: string
message:
type: string

View File

@ -0,0 +1,108 @@
{
"__export_date": "2022-08-05T10:38:46.184Z",
"__export_format": 4,
"__export_source": "insomnia.importers:v0.1.0",
"_type": "export",
"resources": [
{
"_id": "__WORKSPACE_ID__",
"_type": "workspace",
"description": "This is a sample server Petstore server.",
"name": "Swagger Petstore 1.0.2",
"parentId": null
},
{
"_id": "__BASE_ENVIRONMENT_ID__",
"_type": "environment",
"data": {
"base_url": "{{ scheme }}://{{ host }}{{ base_path }}"
},
"name": "Base environment",
"parentId": "__WORKSPACE_ID__"
},
{
"_id": "env___BASE_ENVIRONMENT_ID___sub",
"_type": "environment",
"data": {
"base_path": "/v2",
"host": "petstore.swagger.io",
"scheme": "https",
"xApiKey": "xApiKey",
"xAppId": "xAppId",
"xAppSecret": "xAppSecret"
},
"name": "OpenAPI env",
"parentId": "__BASE_ENVIRONMENT_ID__"
},
{
"_id": "fld___WORKSPACE_ID__1b034c38",
"_type": "request_group",
"description": "Everything about your Pets",
"environment": {},
"name": "pet",
"parentId": "__WORKSPACE_ID__"
},
{
"_id": "req___WORKSPACE_ID__23acbe44",
"_type": "request",
"authentication": {},
"body": {},
"headers": [
{
"disabled": false,
"name": "X-API-KEY",
"value": "{{ xApiKey }}"
},
{
"disabled": false,
"name": "X-APP-ID",
"value": "{{ xAppId }}"
},
{
"disabled": false,
"name": "X-APP-SECRET",
"value": "{{ xAppSecret }}"
}
],
"method": "POST",
"name": "Add a new pet to the store",
"parameters": [],
"parentId": "fld___WORKSPACE_ID__1b034c38",
"url": "{{ base_url }}/pet"
},
{
"_id": "req___WORKSPACE_ID__80ab0d08",
"_type": "request",
"authentication": {},
"body": {},
"headers": [
{
"disabled": false,
"name": "X-API-KEY",
"value": "{{ xApiKey }}"
},
{
"disabled": false,
"name": "X-APP-ID",
"value": "{{ xAppId }}"
},
{
"disabled": false,
"name": "X-APP-SECRET",
"value": "{{ xAppSecret }}"
}
],
"method": "GET",
"name": "Finds Pets by status",
"parameters": [
{
"disabled": false,
"name": "status",
"value": "available"
}
],
"parentId": "fld___WORKSPACE_ID__1b034c38",
"url": "{{ base_url }}/pet/findByStatus"
}
]
}

View File

@ -288,13 +288,14 @@ const parseSecurity = (
} }
const supportedSchemes = security const supportedSchemes = security
.map(securityPolicy => { .flatMap(securityPolicy => {
const securityName = Object.keys(securityPolicy)[0]; return Object.keys(securityPolicy).map((securityRequirement: string | number) => {
return { return {
// @ts-expect-error the base types do not include an index but from what I can tell, they should // @ts-expect-error the base types do not include an index but from what I can tell, they should
schemeDetails: securitySchemes[securityName], schemeDetails: securitySchemes[securityRequirement],
securityScopes: securityPolicy[securityName], securityScopes: securityPolicy[securityRequirement],
}; };
});
}) })
.filter(({ schemeDetails }) => ( .filter(({ schemeDetails }) => (
schemeDetails && SUPPORTED_SECURITY_TYPES.includes(schemeDetails.type) schemeDetails && SUPPORTED_SECURITY_TYPES.includes(schemeDetails.type)