[英]sqlmodel: adding an example to a Field()
In pydantic we can add an example to Fields, such as:在pydantic中我们可以给Fields添加一个例子,比如:
Field(default=None, example="A very nice Item")
Which will then be displayed in the swagger API docs:然后将显示在 swagger API 文档中:
How do we do this in sqlmodel?我们如何在 sqlmodel 中执行此操作? Adding the key example to the Field class in sqlmodel returns error:
在sqlmodel中的Field class中添加key example返回错误:
Field() got an unexpected keyword argument 'example'
Field() 得到了一个意想不到的关键字参数 'example'
Thank you!谢谢!
Can be accomplished using schema_extra
:可以使用
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 https://github.com/tiangolo/sqlmodel/blob/267cd42fb6c17b43a8edb738da1b689af6909300/sqlmodel/main.py#L119
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.