简体   繁体   中英

sqlmodel: adding an example to a Field()

In pydantic we can add an example to Fields, such as:

Field(default=None, example="A very nice Item")

Which will then be displayed in the swagger API docs:

https://fastapi.tiangolo.com/img/tutorial/body-fields/image01.png

How do we do this in sqlmodel? Adding the key example to the Field class in sqlmodel returns error:

Field() got an unexpected keyword argument 'example'

Thank you!

Can be accomplished using schema_extra :

Field(default=None, schema_extra={'example': "A very nice Item"})

Can be found in code:

https://github.com/tiangolo/sqlmodel/blob/267cd42fb6c17b43a8edb738da1b689af6909300/sqlmodel/main.py#L119

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM