...

Text file src/github.com/qri-io/jsonschema/testdata/draft2019-09/ref.json

Documentation: github.com/qri-io/jsonschema/testdata/draft2019-09

     1[
     2    {
     3        "description": "root pointer ref",
     4        "schema": {
     5            "properties": {
     6                "foo": {"$ref": "#"}
     7            },
     8            "additionalProperties": false
     9        },
    10        "tests": [
    11            {
    12                "description": "match",
    13                "data": {"foo": false},
    14                "valid": true
    15            },
    16            {
    17                "description": "recursive match",
    18                "data": {"foo": {"foo": false}},
    19                "valid": true
    20            },
    21            {
    22                "description": "mismatch",
    23                "data": {"bar": false},
    24                "valid": false
    25            },
    26            {
    27                "description": "recursive mismatch",
    28                "data": {"foo": {"bar": false}},
    29                "valid": false
    30            }
    31        ]
    32    },
    33    {
    34        "description": "relative pointer ref to object",
    35        "schema": {
    36            "properties": {
    37                "foo": {"type": "integer"},
    38                "bar": {"$ref": "#/properties/foo"}
    39            }
    40        },
    41        "tests": [
    42            {
    43                "description": "match",
    44                "data": {"bar": 3},
    45                "valid": true
    46            },
    47            {
    48                "description": "mismatch",
    49                "data": {"bar": true},
    50                "valid": false
    51            }
    52        ]
    53    },
    54    {
    55        "description": "relative pointer ref to array",
    56        "schema": {
    57            "items": [
    58                {"type": "integer"},
    59                {"$ref": "#/items/0"}
    60            ]
    61        },
    62        "tests": [
    63            {
    64                "description": "match array",
    65                "data": [1, 2],
    66                "valid": true
    67            },
    68            {
    69                "description": "mismatch array",
    70                "data": [1, "foo"],
    71                "valid": false
    72            }
    73        ]
    74    },
    75    {
    76        "description": "escaped pointer ref",
    77        "schema": {
    78            "$defs": {
    79                "tilda~field": {"type": "integer"},
    80                "slash/field": {"type": "integer"},
    81                "percent%field": {"type": "integer"}
    82            },
    83            "properties": {
    84                "tilda": {"$ref": "#/$defs/tilda~0field"},
    85                "slash": {"$ref": "#/$defs/slash~1field"},
    86                "percent": {"$ref": "#/$defs/percent%25field"}
    87            }
    88        },
    89        "tests": [
    90            {
    91                "description": "slash invalid",
    92                "data": {"slash": "aoeu"},
    93                "valid": false
    94            },
    95            {
    96                "description": "tilda invalid",
    97                "data": {"tilda": "aoeu"},
    98                "valid": false
    99            },
   100            {
   101                "description": "percent invalid",
   102                "data": {"percent": "aoeu"},
   103                "valid": false
   104            },
   105            {
   106                "description": "slash valid",
   107                "data": {"slash": 123},
   108                "valid": true
   109            },
   110            {
   111                "description": "tilda valid",
   112                "data": {"tilda": 123},
   113                "valid": true
   114            },
   115            {
   116                "description": "percent valid",
   117                "data": {"percent": 123},
   118                "valid": true
   119            }
   120        ]
   121    },
   122    {
   123        "description": "nested refs",
   124        "schema": {
   125            "$defs": {
   126                "a": {"type": "integer"},
   127                "b": {"$ref": "#/$defs/a"},
   128                "c": {"$ref": "#/$defs/b"}
   129            },
   130            "$ref": "#/$defs/c"
   131        },
   132        "tests": [
   133            {
   134                "description": "nested ref valid",
   135                "data": 5,
   136                "valid": true
   137            },
   138            {
   139                "description": "nested ref invalid",
   140                "data": "a",
   141                "valid": false
   142            }
   143        ]
   144    },
   145    {
   146        "description": "ref applies alongside sibling keywords",
   147        "schema": {
   148            "$defs": {
   149                "reffed": {
   150                    "type": "array"
   151                }
   152            },
   153            "properties": {
   154                "foo": {
   155                    "$ref": "#/$defs/reffed",
   156                    "maxItems": 2
   157                }
   158            }
   159        },
   160        "tests": [
   161            {
   162                "description": "ref valid, maxItems valid",
   163                "data": { "foo": [] },
   164                "valid": true
   165            },
   166            {
   167                "description": "ref valid, maxItems invalid",
   168                "data": { "foo": [1, 2, 3] },
   169                "valid": false
   170            },
   171            {
   172                "description": "ref invalid",
   173                "data": { "foo": "string" },
   174                "valid": false
   175            }
   176        ]
   177    },
   178    {
   179        "description": "remote ref, containing refs itself",
   180        "schema": {"$ref": "https://json-schema.org/draft/2019-09/schema"},
   181        "tests": [
   182            {
   183                "description": "remote ref valid",
   184                "data": {"minLength": 1},
   185                "valid": true
   186            },
   187            {
   188                "description": "remote ref invalid",
   189                "data": {"minLength": -1},
   190                "valid": false
   191            }
   192        ]
   193    },
   194    {
   195        "description": "property named $ref that is not a reference",
   196        "schema": {
   197            "properties": {
   198                "$ref": {"type": "string"}
   199            }
   200        },
   201        "tests": [
   202            {
   203                "description": "property named $ref valid",
   204                "data": {"$ref": "a"},
   205                "valid": true
   206            },
   207            {
   208                "description": "property named $ref invalid",
   209                "data": {"$ref": 2},
   210                "valid": false
   211            }
   212        ]
   213    },
   214    {
   215        "description": "$ref to boolean schema true",
   216        "schema": {
   217            "$ref": "#/$defs/bool",
   218            "$defs": {
   219                "bool": true
   220            }
   221        },
   222        "tests": [
   223            {
   224                "description": "any value is valid",
   225                "data": "foo",
   226                "valid": true
   227            }
   228        ]
   229    },
   230    {
   231        "description": "$ref to boolean schema false",
   232        "schema": {
   233            "$ref": "#/$defs/bool",
   234            "$defs": {
   235                "bool": false
   236            }
   237        },
   238        "tests": [
   239            {
   240                "description": "any value is invalid",
   241                "data": "foo",
   242                "valid": false
   243            }
   244        ]
   245    },
   246    {
   247        "description": "Recursive references between schemas",
   248        "schema": {
   249            "$id": "http://localhost:1234/tree",
   250            "description": "tree of nodes",
   251            "type": "object",
   252            "properties": {
   253                "meta": {"type": "string"},
   254                "nodes": {
   255                    "type": "array",
   256                    "items": {"$ref": "node"}
   257                }
   258            },
   259            "required": ["meta", "nodes"],
   260            "$defs": {
   261                "node": {
   262                    "$id": "http://localhost:1234/node",
   263                    "description": "node",
   264                    "type": "object",
   265                    "properties": {
   266                        "value": {"type": "number"},
   267                        "subtree": {"$ref": "tree"}
   268                    },
   269                    "required": ["value"]
   270                }
   271            }
   272        },
   273        "tests": [
   274            {
   275                "description": "valid tree",
   276                "data": { 
   277                    "meta": "root",
   278                    "nodes": [
   279                        {
   280                            "value": 1,
   281                            "subtree": {
   282                                "meta": "child",
   283                                "nodes": [
   284                                    {"value": 1.1},
   285                                    {"value": 1.2}
   286                                ]
   287                            }
   288                        },
   289                        {
   290                            "value": 2,
   291                            "subtree": {
   292                                "meta": "child",
   293                                "nodes": [
   294                                    {"value": 2.1},
   295                                    {"value": 2.2}
   296                                ]
   297                            }
   298                        }
   299                    ]
   300                },
   301                "valid": true
   302            },
   303            {
   304                "description": "invalid tree",
   305                "data": { 
   306                    "meta": "root",
   307                    "nodes": [
   308                        {
   309                            "value": 1,
   310                            "subtree": {
   311                                "meta": "child",
   312                                "nodes": [
   313                                    {"value": "string is invalid"},
   314                                    {"value": 1.2}
   315                                ]
   316                            }
   317                        },
   318                        {
   319                            "value": 2,
   320                            "subtree": {
   321                                "meta": "child",
   322                                "nodes": [
   323                                    {"value": 2.1},
   324                                    {"value": 2.2}
   325                                ]
   326                            }
   327                        }
   328                    ]
   329                },
   330                "valid": false
   331            }
   332        ]
   333    },
   334    {
   335        "description": "refs with quote",
   336        "schema": {
   337            "properties": {
   338                "foo\"bar": {"$ref": "#/$defs/foo%22bar"}
   339            },
   340            "$defs": {
   341                "foo\"bar": {"type": "number"}
   342            }
   343        },
   344        "tests": [
   345            {
   346                "description": "object with numbers is valid",
   347                "data": {
   348                    "foo\"bar": 1
   349                },
   350                "valid": true
   351            },
   352            {
   353                "description": "object with strings is invalid",
   354                "data": {
   355                    "foo\"bar": "1"
   356                },
   357                "valid": false
   358            }
   359        ]
   360    },
   361    {
   362        "description": "ref creates new scope when adjacent to keywords",
   363        "schema": {
   364            "$defs": {
   365                "A": {
   366                    "unevaluatedProperties": false
   367                }
   368            },
   369            "properties": {
   370                "prop1": {
   371                    "type": "string"
   372                }
   373            },
   374            "$ref": "#/$defs/A"
   375        },
   376        "tests": [
   377            {
   378                "description": "referenced subschema doesn't see annotations from properties",
   379                "data": {
   380                    "prop1": "match"
   381                },
   382                "valid": false
   383            }
   384        ]
   385    }
   386]

View as plain text