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

Springdocs doesn't detect header declarations in class level @RequestMappings #1073

Closed
eli-berg-maas opened this issue Feb 22, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@eli-berg-maas
Copy link

Our API uses a number of controllers coded along these lines:

@RestController
@RequestMapping(path = "/registration", headers = {"userId", "registrationId"})
public class RegistrationController {
    
    @Operation(summary = "Save the registration")
    @ApiResponses(...various responses...)
    @PostMapping()
    public ResponseEntity saveRegistration(@RequestBody Registration registration) {
        ... registrationsaving code ...
    }

    @Operation(summary = "Update field of registration")
    @ApiResponses(...various responses...)
    @PostMapping(value = "/{field_name}")
    @Trace(dispatcher = true, metricName = "/{field_name}")
    public ResponseEntity updateRegistrationField(@PathVariable("field_name") String fieldName, 
                                                  @RequestBody Object fieldValue,
                                                  @RequestHeader(value = "version") String version) {
        ... update the registration field ...
    }

    ... many more endpoints ...
}

This class level headers are for logging, but differ from controller to controller, so they're not truly global. The ones declared as parameters have some functional effect.

We are in the process of porting from SpringFox Swagger 2 to Spring Docs OpenAPI 3, and so far everything has gone extremely smoothly except that the class level headers declared in the controllers, which aren't being detected. They don't show up in our api-docs json, and they don't show up in Swagger-ui, meaning that we can't debug the endpoints, as the headers actually are mandatory.

I was hoping that there was some setting I missed that would cause these to be detected, or, barring that, you would have a workaround that would allow me to managed this from OpenAPI config. That said, if there isn't a setting I've missed stopping these from being detected, there would seem to be a bug in how SpringDocs is processing the @RequestMapping annotations.

@bnasslahsen
Copy link
Contributor

@eli-berg-maas,

I have added a fix for that.
You can test it using the latest snapshot.

This was referenced Mar 16, 2021
@bnasslahsen bnasslahsen added the bug Something isn't working label Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants