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

问题描述

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由任何字符串及其本身组成。

解决方法

您可以按照以下示例来了解这一点

3.4666666666666666666666666667
2
3.1891847822775947292439110472
20
3.1465677471829564012877876609
200
3.1420924036835276076022995132
2000
3.1416426510898869869000847891
20000
3.1415976535647933322124871234
200000
3.1415931535895432385563933310
2000000
3.1415927035897907384627370503
20000000
3.1415926585897932134626435385
200000000