zeitbach.com

Nullable enums in OpenAPI

TIL: specifying nullable: true is not enough for an enum to allow null values in an OpenAPI schema. You need to add null explicitly to the set of allowed values, because both constraints need to be satisfied.

A colleague stumbled upon this problem with the Python library we are using to generate OpenAPI specifications from our Marshmallow models (apispec). The library didn’t add a null value to nullable enums, which made our schema validation tests fail. I opened a PR with a fix that is now available starting from version 6.5.0.