简体   繁体   English

如何为多类型数组定义 json schma

[英]How to define json schma for multiple type array

Json Sample: 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 Schema Json 架构

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

I am not sure the given schema is correct.我不确定给定的架构是否正确。 For a general saying, the TestResults is composed of any of string(s) and itself.笼统地说,TestResults 由任何字符串及其本身组成。

You can follow this example to get an idea about this你可以按照这个例子来了解这个

  "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"
          ]
        }
      }
    }
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以从JSON文件生成Avro schma? - Is it possible to generate Avro schma from JSON file? 如何在 JSON 模式中定义嵌套数组,其中数组项的基本类型是特定类型 - How to define nested arrays in JSON schema where the base type of array items is specific type 使用数组在JSON模式中定义类型 - Using an array to define type in JSON Schema 如何在Json Schema 4中定义类型百分比的属性 - How to define property of type percentage in Json Schema 4 如何在 xml 文件的 header 中定义 json 的类型 - How to define type of json in header of in xml file 如何在打字稿中为带有嵌套属性的json定义类型? - How to define a type for a json with nested properties in typescript? 如何在 Android Studio 中的 JSON 中解析 JSON 数据而不定义数组 - How to parse JSON data without define array in JSON in Android Studio 如何在json模式中定义数组的最小大小 - How to define the min size of array in the json schema 如何在 Go 中解码 JSON ,它将多个元素作为类型数组返回,将单个元素作为类型返回 - How to decode JSON in Go which returns multiple elements as array of type and individual elements as type 如何从 django 模型中为模型字段定义 json 类型 - how to define a json type to a model field from django models
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM