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

Provide intelligent defaults for web flux types Mono and Flux #3354

Closed
dilipkrish opened this issue Jun 29, 2020 · 0 comments
Closed

Provide intelligent defaults for web flux types Mono and Flux #3354

dilipkrish opened this issue Jun 29, 2020 · 0 comments

Comments

@dilipkrish
Copy link
Member

Hi @dilipkrish, just wanted to check before opening an issue.

In Webflux projects, the generated responses and definitions don't seem to be correct when returning a Mono or Flux.

Simple DTO:

public class HelloDto {
    private final String message;
    ...

Controller

        @GetMapping("/hello")
        public Mono<HelloDto> hello() {
            return Mono.fromSupplier(() -> new HelloDto("Hello SpringFox!"));
        }
        
        @GetMapping("/hellos")
        public Flux<HelloDto> hellos() {
            return Flux.just(new HelloDto("Hello SpringFox!"));
        }

Generated definitions:

    "paths": {
        "/functional-hello/hello": {
            "get": {
                "tags": [
                    "functional-hello-world-controller"
                ],
                "summary": "hello",
                "operationId": "helloUsingGET",
                "produces": [
                    "*/*"
                ],
                "responses": {
                    "200": {
                        "description": "Ok",
                        "schema": {
                            "$ref": "#/definitions/Mono«HelloDto»"
                        }
                    },
                    "401": {
                        "description": "Unauthorized"
                    },
                    "403": {
                        "description": "Forbidden"
                    },
                    "404": {
                        "description": "Not Found"
                    }
                }
            }
        },
        "/functional-hello/hellos": {
            "get": {
                "tags": [
                    "functional-hello-world-controller"
                ],
                "summary": "hellos",
                "operationId": "hellosUsingGET",
                "produces": [
                    "*/*"
                ],
                "responses": {
                    "200": {
                        "description": "Ok",
                        "schema": {
                            "$ref": "#/definitions/Flux«HelloDto»"
                        }
                    },
                    "401": {
                        "description": "Unauthorized"
                    },
                    "403": {
                        "description": "Forbidden"
                    },
                    "404": {
                        "description": "Not Found"
                    }
                }
            }
        }
    },
    "definitions": {
        "Flux«HelloDto»": {
            "type": "object",
            "properties": {
                "prefetch": {
                    "type": "integer",
                    "format": "int32"
                }
            },
            "title": "Flux«HelloDto»"
        },
        "HelloDto": {
            "type": "object",
            "properties": {
                "message": {
                    "type": "string"
                }
            },
            "title": "HelloDto"
        },
        "Mono«HelloDto»": {
            "type": "object",
            "title": "Mono«HelloDto»"
        }
    }
}

As you can see /functional-hello/hello has a response with this definition #/definitions/Mono«HelloDto» which is

        "Mono«HelloDto»": {
            "type": "object",
            "title": "Mono«HelloDto»"
        }

Shouldn't it just point at #/definitions/HelloDto which has the actual definition?

        "HelloDto": {
            "type": "object",
            "properties": {
                "message": {
                    "type": "string"
                }
            },
            "title": "HelloDto"
        },

The same happens for Flux. I guess it shoud be a response with and array of #/definitions/HelloDto

What do you think?

BTW I tried explicitly using @ApiResponse annotations and didn't make any change:

@ApiResponses(@ApiResponse(code = 200, message = "Ok", response = HelloDto.class))
...
@ApiResponses(@ApiResponse(code = 200, message = "Ok", response = HelloDto.class, responseContainer = "List"))
...

Originally posted by @svpr3m0 in #3070 (comment)

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

1 participant