angular-schema-form icon indicating copy to clipboard operation
angular-schema-form copied to clipboard

Array "type" not supported to json-schema spec: eg. ["number","string"]

Open johnedvard opened this issue 8 years ago • 4 comments

Hi. I have posted a question on stackoverflow because I am not able to make my example work (being validated correctly).

I have the form:

[
  {
    "key":"foo",  
    "title":"Test",
    "type":"string" 
  }
]

The schema:

{
 "type": "object",
  "properties": {
    "foo": {
        "type": ["number","string"],
        "maxLength":2,
        "minLength":0,
        "minimum":3,
        "maximum":10
    }
  }
}

and the model:

{
  "foo": "bar"
}

The problem is that the validation tells me that the model is valid, even though it is not according to the json-schema-validator.

when I post my schema and model in the json-schema-validator, my example work. Why is that? Am I doing something wrong in the form?

johnedvard avatar Jan 28 '16 07:01 johnedvard

Yes, it seems like that works there. But I cannot find anywhere in the specification that having multiple values for "type" is supported, albeit a cursory look. The validator for ASF is TV4, perhaps they have some information?

(I am not sure I would use that functionality even if I could, that'd just be moving a problem further along)

nicklasb avatar Jan 31 '16 17:01 nicklasb

Oops, found it. Indeed it can be an array.

nicklasb avatar Jan 31 '16 17:01 nicklasb

A quick look at source shows that array type definition is primarily supported to support ["null","non-null"], given the example the result could only be a string as that is what the form is set to. So given the form has to be set to something it makes supporting opposite types quite difficult which is why I suspect it hasn't been tackled by anyone.

Anthropic avatar Feb 16 '16 02:02 Anthropic

Yes, it is probably for the same reason "anyOf" isn't supported yet.

nicklasb avatar Feb 16 '16 08:02 nicklasb