Skip to content

@RequestBody not working for @GetMapping endpoints #2775

Closed
@ML-Marco

Description

@ML-Marco
@GetMapping("test")
public void getWithRequestBody(@RequestBody MyClass myClass) {
}

This results in a definition where myClass parameter is defined to appear "in": "query". Correct behavior would be a requestBody block with $ref schema.
Neither org.springframework.web.bind.annotation.RequestBody nor io.swagger.v3.oas.annotations.parameters.RequestBody work.

Actual

"/test": {
      "get": {
        "tags": [
          "test-controller"
        ],
        "operationId": "TestController.getWithRequestBody",
        "parameters": [
          {
            "name": "myClass",
            "in": "query",
            "required": true,
            "schema": {
              "$ref": "#/components/schemas/MyClass"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }

Expected part

"requestBody": {
  "content": {
    "application/json": {
      "schema": {
        "$ref": "#/components/schemas/MyClass"
      }
    }
  },
  "required": true
}

It would be nice if a fix could be backported to the 1.8.x release 🙏.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions