-
Notifications
You must be signed in to change notification settings - Fork 66
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
Schema#ref does not apply custom configuration options #198
Comments
Ha! I've found a solution. configuration = JSONSchemer::Configuration.new(insert_property_defaults: true)
doc = JSONSchemer.openapi(resolved, configuration:)
content_schema = doc.ref('/components/schemas/MySchema')
content_schema.validate(data) # Succeeds! Thanks! 🦆 |
Hi @ahx, sorry for the delay here. I'm going to reopen this because I think it's an issue that subschemas don't inherit some options. It seems like we need to merge (some of?) the json_schemer/lib/json_schemer/schema.rb Line 78 in 2a239b6
so that they get passed to the ref schema: json_schemer/lib/json_schemer/schema.rb Line 191 in 2a239b6
Let me know if you want to work on a fix! |
Hey David, I agree and I would like to work on a fix. I'll try to work on this. If I don't get back here until the new year, feel free to poke me. |
Yep, also hit this case. The library defaults get inherited.
it took me a moment to figure out that “root” is not “root”, but in the “parsed” loop below it saw the properties, then I came up with the issue. |
@ahx have you had a chance to work on this? I've got another fix to merge/release and I'm hoping to include this as well. |
My approach was to clone the base config and merge it with incoming parameters (see commit). And I wanted to merge the many arguments of Schema#new into one **options. I got a failing test to pass, but that resulted in other things breaking, which I could not get my head around just yet. So I have not accomplished much here. I bet you can find a solution much faster than me. So don't feel held back if you find something working. |
This effectively merges `Schema.new` options with the provided `Configuration` object (or the default global one) so that subschemas validate using the same configuration as the parent schema. `base_uri` and `meta_schema` are still instance variables because they're modified by keywords (that's why they're `attr_accessor`). `resolve_ref` still passes `ref_resolver` and `regexp_resolver` to subschemas to support caching (because the `CachedResolver` instances are created in `Schema`). They could maybe be cached in `Configuration` instead, but that felt like a bigger change. Fixes: #198
Cool, I took a similar approach here: #208 |
Fix released in 2.4.0 |
Hi. What I would like to do is to use
insert_property_defaults: true
for subschemas that are adressed viaSchema#ref
without globally changingJSONSchemer.configuration
.But currently that does not seem to be possible, because
Schema#ref
does not apply the custom local options, but only uses the global configuration and passinginsert_property_defaults: true
toSchema#validate
is not supported.Here is an example:
If you have a suggestion for an API to solve this, I'd be happy to try to create a PR for that.
The text was updated successfully, but these errors were encountered: