Replies: 1 comment 3 replies
-
好问题!我觉得 2 更好。 |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
位于不同api文件的不同入参模型,会相互覆盖。
具体见下,假如我有2个api,api_a.py里具有子模型Sub,api_b.py里也具有子模型Sub,那么在生成的api文档里2个接口入参显示是一样的
api_a.py
api_b.py
具体原因是pydantic生成的$ref是按类模型名称生成的,在构建OpenAPI文档时放入definitions的key,如果类名称一样那么key就一样,也即会覆盖。
讨论下怎么解决这个问题?
1、在构建pydantic模型时多加一个参数指明模型的绝对位置,接着在生成openapi.json时也使用这个参数生成唯一的ref引用?
2、pydantic的schema方法是否就可以生成带前缀的ref?
Beta Was this translation helpful? Give feedback.
All reactions