-
Notifications
You must be signed in to change notification settings - Fork 200
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
@GetMapping and @PathVariable: not detected during parsing #1023
Comments
Thanks for the report. Unfortunately, I'm not able to reproduce the problem. I applied these changes to the project: diff --git a/examples/spring-petclinic/src/main/java/org/springframework/samples/petclinic/web/TestRestController.java b/examples/spring-petclinic/src/main/java/org/springframework/samples/petclinic/web/TestRestController.java
index 5dfdbe19e..3db050b75 100644
--- a/examples/spring-petclinic/src/main/java/org/springframework/samples/petclinic/web/TestRestController.java
+++ b/examples/spring-petclinic/src/main/java/org/springframework/samples/petclinic/web/TestRestController.java
@@ -3,10 +3,8 @@ package org.springframework.samples.petclinic.web;
import java.util.Map;
import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.samples.petclinic.model.Vets;
+import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/test")
@@ -19,4 +17,15 @@ public class TestRestController {
Map<String, String> testDoc(@RequestBody Map<String, String> testBody) {
return testBody;
}
+
+ /**
+ * Echo something.
+ *
+ * @param text the text to echo.
+ * @return the text.
+ */
+ @GetMapping("/echo/{text}")
+ public String echo(@PathVariable("text") String text) {
+ return text;
+ }
}
\ No newline at end of file And both the documentation and resulting "\/test/echo/{text}" : {
"get" : {
"tags" : [ "TestRestController" ],
"description" : "Echo something.",
"operationId" : "echo",
"produces" : [ "application/json", "application/xml" ],
"parameters" : [
...,
{
"name" : "text",
"in" : "path",
"required" : true,
"type" : "string",
"description" : "the text to echo."
}
],
...
}, So in order to debug this, I'm going to need more details on how to reproduce the problem. If you can provide a patch that exposes it, that would be great. |
Hi, thanks for your initial investigation. While trying to reproduce the problem of the missing path variable (which unfortunately I cannot reproduce until now with your test code) I noted another wrong behaviour. It assign to each mapping all the operations. So instead of having only 2 definitions, we have 4. Starting from this code: package org.springframework.samples.petclinic.web;
import java.security.Principal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
@RestController
@RequestMapping(
value="/test",
produces="application/json")
public class TestRestController {
@GetMapping("/echo/{text}")
public String echo(
@PathVariable("text") String text,
@RequestHeader(value="somestring", required=false) String ctf
) {
return text;
}
@DeleteMapping("/widgets/{widgetId}")
public void deleteWidget(
Principal principal,
@PathVariable("widgetId") Long widgetId
) {
// do nothing
}
}`
I got this swagger.json:
```json
"\/test/echo/{text}" : {
"delete" : {
"tags" : [ "TestRestController" ],
"operationId" : "deleteWidget",
"produces" : [ "application/json" ],
"parameters" : [
...
{
"name" : "widgetId",
"in" : "path",
"required" : true,
"type" : "number",
"description" : ""
}
],
"responses" : {
"204" : {
"schema" : {
"description" : "",
"type" : "file"
},
"description" : ""
}
}
},
"get" : {
"tags" : [ "TestRestController" ],
"operationId" : "echo",
"produces" : [ "application/json" ],
"parameters" : [
...
{
"name" : "somestring",
"in" : "header",
"type" : "string",
"description" : ""
},
{
"name" : "text",
"in" : "path",
"required" : true,
"type" : "string",
"description" : ""
}
],
"responses" : {
"200" : {
"schema" : {
"description" : "",
"type" : "string"
},
"description" : ""
}
}
}
},
"\/test/widgets/{widgetId}" : {
"delete" : {
"tags" : [ "TestRestController" ],
"operationId" : "deleteWidget",
"produces" : [ "application/json" ],
"parameters" : [
...
{
"name" : "widgetId",
"in" : "path",
"required" : true,
"type" : "number",
"description" : ""
}
],
"responses" : {
"204" : {
"schema" : {
"description" : "",
"type" : "file"
},
"description" : ""
}
}
},
"get" : {
"tags" : [ "TestRestController" ],
"operationId" : "echo",
"produces" : [ "application/json" ],
"parameters" : [
...
{
"name" : "somestring",
"in" : "header",
"type" : "string",
"description" : ""
},
{
"name" : "text",
"in" : "path",
"required" : true,
"type" : "string",
"description" : ""
}
],
"responses" : {
"200" : {
"schema" : {
"description" : "",
"type" : "string"
},
"description" : ""
}
}
}
}, |
Thanks for the report. Fixed at 00cd32a. If you can provide me a way to reproduce the original reported issue, let me know and I'll re-open. |
Fix is available in 2.13.1. |
Thanks, appreciated :) |
Hi,
using these SpringWeb Framework annotation, the enunciate output format doesn't catch well the path variable arguments.
An example class using @GetMapping (same also with @PostMapping):
And the core enunciate.xml file:
Eventually, the generated swagger.json model regarding that endpoint is (the PathVariable parameter text is missing):
The text was updated successfully, but these errors were encountered: