-
Notifications
You must be signed in to change notification settings - Fork 100
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
Circular references cause stack overflow #3
Comments
Hmm intersting. So, this is where we actually append the current schema ref: https://github.com/go-openapi/spec/blob/master/expander.go#L438 The snippet above isn't actually appending the current schema ref, it is just checking to make sure that the schema hasn't already been dereferenced. fmt.Println(pRefs) // #/definitions/Store,#/definitions/Category,
fmt.Println(currentSchema.Ref.String()+",") // #/definitions/Book, So really what is happening here, is pRefs doesn't contain #/definitions/Book, therefore this is the first time we are encountering it, so try to dereference it. After that, then append currentSchema.Ref.String()// #/definitions/Book to the parentRefs array. Does that make sense? I am going to investigate this more though, as you could be correct I might be doing the append too late. |
Yes, it makes sense indeed. I also looked into it a bit further using the following test. func TestIssue3(t *testing.T) {
doc, err := jsonDoc("fixtures/expansion/issue3.json")
assert.NoError(t, err)
spec := new(Swagger)
err = json.Unmarshal(doc, spec)
assert.NoError(t, err)
err = ExpandSpec(spec)
assert.NoError(t, err)
} See issue3.json gist for the spec. A bit of logging reveals that expanding
|
Actually, looking at the logs properly again it seems more of an issue that the schema for is not passed properly when comes to expanding Edit: I don't know the internals that well but something else in the logs I wondered about: whereas the |
After digging a bit deeper I think I now at least know why it's not breaking the circular expansion. When expanding the
When expanding
As a result the following statement from if schema.Ref.String() != "" {
...
parentRefs = append(parentRefs, currentSchema.Ref.String())
...
} So my best guess at this point is that the |
Just to throw in one more observation. After running it again and
However, since it's now expanding in a different order and getting stuck within expanding |
Interesting, I am going to take a look at this more tomorrow. |
@pytlesk4 did you have a chance to look at it? I might also have some time later this week to try getting my head around it. But please let me know if there's anything specific I can help with. |
@christianklotz trying to make time for it, just busy with other things at the moment. By all means if you get to it, and can figure it out, that would be awesome. Just let me know, and I will do the same. Also, don't hesitate to ask any questions: https://slackin.goswagger.io/! |
Looking at this today, unless you have started on this @christianklotz ? |
@christianklotz Fixed, need to update the tests, but will be pushing this soon! |
@pytlesk4 just wanted to say thanks for fixing this. Really appreciated! |
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
After coming across the same or similar issue to go-swagger #537 I looked into it a little further. If I understand it correctly
expander.go
has a check for circular references.However it seems like it's appending the current schema too late. I tested it with the swagger definition below which has a
Book
definition with relatedBook
items, and the overall definition structure isStore > Category > Book
.It only appears to happen if the circular reference a few levels deep. For instance, if the store has books directly without categories, it's fine.
Swagger Definition
The text was updated successfully, but these errors were encountered: