Swagger-ui: Maximum call stack size exceeded with multi file circular refs

Created on 17 Jul 2018  Â·  14Comments  Â·  Source: swagger-api/swagger-ui

Describe the bug you're encountering

Who needs description when you got screenshots...

To reproduce...

http://petstore.swagger.io/?url=https://raw.githack.com/heldersepu/hs-scripts/master/swagger/4411/3.json#/default/get_foo

Expected behavior

No red messages please

Screenshots


screen shot 2018-07-17 at 11 59 46 am

Additional context or thoughts

To stack or not to stack, that is the question...

$ref resolution swagger-js bug

Most helpful comment

Circling back to this...
Looks like the latest UI no longer shows the Error in my initial screenshot.
Now the page just goes unresponsive

All 14 comments

This was initially reported @ #4411

The same works fine if the definitions are all in one file:
http://petstore.swagger.io/?url=https://raw.githack.com/heldersepu/hs-scripts/master/swagger/4411/7.json#/default/get_foo

Is this issue being actively investigated? Running into the same thing where we have more than 20 schemas to read in from external files. If not, I will dig in for a fix.

@ryan81g my guess, no it is not on anyones queue...
and the fact that the workaround is as simple as combine all files, this will probably go into a dark dark corner, IF this is important to you, your best bet is to dig and report your findings

I have to say that this is a crucial bug. A circular dependency should not cause such issues. It is not causing the issue when loaded from the same file - so there is already a mechanism that checks for recursion... seems that this test should use absolute paths.

@tflori it might be crucial for you... but the large majority of swagger users do not use multiple files, and those that do, I bet very few have circular refs.

My point is that for the owners this is a low priority/non critical bug...

It is not just crucial because my definitions don't work. It is crucial because you want to be openapi compliant and because of that bug you are not.

Generating the files for a bigger API is not a job of minutes. Having them all in one file is no option because of maintainability.. Of course we can all implement the same code to combine our definitions but in my opinion some one should have a look and see if there is not a simpler solution..

@tflori https://github.com/tflori Here are my thoughts

You want to be openapi compliant and because of that bug you are not.

Your definition can still be compliant regardless of this bug, Yes there
are many features from OAS that are not fully supported in the ui yet

Generating the files for a bigger API is not a job of minutes.

Not sure what to say... No it should not take minutes, this should be
fully automated and take seconds.

Some one should have a look and see if there is not a simpler solution.

Yes I strongly agree, do you have time to look into this?

To keep the close incident #5037 with its issue in the loop.
The actual problem was not the "direct" use of models, but the situation is this:
Model A includes Model B and C. Model B and C include each other, i.e. the relation is in total this:
A->B, A->C, B->C, C->B.

Any news on this?
We decided to split our API in multiple files, to avoid having a big single file, which is unmanageable (4k lines, 120 KiB in size).

But now we just cannot use the swagger-ui to display it, because the refs…

+1

We also have multi-file API definition, but the UI fails to render it because of this.

UPDATE: Also, we experience this with no circular dependencies, but with too many inherit levels (we have a schema which has an ancestry level of 6, using the allOf and $ref keys. Like #4411 mentions.

@OBoehrer : the core issue is simpler: A module can include itself via a $ref. This clearly happens, and is allowed by the spec.

The only problem, is that the UI tries to validate the whole thing, so it will always blow up to infinity.

To fix it, the UI should be validating the first layer, and then validates only the layer that is being displayed. A sort of lazy validation (perhaps with a fixed depth like 5 still).

Circling back to this...
Looks like the latest UI no longer shows the Error in my initial screenshot.
Now the page just goes unresponsive

This is still an issue. I was able to work around it by generating a single JSON using the code generator.

If anybody is interested, here is my Gradle task:

task openApiGenerateJson(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
    generatorName = "openapi"
    inputSpec = "$rootDir/source/index/index.yaml"
    outputDir = "$rootDir/build/generate-resources/json"
}
Was this page helpful?
0 / 5 - 0 ratings