sphinx-contrib / openapi

OpenAPI (fka Swagger) spec renderer for Sphinx.
https://sphinxcontrib-openapi.readthedocs.io
BSD 2-Clause "Simplified" License
111 stars 81 forks source link

Exception raised on enum query parameters without "type" #106

Open letmaik opened 3 years ago

letmaik commented 3 years ago

JSON Schema does not require "type" to be present for enums, see also https://json-schema.org/understanding-json-schema/reference/generic.html#enumerated-values.

The plugin however requires it for all query parameter schemas: https://github.com/sphinx-contrib/openapi/blob/4f78db9c8ca2cefc4e4c1eeb46552a8d9d432855/sphinxcontrib/openapi/openapi30.py#L279-L282

Sample error:

2021-01-12T14:38:38.9415027Z Exception occurred:
2021-01-12T14:38:38.9416063Z   File "/__w/1/s/env/lib/python3.8/site-packages/sphinxcontrib/openapi/openapi30.py", line 281, in _httpresource
2021-01-12T14:38:38.9416591Z     type=param['schema']['type'],
2021-01-12T14:38:38.9416959Z KeyError: 'type'

Sample parameter:

          {
            "in": "query",
            "name": "status",
            "required": false,
            "schema": {
              "enum": [
                "PENDING",
                "TRUSTED",
                "RETIRED"
              ]
            }
          }