Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erroniously expects security field to be dict instead of list #14

Open
christian-eriksson opened this issue Apr 13, 2020 · 0 comments
Open

Comments

@christian-eriksson
Copy link

The parser erroniously expects security requirement object to be dict instead of list when applied on openapi object. According to the openapi 3 docs the security field should be a list of security requirement object but when parsed with openapi3 I get the following error:

[SpecError("Expected .security to be one of [<class 'dict'>], got <class 'list'>",)]

Example

using 'spec.yaml` below:

# spec.yaml
openapi: 3.0.0
info:
  title: Some Title
  version: 0.0.1
components:
  securitySchemes:
    ApiKey:
      type: apiKey
      name: X-Access-Token
      in: header
security:
  - ApiKey: []
paths:
  /foo:
    get:
      operationId: listFoo
      responses:
        200:
          description: Some description

This snippet will produce the error:

from openapi3 import OpenAPI
import yaml

with open('spec.yaml') as f:
    spec = yaml.safe_load(f.read())

api = OpenAPI(spec, validate=True)

if(len(api._spec_errors) > 0):
    print(api._spec_errors)
# output: [SpecError("Expected .security to be one of [<class 'dict'>], got <class 'list'>",)]

If the security field is under an operation object openapi3 correctly expects it to hold a list of security requirement object.

commonism referenced this issue in commonism/openapi3 Dec 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant