Closed djelusic closed 3 years ago
I implemented a first version of this using jsonschema, specifically these two libraries:
https://github.com/alecthomas/jsonschema for generating the json schema from a Go struct, and https://github.com/qri-io/jsonschema for validating the config against the generated schema.
The config/environment.yml
file is now validated every time it is loaded. If there are validation errors they will be shown to the user. For example, the following config file:
project:
memory_size: string
env:
KEY: 12345
KEY2: project
KEY3: project
stages:
- name: dev
memory_size: string
extra_field: oops
timeout: 120
env:
KEY2: stage
KEY3: stage
functions:
- name: ping
env:
KEY3: function
will produce the following error message:
Failed to validate environment.yml:
/project/stages/0/memory_size: type should be integer, got string
/project/stages/0: additional properties are not allowed
/project/memory_size: type should be integer, got string
/project/env/KEY: type should be string, got integer
Config files that can be modified by users should be validated against a predefined schema. This currently applies to
config/environment.yml