Skip to content

Spring Data Rest: RequestBody for POST, PUT, PATCH should be required #1081

Closed
@mathias-ewald

Description

@mathias-ewald

Describe the bug
For POST, PUT, PATCH operations, the generated openapi specification does not mark the request body as required. I believe it should always be required for those operations. Event for PATCH it should just be at least {} rather an empty body.

To Reproduce
Spring Boot: 2.4.1
Springdoc: 1.5.4

Create a regular JPA repository and export it via Spring Data Rest, like:

public interface ProductRepo extends CrudRepository<Product, UUID> {}

Check api-docs.yaml:

$ curl http://localhost:8080/v3/api-docs.yaml
...
paths:
  /products:
    post:
      ...
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Product'
...

Expected behavior
The expected output is

paths:
  /products:
    post:
      ...
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Product'

Additional notes
I have tried overriding the method signature like

	@Override
	<S extends Product> S save(@Param("entity") @RequestBody(required = true) S entity);

but the @RequestBody annotation is ignored.

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