Skip to content

Conversation

@Picazsoo
Copy link
Contributor

@Picazsoo Picazsoo commented Oct 31, 2025

This PR enables additional property for kotlin-spring generator. It is called includeHttpRequestContext and when enabled, it generates additional parameter for controller interfaces and/or implementations. The parameter is either request: {{javaxPackage}}.servlet.http.HttpServletRequest (if non-reactive) or exchange: 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 when reactive is set to true

The additional method param also respects all annotation library options available in kotlin-spring generator.

The property defaults to false and hence is not a breaking change.

Added tests for various possible combinations of

  • controller implementation / interfaces / delegate
  • reactive / non reactive
  • annotation library swagger1 / swagger2 / none

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

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request. - tagging: @karismann, @Zomzog, @andrewemery, @4brunu, @yutaka0m, @stefankoppier, @e5l

@Picazsoo
Copy link
Contributor Author

Picazsoo commented Nov 2, 2025

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
Copy link
Member

@wing328 wing328 Nov 3, 2025

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?

Copy link
Contributor Author

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!

Copy link
Contributor Author

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 + "]");
Copy link
Contributor Author

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.

@Picazsoo
Copy link
Contributor Author

Picazsoo commented Nov 3, 2025

Just a note that I don't plan any more changes unless some suggestions/requests arise from the code review

@Picazsoo
Copy link
Contributor Author

Picazsoo commented Nov 4, 2025

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?

@Picazsoo Picazsoo changed the title kotlin-spring][server] Feat: Make it possible to include "HttpServletRequest" or "ServerWebExchange" as a method parameter in controller interfaces and/or implementations [kotlin-spring][server] Feat: Make it possible to include "HttpServletRequest" or "ServerWebExchange" as a method parameter in controller interfaces and/or implementations Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants