vuetify-jsonschema-form icon indicating copy to clipboard operation
vuetify-jsonschema-form copied to clipboard

anyOf property silently dropped

Open satra opened this issue 4 years ago • 10 comments

when a property itself takes anyOf of two different types, the field is ignored and not displayed.

see the property identifier in this example here: https://codepen.io/satra-the-reactor/pen/PomjgYK?editors=1010

there are no errors in the console.

satra avatar Jul 19 '21 19:07 satra

FWIW, it seems that it doesn't show because there is no "type": "string", before. But it seems to be not required, e.g. valid in https://www.jsonschemavalidator.net/s/On8R53GD . But if added, then I think anyOf is just completely ignored for validation, since "invalid" in aforementioned in validator would show up valid in @satra's codepen

FWIW: related https://github.com/koumoul-dev/vuetify-jsonschema-form/issues/241

yarikoptic avatar Jul 21 '21 16:07 yarikoptic

I think there are several changes required to manage properly this schema, please correct me if I am wrong:

  • detect type of property based on types of items in allOf / anyOf / oneOf
  • raise a warning in the console if types are inconsistent
  • manage combining validation rules from allOf / anyOf / oneOf (only simple rules are supported for now)
  • manage format=uri validation rule

I think that the easiest way to implement the last 2 points would be to finally review and document this ajv integration pull request that I keep forgetting about.

Is loading the full ajv library client-side something that would be possible for you, or would you prefer that vjsf implement some more complex validation by itself ? Taking into consideration the fact that there will always be limitations to what can reasonably be implemented in vjsf.

albanm avatar Sep 02 '21 06:09 albanm

@albanm - the challenge is that format support would need to be added, perhaps through a config option. in general the JSON schema spec says format does not have to be supported by any client. so what vjsf is doing right now actually is schema compliant.

in the context of anyOf complex objects, vjsf does show a choice list to select them. perhaps the same thing could be done for allOf/anyOf/oneOf for combinations of things. but indeed this is more complicated.

if ajv addresses this, that sounds great.

satra avatar Sep 04 '21 15:09 satra

Showing different inputs would be in the scope of vjsf, but I don't think that would be the proper answer here. Anyway I don't think it would be doable as there would not be a clue in the model about what input needs to be displayed (no const property as vjsf uses in anyOf of complex objects).

It seems to me that the proper response here is simply to interpret the anyOf as a combined validation rule for a simple string input. This would be perfectly supported by the ajv integration I think, as well as checking default formats and adding custom formats.

I will work on testing/merging/documenting the ajv integration pull request.

albanm avatar Sep 04 '21 16:09 albanm

I worked on ajv integration (not released yet). This example is very similar to your use case, you can check it out.

albanm avatar Sep 13 '21 10:09 albanm

since this asked me to file a report, i'm filling it here:

image

overall it looks good, just wanted to make sure what makes vjsf consider it valid while jsonschema does not.

satra avatar Sep 26 '21 20:09 satra

The link I gave you was working fine for me, are you simply opening the documentation in a browser or is there another context that I miss ? If you are simply opening the documentation can you tell me what browser you are using and whether there are some error messages in the console ?

Fyi the link was to the documentation of the master branch, this has been released since then and is available on latest.

albanm avatar Sep 27 '21 07:09 albanm

i'm using the brave browser and the released link (same message):

image

satra avatar Sep 29 '21 12:09 satra

it does look like that the ajv extension is detecting the invalid section. just that vjsf is not considering it invalid.

satra avatar Sep 29 '21 12:09 satra

The ajv message you get is provided by the ajv instance that is run by the documentation site outside of vjsf to check for discrepancies. The recent evolution was to use an ajv instance internally to vjsf, this is different. The expected render is this:

screenshot-koumoul-dev github io-2021 10 04-11_03_04

No error message in your browser's console ?

albanm avatar Oct 04 '21 09:10 albanm