【问题标题】:OpenAPI not empty StringOpenAPI 非空字符串
【发布时间】:2021-04-09 12:37:24
【问题描述】:

我有问题。

我创建了 openApi 请求,我想发送到请求不是空的正文

/test
  post:
   .
   .
   .
   requestBody:
     required:true

TestRequest
  type: object
  required:
    - testName
  properties:
    testName:
    type: string
    description: Test

我可以发送一个空的请求,比如 { } 关于邮递员。

我该如何解决这个问题。

【问题讨论】:

标签: swagger openapi


【解决方案1】:

您的 post 定义声明 a 正文是必需的。但是,您尚未定义必须进入该主体的数据的形状。

这是一个假设您的 TestRequestcomponents/schemas 中定义的示例。

paths:
  /test:
    post:
      description: An example referencing TestRequest
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TestRequest'

【讨论】:

    猜你喜欢
    • 2017-06-12
    • 2018-07-04
    • 2011-09-21
    • 1970-01-01
    • 2013-04-29
    • 1970-01-01
    • 2019-07-24
    • 2015-09-13
    • 1970-01-01
    相关资源
    最近更新 更多