Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(core, testers) allow other additional types besides 'string' when testing for format #1925

Conversation

jdwit
Copy link
Contributor

@jdwit jdwit commented May 3, 2022

I came across an issue where I have the following schema:

{
  "type": [ "string", "null"],
  "default": null,
  "format": "date"
}

As far as I know this is valid JSON schema, and is not really an edge case: a date field might be allowed a NULL value (maybe I am wrong here).

Currently the isDateControl and isDateTimeControl do not work here because they formatIs tests for schema.type === 'string'. This is replaced with hasType(schema, 'string') so the format is recognized correctly when other types are allowed (such as null) as well.

Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jdwit,

Thank you for the PR ❤️ ! In general this make a lot of sense. However there are some considerations.

Changing the behavior of formatIs is a breaking change. Not every developer using it might be expecting null (or even completely arbitrary) values in their renderer, potentially leading to runtime crashes. As we're shortly before the 3.0 release this is a good opportunity to change this, but we need to add an entry to the migration guide. Please add this to the PR.

In then same vain we need to test all our renderers which use formatIs (React Material, React Vanilla, Angular Material, Vue Vanilla, Vue Vuetify) whether they can handle arbitrary value types. Can you help with this endeavor?

@coveralls
Copy link

Coverage Status

Coverage remained the same at 84.29% when pulling f941910 on jdwit:core-allow-additional-types-when-testing-format into 23e1a55 on eclipsesource:master.

@sdirix
Copy link
Member

sdirix commented May 5, 2022

Thinking about this some more: We should probably adapt formatIs to ONLY allow for 'string', ['string'] and ['string', 'null']. I'm not even sure what to render in cases where the type is something else.

Additionally when the type array is ['string', 'null'] the renderer should recognize that and place null instead of undefined in the data when they are cleared.

What do you think? Is this the same use case you have?

@jdwit
Copy link
Contributor Author

jdwit commented May 6, 2022

Hi @sdirix , I can help providing the test coverage and adding an entry to the migration guide. Interesting point you make on the limitation of only string and null, I would think that the JSON Schema spec should be leading in this. I can imagine a case where a field can contain a string with of format of date OR a number with minimum of 10, format exclusively belongs to string type and minimum to number type. The schema validator thereby selects the relevant restrictions for the value. I am not an expert on JSON Schema but I think the above is described here: https://cswr.github.io/JsonSchema/spec/multiple_types

However this is not really compatible with the concept of selecting a renderer (which must represents a single type/format) 😄 . Considering this your suggestion of only allowing null and string makes more sense.

The thing you mentioned about null being the value when field is cleared, if null is in the collection of allowed types is exactly my use case, I am going to add this to must custom bindings set, thanks. I am not sure if this should be part of the JSONForms core however.

@sdirix
Copy link
Member

sdirix commented May 20, 2022

Hi @jdwit, I'm fine with merging this as is in case the format renderers can handle problems relatively gracefully. The null handling should probably be done in a follow up later on.

Did you have a chance to test them?

@sdirix sdirix merged commit 7e66e63 into eclipsesource:master Jun 16, 2022
@sdirix sdirix added the core label Jun 16, 2022
@sdirix sdirix added this to the 3.0 milestone Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants