FastAPI/Redoc created 'openapi.json' is missing 'type' key for Enum params

563 Views Asked by At

I have a REST API build using FastAPI, with various query string params that are all working fine, generating working openapi.json output:

flagged: bool = False,

Generates:

{
  "required": false,
  "schema": {
    "title": "Flagged",
    "type": "boolean"
  },
  "name": "flagged",
  "in": "query"
}

However I have some params that use Enum values. The resulting openAPI definition is missing a type specifier -

sortby: TaskSortby = TaskSortby.confusion,

Generates:

 {
  "required": false,
  "schema": {
    "allOf": [
      {
        "$ref": "#/components/schemas/TaskSortby"
      }
    ],
    "default": "confusion"
  },
  "name": "sortby",
  "in": "query"
}

As you can see schema.type is missing, which causes other tools that read openapi.json files to break.

How can I generate an openapi.json with type key for Enum params?

0

There are 0 best solutions below