Closed BilliAlpha closed 3 years ago
@BilliAlpha Thanks. Would you be interested in taking a crack at a PR?
Sorry for the delay in responding, but i'll take a look at it and try something.
@BilliAlpha I havent tried using the new parameter structures yet, was planning on looking at it later today, but I find that adding the line enum: List[str]
to L35 of openapi3/types.py allows me to do this
>>> from sanic_openapi.openapi3.types import Schema
>>> Schema(enum=["a"]).serialize()
{'enum': ['a']}
No idea if that solves your problem or not, feel free to try it out ...
@artcg That would probably be a barebones usage.
But, it probably should be:
enum: Union[List[str], Enum]
In which case we would need some logic on serialization to extract key/values from an enum.
from enum import Enum
class Color(Enum):
RED = "red"
GREEN = "green"
BLUE = "blue"
print([item.value for item in Color.__members__.values()])
# ['red', 'green', 'blue']
@ahopkins I just saw your comment, I'll adapt the PR to support python Enums too.
The PR #235 was merged
I am migrating my project from openapi2 and I found out that the
choices
parameters has disappeared in favor ofenum
. However it seems that this parameter is not supported in sanic-openapi.I suppose the implementation wouldn't be more complex than adding an
enum
field on theSchema
object.The enum field should be supported as specified in the specifications:
The JSON Schema definition of the
enum
field is:https://datatracker.ietf.org/doc/html/draft-wright-json-schema-validation-00#section-5.20