-
-
Notifications
You must be signed in to change notification settings - Fork 435
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
openapi3: improve internalization ref naming to avoid collisions #955
Conversation
Great changes! One small remark: unless if the project is totally non-US based (so using colour, behaviour, and company), and that's commonly and widely accepted, I would have expected the whole code, issues and PR to mention : Please note, I'm French. It's the kind of error I used to do, so I spotted it |
openapi3/internalize_refs.go
Outdated
// the existing component. | ||
if nameInRoot, found := MatchesComponentInRootDocument(doc, ref); found { | ||
c := *ref.RefPath() | ||
c.Path = nameInRoot |
Check warning
Code scanning / CodeQL
Useless assignment to field
Thanks for pointing out, I had it in the back of my mind but wasn't actively making sure I used the American spelling. I'm English so do this automatically too :D |
23f97c6
to
8f7923c
Compare
8091a0a
to
8e50176
Compare
I think this is very close now, if you'd like to do a full review @fenollp then please go ahead (you may have already as I've been trundling along). I'll do another pass through later this evening too. |
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.
LGTM! Please rebase and use v0.126.0
as the release version in README and we'll be good to go :)
Still got some work to do, the recursive test still fails
This makes resolving references & internalising references determinstic by sorting map for loops by key. Ensures refs are resolved in the same order, depending on the spec this can result in a different (but equal value) internalised spec.
The unmarshal function was removing the .url value
This will be the path at the closest point to the actual definition in the reference chain. Also trim . from the start of paths
9dc5c4f
to
c079cc0
Compare
Excuse my British English
#952
Internalizating references is the way in which a spec which references external files can be shipped as one combined document. The current implementation in DefaultRefNameResolver uses just the final part of the
$ref
. That either being the name of the fixed field component or file name of a whole document.This works in most specs if they maintain documents in the same directory but as soon as you bring child directories the chance of a comflicting file name increasing meaning that two distinct schemas might resolve to the same internalized name. This then goes unnoticed and you unwittingly ship an incorrect spec. Also due to some indeterminisitc logic internalisting the references either of the distinct schemas can be internalized first which leads to an inconistent incorrect spec. (I've refered to schema's here but this appies to all the component fixed field types).
This MR:
DefaultRefNameResolver
has been switched to the new logic, which therefore includes an API breaking change & internalised spec changes.Like before the interlization code doesn't warn if you provide a "name internalizer" that produces colision - this could be added in a follow-up PR. Work would need think out about that could be done.