Closed Finkman closed 10 months ago
Again after some time, I was playing around with "default" attribute.
"default"
My desired use-case is to define a schema that ships default values and it may be applied on an empty json.
Think about the following schema:
{ "$schema": "http://json-schema.org/draft-07/schema#", "properties": { "huhu": { "type": "number" } }, "type": "object", "default":{ "huhu": 4 } }
and the code:
auto schemaJson = R"( { "$schema": "http://json-schema.org/draft-07/schema#", "title": "A person", "properties": { "huhu": { "type": "number", "minimum": 2, "maximum": 200 } }, "type": "object", "default":{ "huhu": 4 } } )"_json; nlohmann::json test; schema_validator validator{ nullptr, nlohmann::json_schema::default_string_format_check }; validator.set_root_schema( schemaJson ); auto patch = validator.validate( test );
The received patch is null but I'd expect:
patch
null
[ { "op": "add", "path": "/", "value": { "huhu": 4 } } ]
Again after some time, I was playing around with
"default"
attribute.My desired use-case is to define a schema that ships default values and it may be applied on an empty json.
Think about the following schema:
and the code:
The received
patch
isnull
but I'd expect: