-
Notifications
You must be signed in to change notification settings - Fork 172
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
Deep merge dereferenced keys #163
base: master
Are you sure you want to change the base?
Conversation
ref['$ref'] && ref['$ref'].split('/').last == 'id' | ||
end | ||
ref = idRef || value['anyOf'].first | ||
ref = value['anyOf'].detect {|ref| ref.has_key?('$ref') && ref['$ref'].split('/').last == 'id'} || value['anyOf'].first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't see how this was affected by my change, but there was a test that was failing for me locally. I also wasn't sure how this was working before, unless somewhere we're creating hash objects that have an empty string as the default value.
@pguelpa I don't think deep-merge is expected, I think instead it might just be a matter of changing the schema a bit. Given your example, maybe something more like:
I think something like that might be in order anyway, I tried to read back through specs and stuff and they are difficult to parse, but don't really indicate anything about more complex or deeper stuff here (I think they are fairly naive and just do overwrites unless I'm totally mistaken) @brandur I know you have also spent a lot of time looking at this stuff, could you chime in about your understanding of this behavior? Thanks! |
@geemus - That was what I tried first, but I get a
|
Hmm. Not off the top of my head. Looks like it might be coming from json_schema instead of prmd itself. @pguelpa - could you post the schema you are getting the error from? Just want to make sure we are working from the same source before I dig too deep and/or ask for further help. Hopefully from there we can get to the bottom of this. Thanks! |
@geemus - Sorry for the delay on my response, this is the schema I'm working with is pretty large, but here is a stripped down version which shows what I'm trying to achieve: https://gist.github.com/pguelpa/53362b0a9e49792ac4f9 Basically because of how our validator currently works (based off the top level object rather than a schema in the link) I'm trying to define the |
@geemus I'm running into this a bit myself. The problem with your suggestion above is it seems to assume that the schema at
Note the double $ref to operation, one to include the base schema and one to override the id property. This does not actually seem to work anyways with PRMD because trying to use "$ref" within the context of
In my case we are using json-api and what I want to do is override ONLY the I was not able to use an URL $ref with PRMD so I have a common.js that largely reproduces the json-api schema file:
That definition of attributes works well broadly for the json-api schema but I want my specific resource (e.g. a Business) to basically redefine The way things stand today I basically have to redefine the entire common resource in the specific resource file just to override |
@bdmac good point, thanks for elaborating. Do you know if the fix as proposed here would fix the issue for you? Seems like we would need to at least rebase, but would be good to know if this was on the right track. |
Hi @bdmac, I'm facing the same problem. Did you get any further with this? |
This is a quick and dirty solution to a problem I had when overriding values in our schema. The problem it's trying to solve was this:
Given the
links
snippet:the resulting documentation would not include both the dereferenced object's properties and the override properties. Instead the override properties would replace those from the dereferenced object.
This is a somewhat naive approach and I'd be open to feedback on how to improve it.