首页 > 解决方案 > 如何在 Open api yml 中的地图对象中定义多个对象时间

问题描述

我是 openapi 的新手。我需要一些帮助来编写 open api yml 3.0

对于以下响应格式

{
    “Details”: {
        “detail1”: [
            {
                "id": “idvalue”1,
                “Info”: {
                    “Testinfo1”: "1.0.0",
                    “Testinfo2”: "2.0.0"
                }
            }
        ],
        “Detail2”: [
            {
                "id": “idvalue2”,
                “Info”: {
                    “Testinfo3”: "1.0.0",
                    “Testinfo4”: "2.0.0"                }
            }
        ],
        "Detail3”: [
            {
                “First name”: “firstName,
                “Lastname: “last”Name,
                “Address”: “address”,
                “Dependents”: []
            }
        ]
    },
    "links": {
        "self": {
            "href": “some url”
        }
    }
}

detail1、detail2、detail3 可以是不同的对象类型或相同的对象类型,并且可以没有 details 。我对以下几点感到震惊

  1. 我如何代表地图打开api
  2. 如何用 in map 表示多个对象类型。

标签: swaggerswagger-uiopenapiswagger-2.0swagger-editor

解决方案


在 YAML snap 下面检查这个

DetailsSchemaElement:
  type: object
  properties:
    Details:
      type: object
      properties:
        detail1:
          type: array
          items:
            properties:
              id:
                type: string
              Info:
                type: object
                properties:
                  Testinfo1:
                    type: string
                  Testinfo2:
                    type: string
        Detail2:
          type: array
          items:
            properties:
              id:
                type: string
              Info:
                type: object
                properties:
                  Testinfo4:
                    type: string
                  Testinfo3:
                    type: string
        Detail3:
          type: array
          items:
            properties:
              First-name:
                type: string
              Address:
                type: string
              Dependents:
                type: array
                items:
                  type: string
              Lastname:
                type: string
    links:
      type: object
      properties:
        self:
          type: object
          properties:
            href:
              type: string

推荐阅读