json schema enforces on array but not object

19 Views Asked by At

I have a custom json schema and have a problem where some data may be either an object or an array depending on the number of records generated when converting from xml. My current schema (using with yaml) will enforce values if the data is in an array but not if there was only one record and it is an object.

The sample data may be:

          sr:
               kref:
                 +content: kisa
                 +@type: spv

or

          sr:
               kref:
                 - +content: kisa
                   +@type: spv
... more items

my schema currently contains:

       "kref_spv_type": {
         "anyOf": [
           {
             "type": "array"
           },
           { 
             "type": "object"
           }
         ], 
        "minItems": 1,
         "items": {    
           "type": "object",
           "properties": {
             "+content": {
               "type": "string"
             },
             "+@type": {
               "type": "string",
               "enum": [
                 "spv",
                 "par"
               ]
             }
           },
           "required": [
             "+@type", 
             "+content" 
           ]            
       }
       },

In the case of an object above, if there is bad data for type or content, nothing will show up in diagnostics. However in the second case, if the 'kref' contains an array, then the diagnostics will work fine.

The screenshot shows the diagnostics working with invalid data in an array. But not working with an object.

I should get a diagnostics error in either case. How can I fix this? Is it an issue with the schema? Or is it maybe even a lanaguge server issue/bug?

Thanks!!!

diagnostics don't work with single object kref item

diagnostics work with kref array item(s)

0

There are 0 best solutions below