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

Offer a switch to not pretty-print large responses in the UI or even not print them at all #4018

Open
dirkschneemann opened this issue Dec 11, 2017 · 24 comments · May be fixed by #9625
Open

Comments

@dirkschneemann
Copy link

Offer a switch to not pretty-print large responses in the UI or even not print them at all but rather send them as a download or similar.

I am aware of issue 1184 which sounds similar. However, the solution mentioned therein names a highlightSizeThreshold parameter which I cannot find anymore in the current version, it probably only existed in swagger-ui 2.x.

Q A
Bug or feature request? Feature Request
Which Swagger/OpenAPI version? 3.0.0
Which Swagger-UI version? 3.6.1
How did you install Swagger-UI? self-hosting the dist folder on NGINX
Which browser & version? any
Which operating system? any

Expected Behavior

Current Behavior

Currently, all responses (at least JSON, GeoJSON and XML) are automatically pretty-printed in the response box with lots of whitespace and linebreaks. Large responses can lead to a huge and inconvenient scrollbar or even make the browser crash.

Possible Solution

Similar as done e.g. in Postman, there could be a button/switch that can be set to Pretty or Raw prior to hitting the execute button.
postman

In addition (nice to have):

  • a Preview button could only display the first x lines of the response
  • another checkbox or button for download would open a Download file dialog box so that the user can save a large response without displaying it in the UI at all

Context

My API returns quite large GeoJSON and SVG responses for some of its endpoints. Typically, when trying out their functionality in swagger-ui via the Try it out button, our users are not interested in reading such responses with the naked eye. What they rather do is copy and paste them into a tool which can display the GeoJSON on a map or render the SVG text into an actual image. We have such tools running locally in our company but similar ones are also freely available online.

Just for copying the response, pretty-printing is not necessary and not doing it would probably increase the browser's performance significantly while keeping the webpage easier navigable due to the smaller scrollbar.

@heldersepu
Copy link
Contributor

We had some discussion about this on Issues #2030 and #3832

I very much like the idea of a button/switch with Pretty or Raw for the response, and of course we should have an option to set a default user preference

The additional Preview I do not see much value, I think that preview should be built-in by default, we should only display X amount of bites of the response, and if the response is large we can add a download link.

@heldersepu
Copy link
Contributor

@dirkschneemann
I'm interested on the SVG portion, Can you provide a link to your api?

Swagger-Ui can display images on the response here is an example:
http://swashbuckletest.azurewebsites.net/swagger/ui/index?filter=Image#/Image/Image_Get
I have only tested with png format, but would love to try SVG

@dirkschneemann
Copy link
Author

Sorry for the late reply, @heldersepu . Our API only runs internally within our network so I cannot share it but it should be easy to come up with a simple example API in any language that serves a static SVG image on request. Feel free to contact me if you need help with this.

@heldersepu
Copy link
Contributor

@dirkschneemann If you can create on simple example it will be awesome, the latest UI should render the image just fine.

@dirkschneemann
Copy link
Author

dirkschneemann commented Jan 3, 2018

Hi @heldersepu , unfortunately I cannot get the SVG rendering to work, using swagger-ui 3.7.0 and 3.8.0.

I created a minimal web application in Python which just returns the SVG code of your example on the /svg endpoint: <svg><circle cx='50' cy='50' r='40' fill='red' /></svg>

The according endpoint definition in the OpenAPI spec looks like this:

  /svg:
    post:
      summary: returns svg
      produces:
        - image/svg
      responses:
        200:
          description: OK

Still, I always get the following error in the response box:
svg

You can see from the developer toolbar at the bottom that the response's content type is correctly set to image/svg.
Besides, the response tab shows that the API return looks good as well:
response

Have you got any idea what could be the reason for this?

@heldersepu
Copy link
Contributor

Interesting enough I did noticed that too...
Already sent a PR to correct it #4063

@dirkschneemann
Copy link
Author

Great, thanks a lot! Hope this will make it into the next release :)

@heldersepu
Copy link
Contributor

If you can take a look at my code...
I could not figure out how to extract the data from a blob, so ended up using an object tag

@dirkschneemann
Copy link
Author

Sorry, I am not enough familiar with this to judge or know about a better way.

@heldersepu
Copy link
Contributor

I was not familiar a month ago...
We have to start somewhere

@shockey shockey mentioned this issue Mar 1, 2018
@icarter09
Copy link

Is this ticket still open? I recently ran into this problem as well. I agree that a button to turn off the "Pretty" option would be nice since Swagger UI seems not to be able to handle large JSON responses.

If the ticket is still open, @heldersepu do you have any insight into the work that has been done on this ticket?

@heldersepu
Copy link
Contributor

@icarter09 Yes ticket still open, as far as I know no work has been done

@shockey
Copy link
Contributor

shockey commented Jun 26, 2018

Just closed #3640 in favor of this - it's worth considering a response size ceiling after which we have the user opt-in to rendering the request at all, be it pretty or raw.

Even raw string rendering starts to break down eventually (probably not far past the 50MB mark 🤔)

@Ovrful
Copy link

Ovrful commented Mar 13, 2020

Is this being resolved any time soon? We are currently facing the same issue.

Best regards.

@amartinez-relpro
Copy link

Just wanted to know if there was a switch created to have a pretty or not pretty JSON responses? In any versions at least. I've also been looking into this but haven't found anything so far.

Thank you

@heldersepu
Copy link
Contributor

@Ovrful and @amartinez-relpro can you provide a link to your API, would be nice to have more data on how others use it

@mkhorton
Copy link

We are also facing this issue with large JSON responses (> 10 MB JSON).

@julioarguello
Copy link

Same issue here. Any workaround? The UI becomes unresponsive with large JSON (catalog export as an instance)

@Vaccano
Copy link

Vaccano commented Oct 28, 2020

Not sure if another "Me Too" comment is helpful, but we are also having this issue. Is there a way to add a filter to not do formatting on the result?

@spyro2000
Copy link

Same here. Freezes on large results.

@RobThree
Copy link

Not sure if another "Me Too" comment is helpful

Same here. I'm facing the same two issues:

@RobThree
Copy link

RobThree commented Feb 2, 2023

Ok, this has bitten me in my behind on several projects now 😤

How about, at least, show a warning? Something along the lines of:

NOTICE: Large numbers over Number.MAX_SAFE_INTEGER were encountered in the response. Numbers shown in the response below may be rounded.

I've made a quick-and-dirty example of how I think it should look:

image

Obviously the message, or the 'design', can be improved and isn't final; I'm just pitching what I think is a decent compromise.

@migoldfinger
Copy link

I originally came here because my big number 2^256 bits. Was translated by the UI into scientific format instead of just showing the raw number. That have led me to various issues that are all closed in favor of this issue here.
Now 7 years have passed. Will this be fixed before I die our should I instruct my successor to keep an eye on the flaw.

@heldersepu
Copy link
Contributor

@migoldfinger & @RobThree this issue if implemented will still not fix your issues with big number, completely unrelated issue

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

Successfully merging a pull request may close this issue.