-
Notifications
You must be signed in to change notification settings - Fork 6k
[Java][Spring] Allows for generation of spring controller code using the delegate pattern #4439
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
[Java][Spring] Allows for generation of spring controller code using the delegate pattern #4439
Conversation
|
Some checkstyle things that clearly need to be cleaned up |
|
|
||
| import io.swagger.annotations.*; | ||
| {{#jdk8}} | ||
| import org.springframework.http.HttpStatus; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor suggestion: what about removing the leading spaces?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do!
|
(the Appveyor issue can be ignored) |
|
Fixed. Other than that is this good? |
|
@JLLeitschuh I did some tests using the following commands: Both failed to compile with different error messages (while the generated code without Can you give it a try to see if you can repeat the issue? |
|
You're right, I had some logic that was wrong. |
|
I think this is not a decorator pattern. It looks more like a delegation. |
|
I suppose that you are right, this may be more like delegation. |
|
Well, I think the generated server should at least start without crashing and provide basic "200 OK" endpoints. After that you can add the implementations to swagger-ignore so that they are not overridden by further regen. |
|
So you are saying add an additional flag flag with something like I mean, I can understand the desire but I don't really want to implement this as I have no use for it. |
|
@wing328 Are you looking for anything else on this PR? |
|
@JLLeitschuh I'll do more tests later today. Will keep you posted. |
|
@JLLeitschuh can you rename the class/option xxxDecorator to xxxService ? |
|
@JLLeitschuh Performed more tests and didn't find any issues. Please kindly reply to @cbornet 's suggestions: #4439 (comment) |
|
Yea, but I want to be free to implement it as I want, perhaps I want to create a class that implements two of the controller interfaces? Maybe 4? I don't want another concrete implementation on the classpath that I have to fight spring to get it to not autowire. |
|
I can do the renaming of |
|
Wouldn't |
|
I just changed everything to use the word |
|
I feel service would be better in the Spring world since you would probably use a component annotated by @service |
|
@JLLeitschuh thanks for creating the Petstore sample test with decorator pattern for Java8 but I got compilation errors when running Did you get similar error message when running |
|
|
||
|
|
||
|
|
||
| public Callable<ResponseEntity<Client>> testClientModel(@ApiParam(value = "client model" ,required=true ) @RequestBody Client body) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be being generated. I need to fix this.
|
@wing328 |
|
I just published my changes internally and I'm using the |
|
@JLLeitschuh I did more tests and no longer found issues. Thanks for your contribution. |
|
🎉 🎆 Thank you @wing328 Awesome work on this project. 🎆 🎉 |
|
ETA for 2.2.2 release is Jan/Feb 2017 |
|
No 2.3 ? |
|
@cbornet yup, I also want to release 2.3.0 right after 2.2.2. |
|
I think I may have accidentally forgotten to change the |
| ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaSpring -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l spring -o samples/server/petstore/springboot-delegate-j8 -DdelegatePattern=true,hideGenerationTimestamp=true,java8=true" | ||
|
|
||
| echo "Removing files and folders under samples/server/petstore/springboot-delegate-j8/src/main" | ||
| rm -rf samples/server/petstore/springboot/src/main |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong. Should be the same as the line above.
| ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaSpring -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l spring -o samples/server/petstore/springboot-delegate -DdelegatePattern=true,hideGenerationTimestamp=true" | ||
|
|
||
| echo "Removing files and folders under samples/server/petstore/springboot-delegate/src/main" | ||
| rm -rf samples/server/petstore/springboot/src/main |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong. Should be the same as the line above.
…ttern (swagger-api#4439) * Allows for generation of spring conroller code using the decorator pattern * Change Decorator to Delegate in spring codegen
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates)2.3.0branch for breaking (non-backward compatible) changes.Description of the PR
Adds the ability to generate Spring Server code using the decorator pattern.
Because annotations on interface parameters aren't inherited in java and aren't accessible using reflection spring requires you to have annotations like
@RequestBodyon the concrete class.This means that as a developer you can not just override the methods in your controller, you must also copy the annotations from the
Apiinterface's methods.This fixes the problem by allowing you to generate interfaces that can be implemented and don't require you to copy the annotations from the parent.
Note: It seems like someone didn't generate the samples for one of their changes so there is a bit more noise in those files than this PR should create for consumers.