Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
petergphillips opened this issue Mar 27, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@petergphillips
Copy link

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.

bnasslahsen added a commit that referenced this issue Mar 30, 2023
@bnasslahsen
Copy link
Contributor

@petergphillips,

i have added a fix for it.
You can test it with the latest SNAPSHOT and let us know.

@petergphillips
Copy link
Author

Hi @bnasslahsen thanks for the quick fix. I've tested the latest snapshot and it fixes the bug, but then discovered that the issue also exists for request headers too so have raised #2187.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants