Skip to content

add includeHttpRequestContext additional property defaulting to "true" for reactive and "false" for blocking. Implement tests and add samples to check compilation success.#22890

Closed
Picazsoo wants to merge 12 commits intoOpenAPITools:masterfrom
Picazsoo:feature/add-support-for-includeHttpRequestContext-to-java-spring-codegen
Closed

add includeHttpRequestContext additional property defaulting to "true" for reactive and "false" for blocking. Implement tests and add samples to check compilation success.#22890
Picazsoo wants to merge 12 commits intoOpenAPITools:masterfrom
Picazsoo:feature/add-support-for-includeHttpRequestContext-to-java-spring-codegen

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 for Spring Boot 3 (reactive) and Springfox (blocking); 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 8eeb2a6. 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
Contributor

@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.

@Picazsoo Picazsoo marked this pull request as draft February 4, 2026 10:31
@Picazsoo Picazsoo marked this pull request as ready for review February 6, 2026 07:58
@Picazsoo Picazsoo closed this Feb 6, 2026
Copy link
Contributor

@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.

3 issues found across 132 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="samples/server/petstore/springboot-include-http-request-context/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java">

<violation number="1" location="samples/server/petstore/springboot-include-http-request-context/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java:66">
P2: addNullableArrayItem can throw NullPointerException when nullableArray is JsonNullable.of(null). isPresent() is true for explicit null, so get() returns null and add() fails.</violation>
</file>

<file name="samples/openapi3/server/petstore/springboot-3-include-http-request-context/src/main/java/org/openapitools/RFC3339DateFormat.java">

<violation number="1" location="samples/openapi3/server/petstore/springboot-3-include-http-request-context/src/main/java/org/openapitools/RFC3339DateFormat.java:36">
P2: clone() returns the same instance, violating the clone contract (x.clone() != x) and preventing callers (e.g., frameworks cloning DateFormat) from getting independent copies.</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:287">
P2: Blocking + includeHttpRequestContext + no params yields invalid method invocation because the pageable argument is not separated from servletRequest.</violation>
</file>

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

if (this.nullableArray == null || !this.nullableArray.isPresent()) {
this.nullableArray = JsonNullable.of(new ArrayList<>());
}
this.nullableArray.get().add(nullableArrayItem);
Copy link
Contributor

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

Choose a reason for hiding this comment

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

P2: addNullableArrayItem can throw NullPointerException when nullableArray is JsonNullable.of(null). isPresent() is true for explicit null, so get() returns null and add() fails.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/server/petstore/springboot-include-http-request-context/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java, line 66:

<comment>addNullableArrayItem can throw NullPointerException when nullableArray is JsonNullable.of(null). isPresent() is true for explicit null, so get() returns null and add() fails.</comment>

<file context>
@@ -0,0 +1,223 @@
+    if (this.nullableArray == null || !this.nullableArray.isPresent()) {
+      this.nullableArray = JsonNullable.of(new ArrayList<>());
+    }
+    this.nullableArray.get().add(nullableArrayItem);
+    return this;
+  }
</file context>
Fix with Cubic


@Override
public Object clone() {
return this;
Copy link
Contributor

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

Choose a reason for hiding this comment

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

P2: clone() returns the same instance, violating the clone contract (x.clone() != x) and preventing callers (e.g., frameworks cloning DateFormat) from getting independent copies.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/server/petstore/springboot-3-include-http-request-context/src/main/java/org/openapitools/RFC3339DateFormat.java, line 36:

<comment>clone() returns the same instance, violating the clone contract (x.clone() != x) and preventing callers (e.g., frameworks cloning DateFormat) from getting independent copies.</comment>

<file context>
@@ -0,0 +1,38 @@
+
+  @Override
+  public Object clone() {
+    return this;
+  }
+}
</file context>
Fix with Cubic

){{#unhandledException}} throws Exception{{/unhandledException}}{{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}} {
{{#delegate-method}}
{{^isVoid}}return {{/isVoid}}{{#isVoid}}{{#useResponseEntity}}return {{/useResponseEntity}}{{^useResponseEntity}}{{#reactive}}return {{/reactive}}{{/useResponseEntity}}{{/isVoid}}{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#reactive}}, {{/reactive}}{{/hasParams}}pageable{{/vendorExtensions.x-spring-paginated}});
{{^isVoid}}return {{/isVoid}}{{#isVoid}}{{#useResponseEntity}}return {{/useResponseEntity}}{{^useResponseEntity}}{{#reactive}}return {{/reactive}}{{/useResponseEntity}}{{/isVoid}}{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}}, {{/hasParams}}{{#reactive}}exchange{{/reactive}}{{^reactive}}servletRequest{{/reactive}}{{/includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#reactive}}, {{/reactive}}{{/hasParams}}pageable{{/vendorExtensions.x-spring-paginated}});
Copy link
Contributor

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

Choose a reason for hiding this comment

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

P2: Blocking + includeHttpRequestContext + no params yields invalid method invocation because the pageable argument is not separated from servletRequest.

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 287:

<comment>Blocking + includeHttpRequestContext + no params yields invalid method invocation because the pageable argument is not separated from servletRequest.</comment>

<file context>
@@ -270,24 +277,24 @@ public interface {{classname}} {
     ){{#unhandledException}} throws Exception{{/unhandledException}}{{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}} {
         {{#delegate-method}}
-        {{^isVoid}}return {{/isVoid}}{{#isVoid}}{{#useResponseEntity}}return {{/useResponseEntity}}{{^useResponseEntity}}{{#reactive}}return {{/reactive}}{{/useResponseEntity}}{{/isVoid}}{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#reactive}}, {{/reactive}}{{/hasParams}}pageable{{/vendorExtensions.x-spring-paginated}});
+        {{^isVoid}}return {{/isVoid}}{{#isVoid}}{{#useResponseEntity}}return {{/useResponseEntity}}{{^useResponseEntity}}{{#reactive}}return {{/reactive}}{{/useResponseEntity}}{{/isVoid}}{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}}, {{/hasParams}}{{#reactive}}exchange{{/reactive}}{{^reactive}}servletRequest{{/reactive}}{{/includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#reactive}}, {{/reactive}}{{/hasParams}}pageable{{/vendorExtensions.x-spring-paginated}});
     }
 
</file context>
Fix with Cubic

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