Closed saraawss closed 6 years ago
It seems like a bug in one of the code generation strategies. The way to annotate an optional PathVariable in Spring is to use a Java8 Optional type refering to the following article: https://www.n-k.de/2016/05/optional-path-variables-with-spring-boot-rest-mvc.html
Workaround in your case: Since you‘re using the StubRule you can simply repair the optional=false in the generated code.
Please note: It‘s not a good practice to alter generated code at all. That‘s why we introduced other code generation rules like Spring4ControllerDecoratorRule or Spring4ControllerInterfaceRule. But in your case you decided to use the Spring4ControllerStubRule in which you have to inject your controller logic in the body of the generated controller method stub. So fixing the wrong required=false in the PathVariable is just another altering of the generated stub. ;)
But: it‘s still a bug.
I tried to use Spring4ControllerDecoratorRule or Spring4ControllerInterfaceRule, but still it is generating @PathVariable(required = false).
How to repair the generated code?
@aweisser thnx for pointing out the solution (or let's call it a workaround).
@saraawss there is nothing you can to make your build passing until I implement the workaround. But you can make the issue more clear and provide snippet of your raml :) If I'm not mistaken, you have a raml like this:
/todos:
/{todoId}:
uriParameters:
todoId:
type: number
required: false
get:
responses:
200:
body:
application/json:
type: Todo
which leads to the code you pasted that is not supported by Spring although it compiles.
I'm going to push the fix soon although I'm not very happy with the solution/workaround.
The problematic part is multiple values for @RequestMapping
.
With 1 optional param - there are 2 values, with 2 params - 4 values etc.
Bunch of mapping values might lead to unexpected mapping.
I added a warning in case of more than 1 optional uri param but I will still let a user to shoot himself in a leg if he wants to.
I am facing a problem, I have a raml file and I have to convert to spring java controller file.I added com.phoenixnap.oss pluging in pom file like this,
when I am generating java controller file generating like this,
but @PathVariable(required = false) is getting error spring is not supporting required = false in @PathVariable.
Please advice me what should I do.