@PathVariable interpreted as a query parameter when annotated on an interface
See original GitHub issueVersions:
springfox 2.9.2 Spring boot web starter 2.0.4
there seems to be a bug where PathVariable gets interpreted as a query parameter. It only seems to occur when using a style where @PathVariable is annotated on the interface (e.g. it works properly when annotated on the controller directly)
Given an interface:
public interface SampleApi {
@RequestMapping(
value = "/test/{var1}",
consumes = {"application/json"},
method = RequestMethod.PUT)
ResponseEntity<Void> test(
@ApiParam(value = "some named var1", required = true)
@PathVariable("var1")
Long var1
);
}
And implementation:
@Controller
public class SampleApiImpl implements SampleApi {
public ResponseEntity<Void> test(Long var1) {
return null;
}
}
Yields:
"/test/{var1}": {
"put": {
"tags": ["sample-api-impl"],
"summary": "test",
"operationId": "testUsingPUT",
"consumes": ["application/json"],
"produces": ["*/*"],
"parameters": [{
"name": "var1",
"in": "query",
"description": "var1",
"required": false,
"type": "integer",
"format": "int64"
}],
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Spring MVC Annotated Controller Interface with @PathVariable
Apparently, when a request pattern is mapped to a method via the @RequestMapping annotation, it is mapped to to the concrete method implementation....
Read more >Spring @RequestParam vs @PathVariable Annotations
@RequestParam and @PathVariable can both be used to extract values from the request URI, but they are a bit different.
Read more >18.2 Creating RESTful services - Spring
The @PathVariable method parameter annotation is used to indicate that a method parameter should be bound to the value of a URI template...
Read more >How to configure query parameters in Spring Controllers
When making a call to a controller, one can customize the behavior and the results that are produced by that endpoint by setting...
Read more >Retrofit 2 - Query and Path parameters example
It specifies whether the argument value to the annotated method parameter is already URL encoded or not. Based on it's value, URL encoding...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This seems to work now?
I tried it using springfox-swagger2 3.0.0-SNAPSHOT together with Spring Boot 2.1.0-RC1 (i.e. Spring 5.1.1-RELEASE).
An interface declaration like:
Results in a swagger definition like:
i.e. “in” equals to “path”
An interface declaration like:
Results in a swagger definition like:
i.e. “in” equals to “query”
Or, am I missing something?
Great that its working out of the box!