koumoul-dev / vuetify-jsonschema-form

Create beautiful and low-effort forms that output valid data. Published on npm as @koumoul/vjsf.
https://koumoul-dev.github.io/vuetify-jsonschema-form/latest/
MIT License
546 stars 155 forks source link

anyOf property silently dropped #278

Open satra opened 3 years ago

satra commented 3 years ago

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.

yarikoptic commented 3 years ago

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

albanm commented 3 years ago

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

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.

satra commented 3 years ago

@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.

albanm commented 3 years ago

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 commented 3 years ago

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

satra commented 3 years ago

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.

albanm commented 3 years ago

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.

satra commented 3 years ago

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

image

satra commented 3 years ago

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

albanm commented 3 years ago

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 ?