json schema support default value #240
Replies: 3 comments
-
No its not supported. The json schema stuff is fairly limited and was mainly to help auto generate a schema for a meta object that can be used when filling out config files for autocomplete/linting. The full schema spec is pretty large so I imagine less than 5% of it is supported. Id be more apt to support a limited spec like https://jsontypedef.com/ if it was more widely used. We could 100% support default constructing the object (or it being passed in as an optional parameter) and get the default values from it if that would be useful. |
Beta Was this translation helpful? Give feedback.
-
I think it would be beneficial to default to default construction, and being able to pass optional parameter with explicit value of the given type(being converted to schema) as default. Something like the following: struct foo {
int a{11};
int b{32};
struct glaze{
static constexpr auto value{ "a", &foo::a, "b", &foo::b };
}
}
void function() {
glz::write_json_schema<foo>(); // would use foo{} as defaults
glz::write_json_schema<foo>(foo{.a=2,.b=3}); // would use the input param defaults
} |
Beta Was this translation helpful? Give feedback.
-
While feasible, I think this has the potential of being confusing, as this allows the meaning of I think it is best to write out default values in the JSON comments until we have a well thought out approach on how this should be handled. I do not think this is a priority, but I'm open to seeing more use cases if this is seen by others as a significant issue. |
Beta Was this translation helpful? Give feedback.
-
Looking at the specification of json schema https://json-schema.org/understanding-json-schema/reference/generic.html I see that the keyword
default
is supported.From
glaze/json/schema.hpp
I am not sure whether declaring default of a schema variable is supported by glaze?
Beta Was this translation helpful? Give feedback.
All reactions