arduino-cli
arduino-cli copied to clipboard
Use `"additionalProperties": false` in the configuration JSONSchema
Describe the request
from @kittaakos:
I have noticed that the
additionalProperties
is absent from the schema. Hence, when generating types downstream, arbitrary properties are valid. Are they valid? In other words, is the "additionalProperties": false missing on purpose?
Describe the current behavior
If an extraneous property is present in the config file of the CLI it is not detected as "wrong".
Arduino CLI version
nightly
Operating system
N/A
Operating system version
N/A
Additional context
No response
Issue checklist
- [X] I searched for previous requests in the issue tracker
- [X] I verified the feature was still missing when using the nightly build
- [X] My request contains all necessary details
The JSON schema should be generated starting from a well-known structure. Unfortunately, the current schema was hand-written. Not being automatically generated has two downsides: difficulty in adding new properties, and the correctness of the values. This makes the schema completely unreliable. In the CLI, we cannot perform the configuration validation, leaving the door open at runtime issues that could be prevented in the first place.
At this point, we have to rethink the configuration system from the ground up.
- Define a Golang struct that represents the configuration.
- Use that Config struct to add
jsonschema
tags and use some go library to generate the schema. - Understand if we can remove
viper
.
Pros
- Validate config file at startup aka no more runtime errors
- Configs are now typed
- Jsonschema is automatically generated
- We can lower the viper footprint or even completely remove it
Cons
- Require a good amount of effort and planning