-
Notifications
You must be signed in to change notification settings - Fork 100
Description
I'm using Piccolo with FastAPI, which generates documentation in Swagger. In my tables file, I've created a table (relationship) that has a field based on an enum
class RelationshipType(str, enum.Enum):
colleague = "colleague"
friend = "friend"
...
type= Varchar(choices=RelationshipType)When I use create_pydantic_model to generate a pydantic model based on the table, I had expected the "choices" field to get passed along to Swagger, but that doesn't seem to be the case. Swagger treats it as a vanilla string.
I dumped the schemas for both a Pydantic model created directly that uses an enum and a Pydantic model created using the create_pydantic_model method, and they're laid out pretty differently. I'll add them at the end.
Do you have any guidance on how to get the enum created in piccolo tables to get reflected in Swagger? Do I have to drop down and create Pydantic models directly if I'd like this functionality?
# Direct Pydantic model
model.construct().schema()
{'title': 'RelationshipTest', 'type': 'object', 'properties': {'class_1': {'title': 'Class 1', 'type': 'integer'}, 'class2': {'title': 'Class2', 'type': 'integer'}, 'type': {'$ref': '#/definitions/RelationshipType'}}, 'required': ['class_1', 'class2', 'type'], 'definitions': {'RelationshipType': {'title': 'RelationshipType', 'description': 'An enumeration.', 'enum': ['colleague', 'friend', 'relative'], 'type': 'string'}}}
# Creating a model from Piccolo table
model.construct().schema()
{'title': 'RelationshipIn', 'type': 'object', 'properties': {'first_contact': {'title': 'First Contact', 'extra': {'foreign_key': True, 'to': 'contact', 'target_column': 'id', 'help_text': None, 'choices': None}, 'nullable': True, 'type': 'integer'}, 'second_contact': {'title': 'Second Contact', 'extra': {'foreign_key': True, 'to': 'contact', 'target_column': 'id', 'help_text': None, 'choices': None}, 'nullable': True, 'type': 'integer'}, 'type': {'title': 'Type', 'extra': {'help_text': None, 'choices': {'colleague': {'display_name': 'Colleague', 'value': 'colleague'}, 'friend': {'display_name': 'Friend', 'value': 'friend'}, 'relative': {'display_name': 'Relative', 'value': 'relative'}, 'partner': {'display_name': 'Partner', 'value': 'partner'}, 'ex': {'display_name': 'Ex', 'value': 'ex'}, 'child': {'display_name': 'Child', 'value': 'child'}, 'teacher': {'display_name': 'Teacher', 'value': 'teacher'}, 'student': {'display_name': 'Student', 'value': 'student'}}}, 'nullable': False, 'maxLength': 255, 'type': 'string'}}, 'help_text': None}