How to configure Swagger-UI to display results as and when received asynchronously instead of waiting for the complete results?
Asked Answered
H

0

3

I am developing a Rest-API service using Quarkus and for this, I have added OpenAPI (org.eclipse.microprofile.openapi) annotations to generate Swagger-UI. My response can consist of large amounts of data, so I have used the Multi (from SmallRye Mutiny) so as to return the response asynchronously during execution.

Everything works perfectly when a small set of data is returned to Swagger-UI, The problem arises when a large set of data is returned to Swagger-UI then I believe the Swagger-UI waits for the complete response and the browser stops responding and crashes.

However, when I make a request to the same API endpoint using the cURL command, I see that Mutiny Multi is working perfectly and returning the response asynchronously and displaying it on the command line, so nothing breaks in cURL command and everything works perfectly here, even for very large sets of returned data.

Is there something that I can do so as to avoid the crashing of Swagger-UI, like some additional open-api annotation or some custom classes, so as to avoid the Swagger-UI waiting and displaying the results as and when they are received?

Updated things I have tried the following based on other answers:

  1. I found that some answers have mentioned disabling the syntaxHighlight so I tried the same by adding the following lines in my application.yml but it is still not working and swagger-ui hangs:
quarkus:
  swagger-ui:
    always-include: true
    syntaxHighlight:
      activated: false
  http:
    cors: true
    port: 8080
Headlight answered 7/10, 2022 at 8:19 Comment(6)
syntaxHighlight has nothing to do with your problem. I'm not sure if Swagger-UI supports async calls. Might as well look at the OpenAPI Callbacks to see if that helps.Every
@DebarghaRoy Thanks a lot for the response, is there anyway to implement the same using the OpenAPI Annotations in the Quarkus application because I am not creating any yml file, it will be created automatically based on the annotations provided on the Rest API service.Headlight
"large set of data" - how large? There's a known performance issue with large responses. Plus, as @DebarghaRoy correctly noted, Swagger UI does not support async API calls. If your API is entirely async, you should use AsyncAPI and its related tooling instead of OpenAPI.Modernity
@Modernity The amount of events returned by the application depends on user input actually. It can be 1000 events or millions of events. Is there a command that I can use to calculate the size of the sample response via the cURL command for your reference? So currently there is no way to do this using the OpenAPI then. All our applications are on OpenAPI so switching to AsyncAPI would be bit difficult at this time :)Headlight
Perhaps, switching over to Async API would be the best bet but the Java/Spring ecosystem is still evolving around it. But one thing for sure, you should not be using a framework like OpenAPI/AsyncAPI to test with large values. Understand that the primary purpose of them are to provide documentation and a playground sort of thing to explore the APIs, not to be used by user. Input that pushes the response to a large data should be restricted on these documentations.Every
@DebarghaRoy I understand now, I will continue to use the OpenAPI and ensure that we are using it for documentation/reference purposes, however, users can continue to use the cURL command to generate extensive data using the API endpoints.Headlight

© 2022 - 2024 — McMap. All rights reserved.