arduino-cli icon indicating copy to clipboard operation
arduino-cli copied to clipboard

Use `"additionalProperties": false` in the configuration JSONSchema

Open cmaglie opened this issue 1 year ago • 1 comments

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

cmaglie avatar Jun 05 '23 14:06 cmaglie

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.

  1. Define a Golang struct that represents the configuration.
  2. Use that Config struct to add jsonschema tags and use some go library to generate the schema.
  3. 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

alessio-perugini avatar Sep 28 '23 09:09 alessio-perugini