Skip to content

Conversation

@Picazsoo
Copy link
Contributor

@Picazsoo Picazsoo commented Feb 3, 2026

As was promised by me, this is to bring java-spring and kotlin-spring closer to parity functionality-wise. I implemented the change in such a way that it does not impact current users of the java-spring generator at all:

  • for reactive stack, the includeHttpRequestContext defaults to true and thus the ServerWebExchange is present in the methods. (Same as it was before introduction of this flag)
  • for blocking stack, the includeHttpRequestContext defaults to false and thus the HttpServletRequest is NOT present in the methods. (Same as it was before introduction of this flag)

Explicitly setting the flag allows the developer to control the presence/absence of this http request context object.

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.

Summary by cubic

Adds a new includeHttpRequestContext option to the Spring generator to pass the HTTP request context to controller/delegate methods. Defaults to true for reactive (ServerWebExchange) and false for blocking (HttpServletRequest).

  • New Features

    • New additionalProperty: includeHttpRequestContext.
    • Reactive: adds ServerWebExchange parameter by default.
    • Blocking: adds HttpServletRequest when enabled.
    • Parameter is hidden from API docs (and annotated with ApiIgnore for Springfox).
    • Updated templates, docs, and tests to cover defaults and behavior.
    • New sample configs and Spring Boot 3 sample added; CI updated to compile them.
  • Migration

    • Reactive projects will now get a ServerWebExchange parameter by default. To opt out, set includeHttpRequestContext to "false" (e.g., -p includeHttpRequestContext=false or via config file). Blocking projects are unaffected unless enabled.

Written for commit 49fa455. Summary will update on new commits.

…" for reactive and "false" for blocking. Implement tests and add samples to check compilation success.
…Context-to-java-spring-codegen

# Conflicts:
#	.github/workflows/samples-jdk17.yaml
@Picazsoo Picazsoo marked this pull request as ready for review February 4, 2026 08:53
@Picazsoo
Copy link
Contributor Author

Picazsoo commented Feb 4, 2026

I seem unable to edit the title of the PR. If I could, this is what I would change it to:

[java-spring] - add 'includeHttpRequestContext' additional property defaulting to "true" for reactive and "false" for blocking to include ServerWebExchange/HttpServletRequest

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 issues found across 318 files

Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="docs/generators/spring.md">

<violation number="1" location="docs/generators/spring.md:64">
P3: Documentation inconsistency: the description says the default differs for reactive vs blocking, but the Default column lists only `false`, which can mislead reactive users.</violation>
</file>

<file name="docs/generators/java-camel.md">

<violation number="1" location="docs/generators/java-camel.md:71">
P3: The documentation row for includeHttpRequestContext is internally inconsistent: the description says the default is conditional (true for reactive, false for blocking), but the Default column shows a fixed false. For java-camel (inherits SpringCodegen), the default is conditional based on the reactive flag. Update the Default column or description to match actual behavior to avoid misleading users.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/JavaSpring/api.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/JavaSpring/api.mustache:27">
P2: ApiIgnore import is gated by includeHttpRequestContext, but @ApiIgnore is still used for pageable/provide-args even when includeHttpRequestContext is false, leading to missing import compilation errors.</violation>

<violation number="2" location="modules/openapi-generator/src/main/resources/JavaSpring/api.mustache:283">
P2: includeHttpRequestContext on blocking + no params can generate a method signature missing a comma before Pageable/provide-args, leading to invalid Java code.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/JavaSpring/apiDelegate.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/JavaSpring/apiDelegate.mustache:82">
P2: Pagination separator logic still relies on `hasParams` and assumes a reactive exchange parameter always exists. When the request context parameter is optional, this can generate invalid method signatures (missing or leading comma) for pagination-only operations.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

{{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>cookieParams}}{{^-last}},
{{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}},
{{/hasParams}}{{#swagger2AnnotationLibrary}}@Parameter(hidden = true){{/swagger2AnnotationLibrary}}{{#springFoxDocumentationProvider}}@ApiIgnore{{/springFoxDocumentationProvider}} final ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}},
{{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}},
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: includeHttpRequestContext on blocking + no params can generate a method signature missing a comma before Pageable/provide-args, leading to invalid Java code.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/JavaSpring/api.mustache, line 283:

<comment>includeHttpRequestContext on blocking + no params can generate a method signature missing a comma before Pageable/provide-args, leading to invalid Java code.</comment>

<file context>
@@ -270,24 +280,24 @@ public interface {{classname}} {
         {{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>cookieParams}}{{^-last}},
-        {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}},
-        {{/hasParams}}{{#swagger2AnnotationLibrary}}@Parameter(hidden = true){{/swagger2AnnotationLibrary}}{{#springFoxDocumentationProvider}}@ApiIgnore{{/springFoxDocumentationProvider}} final ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}},
+        {{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}},
+        {{/hasParams}}{{#swagger2AnnotationLibrary}}@Parameter(hidden = true){{/swagger2AnnotationLibrary}}{{#springFoxDocumentationProvider}}@ApiIgnore{{/springFoxDocumentationProvider}} final {{#reactive}}ServerWebExchange exchange{{/reactive}}{{^reactive}}HttpServletRequest servletRequest{{/reactive}}{{/includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}},
         {{/hasParams}}{{^hasParams}}{{#reactive}},{{/reactive}}{{/hasParams}}{{#springFoxDocumentationProvider}}@ApiIgnore {{/springFoxDocumentationProvider}}{{#springDocDocumentationProvider}}@ParameterObject {{/springDocDocumentationProvider}}final Pageable pageable{{/vendorExtensions.x-spring-paginated}}{{#vendorExtensions.x-spring-provide-args}}{{#hasParams}},
</file context>
Fix with Cubic

Comment on lines +27 to +29
{{#springFoxDocumentationProvider}}{{#includeHttpRequestContext}}
import springfox.documentation.annotations.ApiIgnore;
{{/includeHttpRequestContext}}{{/springFoxDocumentationProvider}}
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: ApiIgnore import is gated by includeHttpRequestContext, but @ApiIgnore is still used for pageable/provide-args even when includeHttpRequestContext is false, leading to missing import compilation errors.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/JavaSpring/api.mustache, line 27:

<comment>ApiIgnore import is gated by includeHttpRequestContext, but @ApiIgnore is still used for pageable/provide-args even when includeHttpRequestContext is false, leading to missing import compilation errors.</comment>

<file context>
@@ -24,6 +24,9 @@ import io.swagger.v3.oas.annotations.media.ExampleObject;
 {{#swagger1AnnotationLibrary}}
 import io.swagger.annotations.*;
 {{/swagger1AnnotationLibrary}}
+{{#springFoxDocumentationProvider}}{{#includeHttpRequestContext}}
+import springfox.documentation.annotations.ApiIgnore;
+{{/includeHttpRequestContext}}{{/springFoxDocumentationProvider}}
</file context>
Suggested change
{{#springFoxDocumentationProvider}}{{#includeHttpRequestContext}}
import springfox.documentation.annotations.ApiIgnore;
{{/includeHttpRequestContext}}{{/springFoxDocumentationProvider}}
{{#springFoxDocumentationProvider}}
import springfox.documentation.annotations.ApiIgnore;
{{/springFoxDocumentationProvider}}
Fix with Cubic

{{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}},
{{/hasParams}}ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#reactive}}, {{/reactive}}{{/hasParams}}final Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{#unhandledException}} throws Exception{{/unhandledException}}{{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}} {
{{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}},
{{/hasParams}}{{#reactive}}ServerWebExchange exchange{{/reactive}}{{^reactive}}HttpServletRequest servletRequest{{/reactive}}{{/includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#reactive}}, {{/reactive}}{{/hasParams}}final Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{#unhandledException}} throws Exception{{/unhandledException}}{{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}} {
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Pagination separator logic still relies on hasParams and assumes a reactive exchange parameter always exists. When the request context parameter is optional, this can generate invalid method signatures (missing or leading comma) for pagination-only operations.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/JavaSpring/apiDelegate.mustache, line 82:

<comment>Pagination separator logic still relies on `hasParams` and assumes a reactive exchange parameter always exists. When the request context parameter is optional, this can generate invalid method signatures (missing or leading comma) for pagination-only operations.</comment>

<file context>
@@ -71,8 +78,8 @@ public interface {{classname}}Delegate {
-        {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}},
-        {{/hasParams}}ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#reactive}}, {{/reactive}}{{/hasParams}}final Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{#unhandledException}} throws Exception{{/unhandledException}}{{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}} {
+        {{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}},
+        {{/hasParams}}{{#reactive}}ServerWebExchange exchange{{/reactive}}{{^reactive}}HttpServletRequest servletRequest{{/reactive}}{{/includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#reactive}}, {{/reactive}}{{/hasParams}}final Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{#unhandledException}} throws Exception{{/unhandledException}}{{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}} {
         {{>methodBody}}{{! prevent indent}}
     }{{/jdk8-default-interface}}
</file context>
Suggested change
{{/hasParams}}{{#reactive}}ServerWebExchange exchange{{/reactive}}{{^reactive}}HttpServletRequest servletRequest{{/reactive}}{{/includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#reactive}}, {{/reactive}}{{/hasParams}}final Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{#unhandledException}} throws Exception{{/unhandledException}}{{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}} {
{{/hasParams}}{{#reactive}}ServerWebExchange exchange{{/reactive}}{{^reactive}}HttpServletRequest servletRequest{{/reactive}}{{/includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#includeHttpRequestContext}}, {{/includeHttpRequestContext}}{{/hasParams}}final Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{#unhandledException}} throws Exception{{/unhandledException}}{{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}} {
Fix with Cubic

|ignoreAnyOfInEnum|Ignore anyOf keyword in enum| |false|
|implicitHeaders|Skip header parameters in the generated API methods using @ApiImplicitParams annotation.| |false|
|implicitHeadersRegex|Skip header parameters that matches given regex in the generated API methods using @ApiImplicitParams annotation. Note: this parameter is ignored when implicitHeaders=true| |null|
|includeHttpRequestContext|Whether to include HttpServletRequest (blocking) or ServerWebExchange (reactive) as additional parameter in generated methods. Defaults to 'true' for reactive and 'false' for blocking.| |false|
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: Documentation inconsistency: the description says the default differs for reactive vs blocking, but the Default column lists only false, which can mislead reactive users.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At docs/generators/spring.md, line 64:

<comment>Documentation inconsistency: the description says the default differs for reactive vs blocking, but the Default column lists only `false`, which can mislead reactive users.</comment>

<file context>
@@ -61,6 +61,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
 |ignoreAnyOfInEnum|Ignore anyOf keyword in enum| |false|
 |implicitHeaders|Skip header parameters in the generated API methods using @ApiImplicitParams annotation.| |false|
 |implicitHeadersRegex|Skip header parameters that matches given regex in the generated API methods using @ApiImplicitParams annotation. Note: this parameter is ignored when implicitHeaders=true| |null|
+|includeHttpRequestContext|Whether to include HttpServletRequest (blocking) or ServerWebExchange (reactive) as additional parameter in generated methods. Defaults to 'true' for reactive and 'false' for blocking.| |false|
 |interfaceOnly|Whether to generate only API interface stubs without the server files.| |false|
 |invokerPackage|root package for generated code| |org.openapitools.api|
</file context>
Suggested change
|includeHttpRequestContext|Whether to include HttpServletRequest (blocking) or ServerWebExchange (reactive) as additional parameter in generated methods. Defaults to 'true' for reactive and 'false' for blocking.| |false|
|includeHttpRequestContext|Whether to include HttpServletRequest (blocking) or ServerWebExchange (reactive) as additional parameter in generated methods. Defaults to 'true' for reactive and 'false' for blocking.| |true (reactive) / false (blocking)|
Fix with Cubic

|ignoreAnyOfInEnum|Ignore anyOf keyword in enum| |false|
|implicitHeaders|Skip header parameters in the generated API methods using @ApiImplicitParams annotation.| |false|
|implicitHeadersRegex|Skip header parameters that matches given regex in the generated API methods using @ApiImplicitParams annotation. Note: this parameter is ignored when implicitHeaders=true| |null|
|includeHttpRequestContext|Whether to include HttpServletRequest (blocking) or ServerWebExchange (reactive) as additional parameter in generated methods. Defaults to 'true' for reactive and 'false' for blocking.| |false|
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The documentation row for includeHttpRequestContext is internally inconsistent: the description says the default is conditional (true for reactive, false for blocking), but the Default column shows a fixed false. For java-camel (inherits SpringCodegen), the default is conditional based on the reactive flag. Update the Default column or description to match actual behavior to avoid misleading users.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At docs/generators/java-camel.md, line 71:

<comment>The documentation row for includeHttpRequestContext is internally inconsistent: the description says the default is conditional (true for reactive, false for blocking), but the Default column shows a fixed false. For java-camel (inherits SpringCodegen), the default is conditional based on the reactive flag. Update the Default column or description to match actual behavior to avoid misleading users.</comment>

<file context>
@@ -68,6 +68,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
 |ignoreAnyOfInEnum|Ignore anyOf keyword in enum| |false|
 |implicitHeaders|Skip header parameters in the generated API methods using @ApiImplicitParams annotation.| |false|
 |implicitHeadersRegex|Skip header parameters that matches given regex in the generated API methods using @ApiImplicitParams annotation. Note: this parameter is ignored when implicitHeaders=true| |null|
+|includeHttpRequestContext|Whether to include HttpServletRequest (blocking) or ServerWebExchange (reactive) as additional parameter in generated methods. Defaults to 'true' for reactive and 'false' for blocking.| |false|
 |interfaceOnly|Whether to generate only API interface stubs without the server files.| |false|
 |invokerPackage|root package for generated code| |org.openapitools.api|
</file context>
Suggested change
|includeHttpRequestContext|Whether to include HttpServletRequest (blocking) or ServerWebExchange (reactive) as additional parameter in generated methods. Defaults to 'true' for reactive and 'false' for blocking.| |false|
|includeHttpRequestContext|Whether to include HttpServletRequest (blocking) or ServerWebExchange (reactive) as additional parameter in generated methods. Defaults to 'true' for reactive and 'false' for blocking.| |true (reactive) / false (blocking)|
Fix with Cubic

@Picazsoo Picazsoo marked this pull request as draft February 4, 2026 10:31
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.

1 participant