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 headers marked as required for Java controllers in mixed projects in 2.0.3 #2187

Closed
petergphillips opened this issue Mar 31, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@petergphillips
Copy link

Similar to #2170 but for request headers instead of request parameters. Tested with 2.0.5-SNAPSHOT and bug still remains.

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 @RequestHeader 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(@RequestHeader(required = false) @Parameter(required = false) final String name) {
        return new Greeting(name);
    }

always generates a required parameter:
Screenshot 2023-03-31 at 10 27 57

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": "header",
                        "name": "name",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],

Expected is

                "parameters": [
                    {
                        "in": "header",
                        "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 OptionalHeaderController {
    @GetMapping("/")
    public Greeting greet(@RequestHeader(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
Copy link
Contributor

@petergphillips,

I have added a better fix. Let me know if this one is better!

@bnasslahsen bnasslahsen added the bug Something isn't working label Apr 1, 2023
@petergphillips
Copy link
Author

Just had a check of our project and looking good 👍 , thanks

@springdoc springdoc locked as resolved and limited conversation to collaborators Apr 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants