【问题标题】:OpenAPI generated schema request body display the default value instead of typeOpenAPI 生成的架构请求正文显示默认值而不是类型
【发布时间】:2020-03-17 10:10:31
【问题描述】:

在将 Pydantic 与 FastApi 结合使用时,我有一个自动生成的 Swagger UI。

示例 Post 方法的代码如下,其中包含使用的 pydantic 模型。

class StackInstanceInvocation(BaseModel):
    params: Dict[str, Any] = {}
    connection_credentials: ConnectionCredentials = None
    stack_infrastructure_template: str = "stackl"
    stack_application_template: str = "web"
    stack_instance_name: str = "default_test_instance"

@router.post('')
def post_stack_instance(stack_instance_invocation: StackInstanceInvocation):
    """Creates a stack instance with a specific name"""
    logger.info("[StackInstances POST] Received POST request")
    # check if SIT exists
    <SCRATCH>

为此,UI 显示以下内容:

Image1Image2

在尝试时:

Image 3

但是,在试用时,我希望预填充的值不是类型,而是指定的默认值(即“stackl”、“web”和“default_test_instance”)。我去了文档,但还没有找到一种方法来做到这一点。这可能吗?

【问题讨论】:

    标签: python fastapi pydantic


    【解决方案1】:

    我认为this 可能会对您有所帮助。将FieldBody 与示例参数一起使用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-25
      相关资源
      最近更新 更多