Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Pizzaface opened this issue Nov 10, 2023 · 0 comments
Open

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

Pizzaface opened this issue Nov 10, 2023 · 0 comments

Comments

@Pizzaface
Copy link

Pizzaface commented Nov 10, 2023

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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant