balena-io-modules / jellyschema

JellySchema - data validation, UI form generation
Apache License 2.0
4 stars 2 forks source link

Introduce fill_default_values #114

Closed zrzka closed 5 years ago

zrzka commented 5 years ago

Change-type: patch Signed-off-by: Robert Vojta robert@balena.io

zrzka commented 5 years ago

@cyplo doesn't this & this do what you want?

cyplo commented 5 years ago

I think it could be a part of it. I'm thinking of a case where we do not have an optional type there.

From rendition perspective, if the schema defines a non-optional property we could still accept empty {} as a default value for the whole data object, as the form will set it there. It just needs to be an object. It looks weird, because it does not conform to the schema, but would work.

If we'd like to have it conform to the schema, it would work as well, so e.g. { "stringProperty" : ""} should be perfectly fine, as long as it is returned for a schema where the stringProperty does not have a default keyword set as well.

So in other words:

properties:
  - stringProperty:
      type: string

could either result in default value be {} or { "stringProperty" : ""} - both are acceptable. I kinda like the second a bit more because it is more specific and because it should pass the schema validation. What do you think ?

zrzka commented 5 years ago

I did commit a change where I make sure that the root object / array is created.

But this ...

properties:
  - stringProperty:
      type: string

... leading to { "stringProperty" : ""} I do not like. I don't see a reason to do it. This is about default in the JellySchema. Empty object / array is one thing, but real value for string (even empty "") is something completely different.

cyplo commented 5 years ago

Cool, let me test this out after lunch and I can try and see what happens when I try to use it in rendition :)

zrzka commented 5 years ago

One important note - this isn't replacement of what you do in rendition. It should fill in default values and that's it. So, if you need more, should be done in rendition.