Skip to content

All request parameters marked as required for Java controllers in mixed projects in 2.0.3 #2170

Closed
@petergphillips

Description

@petergphillips

Describe the bug
We've got some large projects that we are gradually converting to Kotlin. For those projects we have a mix of Java and Kotlin rest controllers.
Under 2.0.2 in the Java controllers the required parameter of @RequestParam was honoured. Under 2.0.3 / 2.0.4 it appears that this parameter is completely ignored. Furthermore adding in a @Parameter(required = false) annotation has no effect either.
So

    @GetMapping("/")
    public Greeting greet(@RequestParam(required = false) @Parameter(required = false) final String name) {
        return new Greeting(name);
    }

always generates a required parameter:
Screenshot 2023-03-27 at 15 38 22

To Reproduce

  • What version of spring-boot you are using? 3.0.4
  • What modules and versions of springdoc-openapi are you using? springdoc-openapi-starter-webmvc-ui 2.0.4
  • What is the actual and the expected result using OpenAPI Description (yml or json)?
    Actual is
                "parameters": [
                    {
                        "in": "query",
                        "name": "name",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],

Expected is

                "parameters": [
                    {
                        "in": "query",
                        "name": "name",
                        "required": false,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
  • Provide with a sample code (HelloController) or Test that reproduces the problem
    Sample controller is
@RestController
public class OptionalController {
    @GetMapping("/")
    public Greeting greet(@RequestParam(required = false) final String name) {
        return new Greeting(name);
    }
}

Sample project demonstrating the issue (including test case) can be found at https://github.com/petergphillips/springdoc-optional-parameters.

Expected behavior
We weren't expecting the upgrade of spring boot / spring docs to change the OpenAPI documentation for of all our Java controllers. The fix appears to be either to convert all our controllers to Kotlin or setting

springdoc.nullable-request-parameter-enabled = false

The latter change then means that we can't take advantage of the improvement in #2006 in our Kotlin controllers.
It also seems odd that the upgrade should change the behaviour in this way, perhaps the code should take into account whether it is a Java controller and if so then not to look at the nullability of the parameter to determine if it is required.

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