微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在用户对象中编辑 YAML 响应

如何解决如何在用户对象中编辑 YAML 响应

我正在通过 swagger 制作 API 文档 在我大摇大摆的编辑器中,我返回此回复

 {
  "id": "70020ed1-50fe-4c7e-afed","email": "test123@gmail.com","authentication_token": "xzmsjvvkvgf448449"
}

通过下面来自swagger编辑器的代码

responses:
        200:
          description: User credentials.
          schema:
          # $ref: '#/deFinitions/User'
            properties:
              id:
                type: string
                example: 70020ed1-50fe-4c7e-afed
              email:
                type: string
                example: test123@gmail.com
              authentication_token:
                type: string
                example: xzmsjvvkvgf448449

我想以一种实际的方式展示它。像这样

    {
    "message": "User information & already exist","user": {
        "id": "2386d9c5-5530-4950-b8fe-","email": "saad.arshad@yahoo.com","authentication_token": "kagHmoRSmPiu2R"}}

可能在用户对象中。

解决方法

您需要将 user 嵌套在一个对象中:

responses:
  200:
    description: User credentials.
    content:
      application/json:
        schema:
          properties:
            message:
              type: string
              example: "User Information already exists"
            user:
              type: object
              properties:
                id:
                  type: string
                  example: 70020ed1-50fe-4c7e-afed
                email:
                  type: string
                  example: test123@gmail.com
                authentication_token:
                  type: string
                  example: xzmsjvvkvgf448449

请参阅 https://swagger.io/docs/specification/data-models/data-types/#nested 了解更多信息,以及有关如何使用引用的说明。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。