[英]FastAPI schema from an OpenAPI yaml file
I'm looking for a way to initialize a FastAPI server, with an existing OpenAPI YAML schema file.我正在寻找一种使用现有 OpenAPI YAML 架构文件初始化FastAPI服务器的方法。
The docs do describe how to modify the auto-generated schema, but I'm looking for something like Connexion , which can generate the validators on-the-fly.文档确实描述了如何修改自动生成的模式,但我正在寻找类似Connexion 的东西,它可以即时生成验证器。
Edit编辑
I've traced down the offending property to this one:我已经将有问题的财产追溯到这个:
class MyParameters(BaseModel):
...
ModelName: Optional[ModelName] = Field(None, description='')
...
The matching object schema in openapi.yaml: openapi.yaml 中匹配的对象模式:
MyParameters:
type: object
properties:
...
ModelName:
type: string
enum: [XYZ]
description: ""
...
ModelName
is not mandatory. ModelName
不是必需的。
After resolving the issue with fastapi-code-generator , I've opted to use it.在使用fastapi-code-generator解决问题后,我选择使用它。
For future readers, who use Python 3.7 , the issue was a missing import in the generated models.py
file:对于使用Python 3.7 的未来读者,问题是生成的
models.py
文件中缺少导入:
from __future__ import annotations
Adding it at the top of models.py
resolved the issue.在
models.py
的顶部添加它解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.