Skip to content

Request body generated in Swagger YAML for POST/PUT with no body #1200

@Discordia

Description

@Discordia

A requestBody section is generated in swagger YAML even when the POST/PUT do not have a request body. This makes it hard to generated code with swagger-codegen for these routes.

There is no requirement for a POST to have a request body:
https://stackoverflow.com/questions/4191593/is-it-considered-bad-practice-to-perform-http-post-without-entity-body

Steps to Reproduce

  1. Add OpenAPI annotation to Micronaut Application class with a Tag annotation
@OpenAPIDefinition(
        info = @Info(
                title = "Hello Security API",
                version = "1.0",
                description = "Public API for testing Micronat OpenAPI/Swagger for authenticated routes"
        ),
        servers = { @Server(url = "https://example.com") },
        tags = {@Tag(name = "/hello")}
)
public class Application {
    public static void main(String[] args) {
        Micronaut.run(Application.class);
    }
}
  1. Add a controller with the same Tag annotation as in step 1

  2. Add a Post or PUT to the controller without a @Body, only use a path parameter:

    @Post("/authenticated/{helloId}")
    public Single<? extends HttpResponse> authenticated(Authentication authentication, String helloId) {
        return Single.just(HttpResponse.accepted());
    }

Expected Behaviour

The swagger YAML would not have an requestBody section for the POST/PUT.

Actual Behaviour

There is a requestBody section in the YAML for the POST/PUT. See this generated YAML:
https://github.com/Discordia/hello-security/blob/master/hello-security-api-1.0.yml
from this example project:
https://github.com/Discordia/hello-security/

NOTE: the problem also arise when there is no path parameter. Like this:

    @Post("/authenticated")
    public Single<? extends HttpResponse> authenticated(Authentication authentication) {
        return Single.just(HttpResponse.accepted());
    }

Environment Information

  • Operating System: MacOs 10.14.3
  • Micronaut Version: 1.0.4
  • JDK Version: 11.0.1

Example Application

https://github.com/Discordia/hello-security/

Metadata

Metadata

Assignees

Labels

type: improvementA minor improvement to an existing feature

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions