I have a Spring REST controller and two separate GetMappings with the same value but each accepting a different header value for the same header (i.e., one GET method for v1 and one GET method for v2).
@GetMapping(value = "/{id}", headers = { "Accept-version=v1"})
public UserV1 findByIdV1(@PathVariable long id) {
return ...;
}
@GetMapping(value = "/{id}", headers = { "Accept-version=v2"})
public UserV1 findByIdV2(@PathVariable long id) {
return ...;
}
In case the implementation does not change from one version to another, what is the best way to have a single method that can accept either of the header values?
Ideally, the solution would allow me to have different methods for different versions with different implementations to be able to properly document these using OpenAPI. Something similar to the following:
@GetMapping(value = "/{id}", headers = { "Accept-version=v1 OR Accept-version=v2"})
public UserV1 findByIdV1(@PathVariable long id) {
return ...;
}
// Different response, thus need different method to be able to document this.
@GetMapping(value = "/{id}", headers = { "Accept-version=v3"})
public UserV3 findByIdV2(@PathVariable long id) {
return ...;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…