Dorthu / openapi3

A Python3 OpenAPI 3 Spec Parser
BSD 3-Clause "New" or "Revised" License
118 stars 47 forks source link

AttributeError is thrown when response does not have content defined in the spec file #12

Open robert-dzikowski opened 4 years ago

robert-dzikowski commented 4 years ago
openapi: 3.0.0

paths:
  /aggregationtypes:
    get:
      responses:
        "200":
          description: OK
          content:
            "*/*":
              schema:
                items:
                  $ref: "#/components/schemas/AggregationTypeDTO"
                type: array
        "401":
          description: Authorization token missing or invalid.
        "404":
          description: added by me -RD        
        "500":
          description: Unknown Error.
      tags:
        - aggregationtypes
      operationId: GetAggregationTypes
      summary: Returns a collection of AggregationTypeDTO

As you can see in the above specification 401, 404, 500 responses have no content, which is valid OpenAPI specification (https://swagger.io/docs/specification/describing-responses/). But when I call this Get request I get the following error for cases when status code is 401 or 404:

Traceback (most recent call last):
  File "C:/working/openapi3/my_main.py", line 49, in <module>
    main()
  File "C:/working/openapi3/my_main.py", line 16, in main
    make_http_requests(api, get_list)
  File "C:/working/openapi3/my_main.py", line 36, in make_http_requests
    response = function()
  File "C:\working\openapi3\openapi3\openapi.py", line 193, in __call__
    **kwargs)
  File "C:\working\openapi3\openapi3\paths.py", line 266, in request
    expected_media = expected_response.content.get(content_type, None)
AttributeError: 'NoneType' object has no attribute 'get'
commonism commented 2 years ago

should be fixed by #56