Skip to content

Mark Request parameters with default values as required #2149

Closed
@ZachGagnon1

Description

@ZachGagnon1

Describe the bug
Using @RequestParam(required = false) does not work since v2.0.3. It will always show the field as required in the specifications.

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using?
    3.0.4
  • What modules and versions of springdoc-openapi are you using?
    2.0.4
  • Provide with a sample code (HelloController) or Test that reproduces the problem
    java
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "Test")
@RestController
@RequestMapping(value = "/api/v2/test", produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
public class TestController {
  @GetMapping
  public ResponseEntity<Void> getTest(
      @RequestParam(defaultValue = "false", required = false) boolean includeClosed) {
    return ResponseEntity.noContent().build();
  }
}

Expected behavior
Expect the swagger docs to say the field is not required.

Screenshots

V2.0.4

image

V2.0.2

image

No code has been changed between both pictures. Only the version.

Additional context
Using Java 17

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions