Skip to content

requestBody content is empty when using @RequestMapping annotation but is populated for @PostMapping #80

@halvorsone

Description

@halvorsone

We have many existing controller methods in our Spring Boot application that are already annotated with the RequestMapping annotation. When we try using springdoc, the requestBody content for our POST methods is an empty object in the generated /v3/api-docs result.
This:

@RequestMapping(value = "/filter", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public FilterDto filterPost(@RequestBody final FilterDto filter) {
    return filter;
}

results in this:

"/filter": {
    "post": {
        "operationId": "filterPost",
        "requestBody": {
            "content": {}
        },
        "responses": {
            "200": {
                "description": "default response",
                "content": {
                    "application/json;charset=UTF-8": {
                        "schema": {
                            "$ref": "#/components/schemas/FilterDto"
                        }
                    }
                }
            }
        }
    }
}

Eventually, we figured out that switching to use the PostMapping annotation allows the requestBody content to be generated.
This:

@PostMapping("/filter")
@ResponseStatus(value = HttpStatus.OK)
public FilterDto filterPost(@RequestBody final FilterDto filter) {
    return filter;
}

results in this:

"/filter": {
    "post": {
        "operationId": "filterPost",
        "requestBody": {
            "content": {
                "*/*": {
                    "schema": {
                        "$ref": "#/components/schemas/FilterDto"
                    }
                }
            }
        },
        "responses": {
            "200": {
                "description": "default response",
                "content": {
                    "*/*": {
                        "schema": {
                            "$ref": "#/components/schemas/FilterDto"
                        }
                    },
                    "application/json;charset=UTF-8": {
                        "schema": {
                            "$ref": "#/components/schemas/FilterDto"
                        }
                    }
                }
            }
        }
    }
}

We are hoping there is a way to get springdoc to work with our existing RequestMapping POST annotations, so we don't need to change all of our existing code. Is this possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions