0

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?

mikemaccana
  • 110,530
  • 99
  • 389
  • 494
  • 1
    It cannot contain `type` because it uses [AllOf](https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/#allof) keyword for referencing to subschemas, which already contains `type` attribute – alex_noname Feb 02 '21 at 15:38
  • @alex_noname surely the enum param should then use the `type` from the subschemas? – mikemaccana Feb 02 '21 at 15:39
  • I think so. Perhaps the tools do not support OpenAPI 3.0 – alex_noname Feb 02 '21 at 15:46

0 Answers0