springdoc / springdoc-openapi

Library for OpenAPI 3 with spring-boot
https://springdoc.org
Apache License 2.0
3.3k stars 500 forks source link

Support for DeferredResult #804

Closed nk-rks closed 4 years ago

nk-rks commented 4 years ago

My server supports asynchronous Servlet processing, so it returns entities of type DeferredResult. DeferredResult is a special type which the Servelet recognizes, and extracts from it the type referenced in the DeferredResult definition.

e.g. The pojo is defined with a member of type DeferredResult, and the actual entity returned by the Servlet to the end-user is the type referenced in the DeferredResult definition, e.g. ActualReturnedEntity.

The problem is that sprindoc documents the DeferredResult as DeferredResultActualReturnedEntity. The expectation is for sprindoc to document the referenced entity: ActualReturnedEntity

There was a similar issue with springfox: https://github.com/springfox/springfox/issues/346

spring-boot: 2.0.3 springdoc-openapi: 1.4.3

Sample server code:

@ApiResponses({@ApiResponse(responseCode = "200")})
public @ResponseBody DeferredResult<OperationResponse<ActualReturnedEntity>> update(
  @RequestBody ActualReturnedEntity entity) throws Exception {
    return null;
}

Actual result:

{
  "responses": {
  "200": {
    "description": "OK",
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/DeferredResultOperationResponseActualReturnedEntity"
        }
    }
  }
}

Expected results:

{
  "responses": {
  "200": {
    "description": "OK",
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/OperationResponseActualReturnedEntity"
        }
    }
  }
}
bnasslahsen commented 4 years ago

Hi @nk-rks,

To get your expected result, you can declare DeferredResult as follow;

static {
    SpringDocUtils.getConfig().addResponseWrapperToIgnore(DeferredResult.class);
}

Starting from the next release, v1.4.4, it will be added out of the box.