Skip to content

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

Closed
@eli-berg-maas

Description

@eli-berg-maas

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions