-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
builtins.jsonSchemaValidate attrset ./path/to/schema.json
#5392
Comments
I'm willing to work on this one (on my free time) I'll be familiarizing myself a little bit with the codebase in #3505 |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/kubenix-not-maintained-anymore/15324/4 |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/nix-data-merge-mini-dsl-with-array-merge-semantics/15540/1 |
- Add https://github.com/pboettch/json-schema-validator as a dependency `json-schema-validator` is a library that uses `nlohmann` internally, which is being used in other components of Nix already `json-schema-validator` is MIT licensed, complies with the latest draft of JSON schema and is the second one with most stars on GitHub - Add a new builtin for validating data with a JSON schema. This builtin receives two arguments: `data` and `schema`, both in Nix format - Demo: ```nix let data1 = { age = 42; }; data2 = { age = 42; name = "Albert"; }; schema = builtins.fromJSON '' { "$schema": "http://json-schema.org/draft-07/schema#", "title": "A person", "properties": { "name": { "description": "Name", "type": "string" }, "age": { "description": "Age of the person", "type": "number", "minimum": 2, "maximum": 200 } }, "required": [ "name", "age" ], "type": "object" } ''; in [ (builtins.validateJsonSchema data1 schema) (builtins.validateJsonSchema data2 schema) ] ``` ```bash $ nix-instantiate --eval --strict test.nix [ false true ] ``` - This is a work in progress and any feedback would be very appreciated! A few open questions I have: - Is it ok to upload the third party dependency into the repository? it's currently being done for cpptoml and nlohmann - Is the proposed semantics ok? or, for example, receiving the schema as a string would be better? - Pending work: - Add docs - Add tests - Improve error messages by returning the validation messages instead of just success=(true/false) Mentions NixOS#5392
- Add https://github.com/pboettch/json-schema-validator as a dependency `json-schema-validator` is a library that uses `nlohmann` internally, which is being used in other components of Nix already `json-schema-validator` is MIT licensed, complies with the latest draft of JSON schema and is the second one with most stars on GitHub - Add a new builtin for validating data with a JSON schema. This builtin receives two arguments: `data` and `schema`, both in Nix format - Demo: ```nix let data1 = { age = 42; }; data2 = { age = 42; name = "Albert"; }; schema = builtins.fromJSON '' { "$schema": "http://json-schema.org/draft-07/schema#", "title": "A person", "properties": { "name": { "description": "Name", "type": "string" }, "age": { "description": "Age of the person", "type": "number", "minimum": 2, "maximum": 200 } }, "required": [ "name", "age" ], "type": "object" } ''; in [ (builtins.validateJsonSchema data1 schema) (builtins.validateJsonSchema data2 schema) ] ``` ```bash $ nix-instantiate --eval --strict test.nix [ false true ] ``` - This is a work in progress and any feedback would be very appreciated! A few open questions I have: - Is it ok to upload the third party dependency into the repository? it's currently being done for cpptoml and nlohmann - Is the proposed semantics ok? or, for example, receiving the schema as a string would be better? - Pending work: - Add docs - Add tests - Improve error messages by returning the validation messages instead of just success=(true/false) Mentions NixOS#5392
- Add https://github.com/pboettch/json-schema-validator as a dependency `json-schema-validator` is a library that uses `nlohmann` internally, which is being used in other components of Nix already `json-schema-validator` is MIT licensed, complies with the latest draft of JSON schema and is the second one with most stars on GitHub - Add a new builtin for validating data with a JSON schema. This builtin receives two arguments: `data` and `schema`, both in Nix format - Demo: ```nix let data1 = { age = 42; }; data2 = { age = 42; name = "Albert"; }; schema = builtins.fromJSON '' { "$schema": "http://json-schema.org/draft-07/schema#", "title": "A person", "properties": { "name": { "description": "Name", "type": "string" }, "age": { "description": "Age of the person", "type": "number", "minimum": 2, "maximum": 200 } }, "required": [ "name", "age" ], "type": "object" } ''; in [ (builtins.validateJsonSchema data1 schema) (builtins.validateJsonSchema data2 schema) ] ``` ```bash $ nix-instantiate --eval --strict test.nix [ false true ] ``` - This is a work in progress and any feedback would be very appreciated! A few open questions I have: - Is it ok to upload the third party dependency into the repository? it's currently being done for cpptoml and nlohmann - Is the proposed semantics ok? or, for example, receiving the schema as a string would be better? - Pending work: - Add docs - Add tests - Improve error messages by returning the validation messages instead of just success=(true/false) Mentions NixOS#5392
- Add https://github.com/pboettch/json-schema-validator as a dependency `json-schema-validator` is a library that uses `nlohmann` internally, which is being used in other components of Nix already `json-schema-validator` is MIT licensed, complies with the latest draft of JSON schema and is the second one with most stars on GitHub - Add a new builtin for validating data with a JSON schema. This builtin receives two arguments: `data` and `schema`, both in Nix format - Demo: ```nix let schema = { title = "A person"; properties = { age = { description = "Age of the person"; type = "number"; minimum = 1; maximum = 200; }; name = { description = "Complete Name for the person"; first.type = "string"; last.type = "string"; required = [ "first" "last" ]; type = "object"; }; }; required = [ "name" "age" ]; type = "object"; }; in builtins.map (builtins.validateJsonSchema schema) [ { } { age = 24; name.first = "Jane"; } { age = 24; name.first = "Jane"; name.last = "Doe"; } ] ``` ```bash $ nix-instantiate --eval --strict test.nix [ { success = false; value = "At '/', required property 'name' not found in object"; } { success = false; value = "At '/name', required property 'last' not found in object"; } { success = true; value = { age = 24; name = { first = "Jane"; last = "Doe"; }; }; } ] ``` - Pending work: - Add docs - Add tests Mentions NixOS#5392
- Add https://github.com/pboettch/json-schema-validator as a dependency `json-schema-validator` is a library that uses `nlohmann` internally, which is being used in other components of Nix already `json-schema-validator` is MIT licensed, complies with the latest draft of JSON schema and is the second one with most stars on GitHub - Add a new builtin for validating data with a JSON schema. This builtin receives two arguments: `data` and `schema`, both in Nix format - Demo: ```nix let schema = { title = "A person"; properties = { age = { description = "Age of the person"; type = "number"; minimum = 1; maximum = 200; }; name = { description = "Complete Name for the person"; first.type = "string"; last.type = "string"; required = [ "first" "last" ]; type = "object"; }; }; required = [ "name" "age" ]; type = "object"; }; in builtins.map (builtins.validateJsonSchema schema) [ { } { age = 24; name.first = "Jane"; } { age = 24; name.first = "Jane"; name.last = "Doe"; } ] ``` ```bash $ nix-instantiate --eval --strict test.nix [ { success = false; value = "At '/', required property 'name' not found in object"; } { success = false; value = "At '/name', required property 'last' not found in object"; } { success = true; value = { age = 24; name = { first = "Jane"; last = "Doe"; }; }; } ] ``` - Pending work: - Add docs - Add tests Mentions NixOS#5392
- Add https://github.com/pboettch/json-schema-validator as a dependency `json-schema-validator` is a library that uses `nlohmann` internally, which is being used in other components of Nix already `json-schema-validator` is MIT licensed, complies with the latest draft of JSON schema and is the second one with most stars on GitHub - Add a new builtin for validating data with a JSON schema. This builtin receives two arguments: `schema` and `data`, both in Nix format - Demo: ```nix let schema = { title = "A person"; properties = { age = { description = "Age of the person"; type = "number"; minimum = 1; maximum = 200; }; name = { description = "Complete Name for the person"; first.type = "string"; last.type = "string"; required = [ "first" "last" ]; type = "object"; }; }; required = [ "name" "age" ]; type = "object"; }; in map (validateAsJSON schema) [ { } { age = 24; name.first = "Jane"; } { age = 24; name.first = "Jane"; name.last = "Doe"; } ] ``` ```bash $ nix-instantiate --eval --strict test.nix [ { success = false; value = "At '/', required property 'name' not found in object"; } { success = false; value = "At '/name', required property 'last' not found in object"; } { success = true; value = { age = 24; name = { first = "Jane"; last = "Doe"; }; }; } ] ``` - This demo was also added to the documentation in a simplified form - Added language tests Mentions NixOS#5392
- Add https://github.com/pboettch/json-schema-validator as a dependency `json-schema-validator` is a library that uses `nlohmann` internally, which is being used in other components of Nix already `json-schema-validator` is MIT licensed, complies with the latest draft of JSON schema and is the second one with most stars on GitHub - Add a new builtin for validating data with a JSON schema. This builtin receives two arguments: `schema` and `data`, both in Nix format - Demo: ```nix let schema = { title = "A person"; properties = { age = { description = "Age of the person"; type = "number"; minimum = 1; maximum = 200; }; name = { description = "Complete Name for the person"; first.type = "string"; last.type = "string"; required = [ "first" "last" ]; type = "object"; }; }; required = [ "name" "age" ]; type = "object"; }; in map (validateAsJSON schema) [ { } { age = 24; name.first = "Jane"; } { age = 24; name.first = "Jane"; name.last = "Doe"; } ] ``` ```bash $ nix-instantiate --eval --strict test.nix [ { success = false; value = "At '/', required property 'name' not found in object"; } { success = false; value = "At '/name', required property 'last' not found in object"; } { success = true; value = { age = 24; name = { first = "Jane"; last = "Doe"; }; }; } ] ``` - This demo was also added to the documentation in a simplified form - Added language tests Mentions NixOS#5392
I marked this as stale due to inactivity. → More info |
Is your feature request related to a problem? Please describe.
nixpkgs
(notnix
!) module system.nixpkgs
module system is not acceptable for my "internal clients".Describe the solution you'd like
openapi
spec or similarbuiltins.jsonSchemaValidate attrset ./path/to/schema.json
to validate my my configDescribe alternatives you've considered
ajv
Additional context
nix
as _config_ language fluidattacks/makes#619There are a few candidate json schema validate C++ libs that I've found on https://json-schema.org/
/cc @kamadorueda
The text was updated successfully, but these errors were encountered: