-
Notifications
You must be signed in to change notification settings - Fork 148
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
segmentation fault when attempting to generate from spec that contains allOf
groups
#295
Comments
One side effect I noticed when doing this deliberate manual modification of the swagger json is that SwagGen started ignoring the "myProperty": {
"$ref": "#/components/schemas/MyClass",
"nullable": true
} It would generate a public var myProperty: MyClass Interestingly enough, for specific cases I was able to test the public var myProperty: MyClass? While debugging SwagGen I realized that if I modified this part of the code: SwagGen/Sources/Swagger/Schema/ObjectSchema.swift Lines 44 to 52 in 2b3140b
With this: public extension Property {
var nullable: Bool {
return !required || schema.metadata.nullable
}
} Everything works as expected. Any clue as to why there's this special case handling for when the schema type is a reference (which was committed here: b464a08) @yonaskolb @alephao? 🙏 |
@rogerluan Can you share your swagger file or a minimal example where this issue happen? Maybe I can help BTW, the JSON you posted is not following the swagger specs, nullability should be defined in the object itself. I know, it doesn't make any sense, but that's the spec "myProperty": {
"$ref": "#/components/schemas/MyClass",
"nullable": true
} reference: https://swagger.io/docs/specification/using-ref/
|
Thanks for getting back to this issue @alephao ! 🙇
I was afraid someone would ask for it 😅 because unfortunately I can't share my spec, and as I wasn't able to identify what's wrong, I couldn't recreate it 😬 I know this makes it significantly harder for us to come to a solution 😢 but if you have debugging steps you'd like me to take, I'm happy to try out solutions and help debugging in any way I can! Thanks for that reference about the swagger spec on |
I understand, but I won't be very helpful without something that helps me debugging 😔. Perhaps try searching for a reference cycle in your swagger file, that's what the issue you described sounds like to me. |
So, actually there are cyclic references in my swagger file, but that doesn't seem to be the problem when I'm not using If |
Hey 👋
I've recently spent some time fighting with SwagGen because it would enter a recursion when attempting to parse a given json spec.
After much debugging, I narrowed down the problem to the presence of
allOf
groups in my spec.I read a few issues and PRs in this repo, did some shallow code review in key parts of the code base to try to understand what problem the presence
allOf
was causing, that was triggering the recursion. Some of the issues/PRs: #221, #286, #267, #269, #217, #278. I couldn't figure out why it's crashing (entering a recursion) on my specific spec file 😬 Specially because the sample specs present in this repo do featureallOf
groups, so I don't know what specific configuration in my spec files is causing this particular problem 😞I tested with v4.3.1, v4.4.0, and v4.6.0, all of which caused the same problem (segmentation fault - a recursion somewhere).
If it helps at all, here's the stack trace (click to expand):
Workaround
As a workaround for my specific case, since all of the
allOf
occurrences had a single element in the array, I replaced extracted its$ref
out of theallOf
key, directly in the JSON file, before parsing it using SwagGen. In Ruby, here's the script that worked for me:This workaround is admittedly terrible, but in my specific use case it didn't break anything. Use with caution.
The text was updated successfully, but these errors were encountered: