-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[kotlin-spring][server] Feat: Make it possible to include "HttpServletRequest" or "ServerWebExchange" as a method parameter in controller interfaces and/or implementations #22263
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
base: master
Are you sure you want to change the base?
Conversation
|
If this merge request is considered for merging, I would like to go and implement the same in java-spring generator. There it is now only active by default for reactive. I would like to make it possible to also enable for non-reactive. And honestly I would probably consider making a breaking change there and disable it by default (with the possibility to enable it as is done in this merge request). |
| @@ -0,0 +1,17 @@ | |||
| generatorName: kotlin-spring | |||
| outputDir: samples/server/petstore/kotlin-springboot-include-http-request-context-delegate.yaml | |||
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.
what about naming the folder without .yaml?
also can we add this to the github action config file to test it in the CI moving forward?
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.
definitely will rename the folder. And will add to the action config file. Thanks for the guidance!
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.
I implemented the proposed changes, fixed some compilation errors and added more tests.
I really like the robust test system this project has. So many failing commits before I get everything right... Seems like the major reason why it can accept PRs so quickly without becoming a broken mess.
| assertNotNull(file); | ||
| for (String line : lines) | ||
| assertTrue(file.contains(linearize(line)), "File does not contain line [" + line + "]"); | ||
| assertTrue(file.contains(linearize(line)), "File '" + path + "' does not contain line [" + line + "]"); |
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.
I added this since it simplifies debugging when a unit test fails - it makes it easy to retrieve the file and compare expectation with reality without setting break points, etc.
|
Just a note that I don't plan any more changes unless some suggestions/requests arise from the code review |
|
Same as in my other PR - should create a corresponding issue and link the PR from there? If we expect further discussion, maybe the issue would be a better place? Don't get me wrong - I am in no hurry to get this merged. For my practical use, I can solve this via template overrides, but of course having it eventually merged into the project would make sense to me. This PR maybe looks a bit menacing because of all the added tests? |
This PR enables additional property for kotlin-spring generator. It is called
includeHttpRequestContextand when enabled, it generates additional parameter for controller interfaces and/or implementations. The parameter is eitherrequest: {{javaxPackage}}.servlet.http.HttpServletRequest(if non-reactive) orexchange: org.springframework.web.server.ServerWebExchange(for reactive stack). This parameter is useful for retrieving additional info about the request. The same parameter is generated e.g. by java-spring generator whenreactiveis set totrueThe additional method param also respects all annotation library options available in kotlin-spring generator.
The property defaults to
falseand hence is not a breaking change.Added tests for various possible combinations of
I feel that this is pretty thoroughly tested in the unit tests.
I could not find an issue ticket for exactly this issue, so I went ahead and created the PR without linking anything. I hope it is ok.
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)