Skip to content
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

Swagger page failing to load for API endpoints with large JSON responses #9662

Open
VarunReddy1111 opened this issue Mar 4, 2024 · 13 comments

Comments

@VarunReddy1111
Copy link

VarunReddy1111 commented Mar 4, 2024

Example Swagger/OpenAPI definition:
openapi.yaml.zip

I am using Quarkus 3.5.0 (OpenAPI 3.0.3) embedded swagger, When dealing with API endpoints, due to large json response that gets populated in example schema section, the UI is crashing. Attaching the openapi definition. Please let me know if any other information is needed.

image

@glowcloud
Copy link
Contributor

glowcloud commented Mar 5, 2024

Related to #3832

The current known workaround is using this setting:

    syntaxHighlight: {
      activated: false,
      theme: "agate"
    }

It seems like it's not enough in this case - the examples will sometimes load after hanging and sometimes still crash the browser.

There is a PR #9625 addressing this issue, I'll take a look at it next.

@glowcloud
Copy link
Contributor

I will be tracking this further in the related issue #3832.

@heldersepu
Copy link
Contributor

heldersepu commented Mar 7, 2024

NO PR #9625 is not addressing this issue
... and this issue is not related to issue #3832

@heldersepu
Copy link
Contributor

heldersepu commented Mar 7, 2024

The schema in the given openapi.yaml.zip is massive!!
once unpacked that is 2.5MB

this is not about "large JSON responses" heck with that schema the UI crashes even without making any requests

Just expanding the "put_api_agm_disease_annotation" crashes, there was no large response because we did not make any request, the [Try it out] button did not even show, you can test it here:
https://petstore.swagger.io/?docExpansion=None&defaultModelsExpandDepth=None&url=https://gist.githubusercontent.com/heldersepu/ab37902d2f687d2c71aa1b36bb72ee48/raw/0f68906074dfbad5528a81132ae7975b6bf2ef75/openapi.yml#/CRUD%20-%20AGM%20Disease%20Annotations

the problem on issue 3832 is an actual large response from the API, in that case the syntax highlighter takes too long to render and browsers crashes

@VarunReddy1111
Copy link
Author

Thank you for the response @heldersepu. Yes, the swagger ui crashing while expanding the end point. Is this because of massive openAPI file? and do you have any resolution for this issue?

@heldersepu
Copy link
Contributor

heldersepu commented Mar 7, 2024

This issue is closer in relation to issue 4411, see my comment there:

#4411 (comment)

The expansion of a truly complex object creates a LOT of code, the browser will ultimately crash and burn

The problem presented on this issue I would put this schema on the "huge and extra complex" category, it has 84962 lines, that is mind blowing for an API description ... everyone is moving toward micro-service architectures but it looks like this is the opposite movement

@heldersepu
Copy link
Contributor

heldersepu commented Mar 7, 2024

Thank you for the response @heldersepu. Yes, the swagger ui crashing while expanding the end point. Is this because of massive openAPI file? and do you have any resolution for this issue?

Sorry but no resolution or even a workaround, and no the syntaxHighlight deactivation is not a workaround for this ...
if that is the schema your team wants to use, then Swagger-UI is not the tool for you...

have you heard that saying:
"when you are a hammer everything is a nail"

quite often we developers fall in that trap...
yes we can use a hammer to cut down a tree, but that is not the right tool.

My recommendation: refactor your code, move to a micro-service architecture

@heldersepu
Copy link
Contributor

If we want to keep this open for someone to investigate ...
here is small schema but with nested definitions that causes the same crash:

https://petstore.swagger.io/?url=https://raw.githubusercontent.com/heldersepu/hs-scripts/master/swagger/NestedSwag.json

@glowcloud
Copy link
Contributor

Hi there,

I started tracking this as a related issue, because the changes to HighlightCode in #9625 also affect the rendering of example values and with those changes I was able to expand the operations, although after some seconds of waiting. I looked at the issue of rendering such large values, whether for server responses or just example responses, as one.

In the case of this specification, there are further issues with out of memory crashes when using try it out, changing from example to schema or expanding more definitions, which I’m investigating. As I mentioned in #3832 (comment), this might be related to doing many operations on immutable values, in which case it might be a separate issue.

I can also confirm that your example @heldersepu https://raw.githubusercontent.com/heldersepu/hs-scripts/master/swagger/NestedSwag.json will also be possible to expand with the PR changes, but the memory usage will be high:

Screenshot 2024-03-07 at 16 21 47

@heldersepu
Copy link
Contributor

Yes the changes to HighlightCode offer some improvement to the examples, but the examples are significantly more complex unlike the responses from the API that we just show what we receive, the nested examples the entire tree is created, that will cause some serious memory consumption...

but back to my point: this issue is not related to issue #3832
I see no reason to close this issue

@glowcloud try expanding the models in that nested example see if that helped there

@glowcloud
Copy link
Contributor

I can expand the models

Screenshot 2024-03-08 at 08 41 03

but opening more of them (as in, not the nested ones in the screenshot, just separate models) will cause a crash at some point. Seems like it's also a memory related crash.

@char0n
Copy link
Member

char0n commented Mar 8, 2024

Reopening this as it's confirmed now that this is unrelated to #3832

@char0n char0n reopened this Mar 8, 2024
@char0n
Copy link
Member

char0n commented Mar 8, 2024

The swagger-client either creates unnecessary nesting instead of stopping on first detected cycle. It might also be the case that the resolver is functioning OK, but then the SwaggerUI is doing it's additional primitive "dereferencing" itself which might again introduce cycles.

@glowcloud confirmed that the definition resolved immediately, so the probably candidate is the primitive "dereferencing" inside the SwaggerUI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants