sanic-org / sanic-openapi

Easily document your Sanic API with a UI
https://sanic-openapi.readthedocs.io/
MIT License
505 stars 108 forks source link

#231: [OpenApi3] Add support for enums #235

Closed BilliAlpha closed 3 years ago

BilliAlpha commented 3 years ago

This PR adds the enum field on the Schema object (as explained in #231)

I also added some tests to make sure the field appeared in the resulting openapi specs.

ahopkins commented 3 years ago

Does the OpenAPI spec require enum values to be strings? Or, can it be any valid scalar value? Should we check for this?

BilliAlpha commented 3 years ago

Does the OpenAPI spec require enum values to be strings? Or, can it be any valid scalar value? Should we check for this?

The JSON Schema definition of the enum field is:

The value of this keyword MUST be an array. This array SHOULD have at least one element. Elements in the array SHOULD be unique.

Elements in the array MAY be of any type, including null.

An instance validates successfully against this keyword if its value is equal to one of the elements in this keyword's array value.