openapi3 icon indicating copy to clipboard operation
openapi3 copied to clipboard

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

Open robert-dzikowski opened this issue 5 years ago • 1 comments

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'

robert-dzikowski avatar Mar 23 '20 17:03 robert-dzikowski

should be fixed by #56

commonism avatar Dec 21 '21 11:12 commonism