codeoverflow-org / nodecg-io

A NodeCG-bundle which implements Social Media API's in the NodeCG framework
https://nodecg.io
MIT License
108 stars 26 forks source link

Validate configs from the user against the json schema of the service #5

Closed hlxid closed 4 years ago

hlxid commented 4 years ago

Description

To make sure that the user provided config actually has the correct fields and that these fields have the correct type we should validate the config against the json schema that is provided by the service.

This is needed so we can cast the config of type unknown to the config type of the service with knowing that it is actually compatible and that the service can rely on the types of its config.

First it was intended to have a replicant for each service instance and use the Replicant validation from nodecg to do this validation. But this plan has failed for various reasons (read the commit message of ff16cf356331b58fba009f61851ad089e6383826 for more information) and wasn't that great when it comes to persisting it.

So now we have to validate the config against the json schema ourself. ajv-validator/ajv seems to fit our needs here, so I'll probably use that to validate the json schema.

References

Todo comment: https://github.com/codeoverflow-org/nodecg-io/blob/30e6a6f5f42313c6135d13182ade1453d7758c65/nodecg-io-core/extension/instanceManager.ts#L103

hlxid commented 4 years ago

Implemented in 2074fca8d207c8bad9de1e6853813adc088eee60, e6403d0c69fe3e100078f4742043aa68ce513dd6 and 6ac74d9ae832b169cf5b8ab51aca608133412821.