Skip to content

Type annotation on request body model erroneously results in parameter annotation as well #380

@vvanpo

Description

@vvanpo

I've pushed a failing test case to illustrate this behaviour: master...vvanpo:openapi-processor-spring:master

When running this, the test output shows the following diff:

/.../openapi-processor-spring/build/resources/testInt/tests/params-request-body-annotation/outputs/api/Api.java
--- /.../openapi-processor-spring/build/resources/testInt/tests/params-request-body-annotation/outputs/api/Api.java
+++ /.../generated/api/Api.java
@@ -1,8 +1,9 @@
 package generated.api;
 
 import generated.model.Book;
 import generated.support.Generated;
+import lombok.Builder;
 import org.springframework.http.HttpStatus;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.ResponseStatus;
@@ -11,7 +12,7 @@
 public interface Api {
 
     @ResponseStatus(HttpStatus.CREATED)
     @PostMapping(path = "/book", consumes = {"application/json"}, produces = {"application/json"})
-    Book postBook(@RequestBody Book body);
+    Book postBook(@RequestBody @Builder Book body);
 
 }
/.../openapi-processor-spring/build/resources/testInt/tests/params-request-body-annotation/outputs/api/Api.java
--- /.../openapi-processor-spring/build/resources/testInt/tests/params-request-body-annotation/outputs/api/Api.java
+++ /.../generated/api/Api.java
@@ -1,8 +1,9 @@
 package generated.api;
 
 import generated.model.Book;
 import generated.support.Generated;
+import lombok.Builder;
 import org.springframework.http.HttpStatus;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.ResponseStatus;
@@ -11,7 +12,7 @@
 public interface Api {
 
     @ResponseStatus(HttpStatus.CREATED)
     @PostMapping(path = "/book", consumes = {"application/json"}, produces = {"application/json"})
-    Book postBook(@RequestBody Book body);
+    Book postBook(@RequestBody @Builder Book body);
 
 }

Basically, annotating a model that also happens to be a request body results in an unwanted parameter annotation, that in this case breaks because lombok.Builder is not a valid parameter annotation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions