【问题标题】:How to define json schma for multiple type array如何为多类型数组定义 json 模式
【发布时间】:2020-08-22 02:47:06
【问题描述】:

Json 示例:

{
    "testResults": [
        "begin",
        [
            "call step 1.1",
            "call step 1.2"
        ],
        [
            "call step 2.1",
             [
                "call step 2.1.1",
                [
                    "call step 2.1.1.1",
                    "call step 2.1.1.2"
                ],
                [
                    "call step 2.1.2.1",
                    "call step 2.1.2.2"
                ],
                "end call step 2.1.1"
            ]
        ],
        "end"
    ]
}

Json 架构

    TestResults:
      type: array
      items:
        anyOf:
          - type: string
          - $ref: "#/components/schemas/TestResults"

我不确定给定的架构是否正确。通俗的说,TestResults 由任意字符串和它自己组成。

【问题讨论】:

    标签: json yaml schema openapi


    【解决方案1】:

    你可以按照这个例子来了解这个

      "SampleSchema": {
        "type": "object",
        "properties": {
          "daysOfWeek": {
            "description": "An array of zero or more days of the week",
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "Sunday",
                "Monday",
                "Tuesday",
                "Wednesday",
                "Thursday",
                "Friday",
                "Saturday"
              ]
            }
          }
        }
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-14
      • 2014-11-11
      • 2019-11-06
      • 2016-02-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多