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

No documented way to handle Mono/Flux without Webflux #523

Closed
pkubowicz opened this issue Apr 1, 2020 · 7 comments
Closed

No documented way to handle Mono/Flux without Webflux #523

pkubowicz opened this issue Apr 1, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@pkubowicz
Copy link

Describe the bug

  • If you are reporting a bug, please help to speed up problem diagnosis by providing as much information as possible:
  • A clear and concise description of what the bug is: the title of an issue is not enough

To Reproduce
I have Spring MVC (no spring-webflux) application based on Spring Boot 2.2.6 and Springdoc 1.3.0.

My controllers return Flux and Mono.

By default springdoc's swagger-ui page displays Flux response as:

{
  "prefetch": 0
}

When I include org.springdoc:springdoc-openapi-webflux-core:1.3.0 my application fails to start:

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springdoc.core.SpringDocWebMvcConfiguration.openApiResource(SpringDocWebMvcConfiguration.java:60)

The following method did not exist:

    'void org.springdoc.api.OpenApiResource.<init>(java.lang.String, org.springdoc.core.OpenAPIBuilder, org.springdoc.core.AbstractRequestBuilder, org.springdoc.core.GenericResponseBuilder, org.springdoc.core.OperationBuilder, org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping, java.util.Optional, java.util.Optional, org.springdoc.core.SpringDocConfigProperties, java.util.Optional)'

The method's class, org.springdoc.api.OpenApiResource, is available from the following locations:

    jar:file:/home/pkubowicz/.gradle/caches/modules-2/files-2.1/org.springdoc/springdoc-openapi-webflux-core/1.3.0/9254ae87d259128c266dcb64a8fdefefa776fbcb/springdoc-openapi-webflux-core-1.3.0.jar!/org/springdoc/api/OpenApiResource.class
    jar:file:/home/pkubowicz/.gradle/caches/modules-2/files-2.1/org.springdoc/springdoc-openapi-webmvc-core/1.3.0/13bab9bda41e79dbc041c5fb4e564548e7cd0ffd/springdoc-openapi-webmvc-core-1.3.0.jar!/org/springdoc/api/OpenApiResource.class

The work-around is to execute:

SpringDocUtils.getConfig().addResponseWrapperToIgnore(Mono::class.java)
SpringDocUtils.getConfig().addResponseWrapperToIgnore(Flux::class.java)

Expected behavior
This use case should be documented - should springdoc-openapi-webflux-core be used or not used, and if not the documentation should explain how to 'unwrap' Flux and Mono.

@bnasslahsen
Copy link
Contributor

@pkubowicz,

You can have a look at the full documentation:

For spring-mvc you should use, only the springdoc-openapi-webmvc-core.
For spring-webflux, you should use only springdoc-openapi-webflux-core.

You should not ship both modules on the same application.

If you are using Mono and Flux types on you spring-mvc application (which is not natural), using SpringDocUtils might help achieve clean OpenAPI description as you mentionned.

@pkubowicz
Copy link
Author

There is nothing 'unnatural' in using Mono and Flux in Spring MVC. It is officially supported and documented. What is unnatural is that Springdoc considers a supported configuration 'unnatural'.

There is not a single sentence in the documentation supporting what you have written.

I still insist this is a bug (at least a bug in the documentation) and:

This use case should be documented - should springdoc-openapi-webflux-core be used or not used, and if not the documentation should explain how to 'unwrap' Flux and Mono.

@bnasslahsen
Copy link
Contributor

bnasslahsen commented Apr 8, 2020

@pkubowicz,

If you feel the documentation for this part is not clear, please feel free to propose a PR to improve it:

@iyzana
Copy link

iyzana commented Oct 8, 2020

I've run into the same problem.
springdoc-openai-webmvc-core should be able to handle Mono and Flux return types too.

The suggested workaround above is not sufficient for Flux, because just stripping it is not correct, it should be handled as an array.
As a further workaround I had to annotate all endpoints returning a Flux with:

@Operation(responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))

@mvdobrinin
Copy link

BTW Mono and Flux are not supported. See WebFluxSupportConverter and org.springdoc:springdoc-openapi-webflux-core lib.

@mnbattaglia
Copy link

Is this still unsupported? I agree with others that this is a totally valid use case and must be supported

@bnasslahsen bnasslahsen reopened this Aug 25, 2022
bnasslahsen added a commit that referenced this issue Aug 25, 2022
@bnasslahsen
Copy link
Contributor

@mnbattaglia,

There are many workarounds for that.
But as there some demands, it will be added out of the box for the next release.

@bnasslahsen bnasslahsen added the enhancement New feature or request label Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants