Check if config is compatible with UI editor#2137
Conversation
bcb1c2c to
68a36f5
Compare
| const optionalEntKeys = ["name", "icon"]; | ||
| const allEntKeys = optionalEntKeys.concat(requiredEntKeys); | ||
|
|
||
| requiredKeys.forEach((key) => { |
There was a problem hiding this comment.
Let's create a helper so we can write code like this:
verify(config, reqKeys, optKeys);
for (const entity of config.entities) {
verify(entity, reqEntKeys, optEntKeys);
}There was a problem hiding this comment.
Yeah was thinking the same
There was a problem hiding this comment.
Maybe we should consider https://json-schema.org/learn/miscellaneous-examples.html ?
|
|
||
| const entitiesConfigStruct = struct.union([ | ||
| { | ||
| entity: "string", |
There was a problem hiding this comment.
Should we add a superstruct that validates entity ID and icon to be valid format?
- entity ID: should contain a
. - icon: should contain
:
| "string", | ||
| ]); | ||
|
|
||
| const cardConfigStruct = struct({ |
There was a problem hiding this comment.
I am wondering, this is something we should probably export from the hui-entities-card so it can validate the config there too ?
There was a problem hiding this comment.
Ah nevermind, the config editor only supports a subset so needs their own.
There was a problem hiding this comment.
Probably, but the struct of the editor is a little bit simpler as it doesn't support special rows etc.
There was a problem hiding this comment.
I wonder if we can have our special struct register types that validate objects.
So we can have something like
const struct = superstruct({
'divider-row': validateDividerRow,
'entity-row': validateEntityRow,
})
const validate = struct({
entities: ['divider-row|entity-row']
})There was a problem hiding this comment.
And use a struct inside validateDividerRow? Or just use a struct instead of superstruct, will make code a little bit more ugly though...
There was a problem hiding this comment.
yeah use a struct inside the validator, if that can work. Was just thinking out loud.
|
Very nice! |
|
This can be merged and the other things can wait for a future PR |
Just for the entities editor now.



Extra keys are not allowed:
Some config is not supported by the UI editor:
And missing required elements:
Fixes: #2124