prance icon indicating copy to clipboard operation
prance copied to clipboard

[BUG] `nullable` enums do not add `null` to the enum list

Open Pizzaface opened this issue 1 year ago • 0 comments

Describe the bug When adding a nullable enum Schema, the operation will fail unless null is directly provided in the enum list. This is because nullable is not processed before the schema is validated and not having null in the values causes an error.

Schema Example:

The following causes the Exception, whereas including null will satisfy the schema.

{
  "name": "sortOrder",
  "in": "query",
  "description": "Sort direction. Example: \"asc\".",
  "schema": {
    "type": "string",
    "nullable": true,
    "default": null,
    "enum": [
      "asc",
      "desc"
    ]
  }
}

Corrected:

{
  "name": "sortOrder",
  "in": "query",
  "description": "Sort direction. Example: \"asc\".",
  "schema": {
    "type": "string",
    "nullable": true,
    "default": null,
    "enum": [
      null,
      "asc",
      "desc"
    ]
  }
}

Exception:

("None is not one of ['asc', 'desc']", 'enum', deque([]), None, [], ['asc', 'desc'], None, {'type': 'string', 'nullable': True, 'default': None, 'enum': ['asc', 'desc']}, deque(['enum']), None)

To Reproduce Steps to reproduce the behavior:

  1. Create an endpoint with a nullable string parameter.
  2. Do not include null in the enum values
  3. Attempt to parse the spec

Expected behavior When adding a nullable field - the property should have null automatically added to the enum list - with the default being null if not supplied while allowing a set value.

System details (please complete the following information):

  • OS: [Ubuntu]
  • OpenAPI / Swagger version [OpenAPI 3.0.1]
  • Python version [3.10.12]

Pizzaface avatar Nov 10 '23 21:11 Pizzaface