简体   繁体   中英

How to define json schma for multiple type array

Json Sample:

{
    "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

    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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM