jsonforms
jsonforms copied to clipboard
Should formatIs ranker support null types?
Describe the bug
export const formatIs = (expectedFormat: string): Tester =>
schemaMatches(
schema =>
!isEmpty(schema) &&
schema.format === expectedFormat &&
schema.type === 'string'
);
Expected behavior
Should support nulls
type: ['string', 'null']
Steps to reproduce the issue
N/A
Screenshots
No response
In which browser are you experiencing the issue?
N/A
Framework
Core
RendererSet
No response
Additional context
No response
Hi @alastair-todd thanks for the report. If I read the spec correctly we should probably not hard code a check against null
but rather check whether string
is included in the type
array.
The only problem I see here is for users who are already using formatIs
, rely on the type always being a string
and then suddenly their custom renderer is also invoked on other types.
In the mean time you can always write your own version of formatIs
which works "properly"
Well yeah I've gone and created my own testers.
const formatIs = (expectedFormat: string): Tester =>
schemaMatches((schema) => !isEmpty(schema) && schema.format === expectedFormat);
Its the same for oneOf
with a null value e.g.
[
{
"title":" ",
"type":"null"
},
{
"title":"Permanent",
"const":"Permanent"
},
{
"title":"Temporary",
"const":"Temporary"
},
{
"title":"Casual",
"const":"Casual"
}
]
const isOneOfEnumControl = and(
uiTypeIs('Control'),
schemaMatches(schema =>
schema.hasOwnProperty('oneOf')
)
);
(removed the in-built version's forcing all options to be const
)
This was fixed with https://github.com/eclipsesource/jsonforms/pull/1925