Skip to content

[JAVA] Add generic okhttp generator #24355

Open
rar91279 wants to merge 7 commits into
OpenAPITools:masterfrom
rar91279:java-generic-okhttp
Open

[JAVA] Add generic okhttp generator #24355
rar91279 wants to merge 7 commits into
OpenAPITools:masterfrom
rar91279:java-generic-okhttp

Conversation

@rar91279

Copy link
Copy Markdown

OkHttp generator supporting Jackson 2/3, Gson and JSONB as well as JSpecify nullability annotations.

Adressing issue [REQ] [Java] [OkHttp-Gson] Add serialization support for Jackson #20655

PR checklist

  • Read the contribution guidelines.
  • 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.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

rar91279 added 4 commits July 20, 2026 00:36
…s serialisation library as well as JSpecify Nullability assertions.
add configs for the new generic okhttp generator

Execute
  ./mvnw clean package || exit
  ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
  ./bin/utils/export_docs_generators.sh || exit

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

38 issues found across 2935 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="samples/client/others/java/okhttp-oneOf-array/.travis.yml">

<violation number="1" location="samples/client/others/java/okhttp-oneOf-array/.travis.yml:20">
P2: `before_install` makes `./gradlew` executable but `script` calls `gradle test` (system Gradle) instead of `./gradlew test` (the wrapper). This bypasses the pinned Gradle version, risking build inconsistency or failure if the system Gradle is a different version.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/ProgressRequestBody.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/ProgressRequestBody.mustache:58">
P2: Unknown-length uploads never report completion, and empty uploads report no progress at all, because callbacks only occur during sink writes and `bytesWritten == -1` is impossible. Emit a final progress callback from `writeTo()` after the delegated write/flush, including when no bytes were written.</violation>
</file>

<file name="samples/client/petstore/java/okhttp-3.1-duplicated-operationid/git_push.sh">

<violation number="1" location="samples/client/petstore/java/okhttp-3.1-duplicated-operationid/git_push.sh:57">
P2: The script hardcodes `master` as the branch name for both `git pull` and `git push`. Many GitHub repos now use `main` as their default branch (or a custom name via `init.defaultBranch`). When the local branch or remote default doesn't match `master`, these commands will fail with "fatal: couldn't find remote ref master" or "fatal: 'master' does not appear to be a git repository". Consider accepting the branch name as a parameter (e.g., `$5`) or detecting it from the remote to make the script portable.</violation>
</file>

<file name="samples/client/echo_api/java/okhttp/docs/PathApi.md">

<violation number="1" location="samples/client/echo_api/java/okhttp/docs/PathApi.md:58">
P3: The `StringEnumRef` model link in the parameters table resolves to `.md` (a relative self-link) rather than the actual model doc page `StringEnumRef.md`. This produces a broken link for readers navigating the generated docs.</violation>
</file>

<file name="samples/client/petstore/java/okhttp-3.1-duplicated-operationid/.travis.yml">

<violation number="1" location="samples/client/petstore/java/okhttp-3.1-duplicated-operationid/.travis.yml:20">
P2: The `before_install` step makes `gradlew` executable (`chmod a+x ./gradlew`), but the `script` step uses `gradle test` (system-installed Gradle) instead of `./gradlew test` (the wrapper). This is inconsistent — the wrapper setup is wasted effort, and the build may use a different Gradle version than expected. Use `./gradlew test` to match the wrapper setup.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/ProgressResponseBody.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/ProgressResponseBody.mustache:20">
P3: `source()` now memoizes the buffered source, which conflicts with the template contract documented for this OkHttp helper. That mismatch makes the generated behavior harder to reason about and can hide future changes that assume a fresh wrapper per call.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/build.gradle.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/build.gradle.mustache:4">
P3: `apply plugin: 'java'` is applied twice when `sourceFolder` is set — once conditionally at line 3 (`{{#sourceFolder}}` block) and once unconditionally at line 19. The conditional apply on line 3 is redundant: the unconditional apply on line 19 already covers all cases. Remove the duplicate to simplify the template.</violation>
</file>

<file name="samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/model/Query.java">

<violation number="1" location="samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/model/Query.java:172">
P1: Additional properties are not represented as OAS additional properties: Gson serializes this field as a nested `additionalProperties` member and discards unknown top-level response fields. Exclude the holder from default Gson reflection and add the generated TypeAdapter logic that flattens/captures undeclared keys.</violation>
</file>

<file name="samples/client/others/java/okhttp-oneOf/build.sbt">

<violation number="1" location="samples/client/others/java/okhttp-oneOf/build.sbt:1">
P3: `build.sbt` contains only `# TODO` — this is a placeholder with no actual build configuration. The sibling build files (`build.gradle`, `pom.xml`) are fully populated. Also, `#` is not valid SBT comment syntax; SBT uses `//` for single-line comments, so this would cause a parse error if someone tries to use this project with SBT.</violation>
</file>

<file name="samples/client/petstore/java/okhttp-3.1/build.sbt">

<violation number="1" location="samples/client/petstore/java/okhttp-3.1/build.sbt:1">
P1: This file uses `# TODO` but `#` is not valid SBT/Scala comment syntax — SBT will fail to parse the file. Use `// TODO` instead (or remove the file if SBT is not needed for this sample).</violation>
</file>

<file name="samples/client/echo_api/java/okhttp/src/main/java/org/openapitools/client/StringUtil.java">

<violation number="1" location="samples/client/echo_api/java/okhttp/src/main/java/org/openapitools/client/StringUtil.java:51">
P3: Both `join` methods duplicate standard library functionality. `String.join(CharSequence, CharSequence...)` and `String.join(CharSequence, Iterable<? extends CharSequence>)` have been available since Java 8 — the same version this project targets. Consider dropping these custom implementations and using `String.join` directly at call sites, or inlining calls to remove the entire class.</violation>
</file>

<file name="samples/client/others/java/okhttp-streaming/.github/workflows/maven.yml">

<violation number="1" location="samples/client/others/java/okhttp-streaming/.github/workflows/maven.yml:16">
P3: Job name `Build ping some object` looks like a leftover template placeholder —er — "ping some object" doesn't describe the actual work (building and testing this Java client under Java 17/21).</violation>
</file>

<file name="samples/client/others/java/okhttp-oneOf-array/build.sbt">

<violation number="1" location="samples/client/others/java/okhttp-oneOf-array/build.sbt:1">
P3: `# TODO` uses invalid SBT comment syntax — `#` is not recognized as a comment marker in `.sbt` files (SBT uses `//` for line comments like Scala). If this file is meant to be parsed by SBT, `#` will cause a parse error. Replace with `// TODO` or a proper SBT project definition.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/auth/HttpBearerAuth.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/auth/HttpBearerAuth.mustache:23">
P3: Generated API docs describe an `AdditionalHeader`, but this authenticator sends the token in the `Authorization` header. Update both getter and setter Javadocs so client users see the actual header behavior.</violation>
</file>

<file name="samples/client/others/java/okhttp-oneOf-array/src/main/java/org/openapitools/client/ProgressRequestBody.java">

<violation number="1" location="samples/client/others/java/okhttp-oneOf-array/src/main/java/org/openapitools/client/ProgressRequestBody.java:33">
P1: `callback.onUploadProgress()` at line 69 will throw NPE if `callback` is null. While the generated `ApiClient` guards against null before constructing this class, `ProgressRequestBody` is a public API that could be used directly. Add `Objects.requireNonNull(callback)` in the constructor to fail fast and make the contract explicit.</violation>

<violation number="2" location="samples/client/others/java/okhttp-oneOf-array/src/main/java/org/openapitools/client/ProgressRequestBody.java:55">
P2: Method `sink` shares the same name as its parameter (`Sink sink`), creating confusing name shadowing. In `writeTo`, the call `sink(sink)` is ambiguous — the outer `sink` is the method and the inner `sink` is the `BufferedSink` parameter from `writeTo`. Rename the method (e.g., `countingSink`) or the parameter to avoid this collision.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/modelInnerEnum.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/modelInnerEnum.mustache:5">
P1: Gson models with an inline enum fail compilation: `@JsonAdapter` is emitted but its annotation is not imported by `pojo.mustache`. Add the conditional `JsonAdapter` import alongside the existing Gson imports.</violation>

<violation number="2" location="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/modelInnerEnum.mustache:37">
P1: JSON-B models with an inline enum fail compilation because generated `@JsonbValue` has no import. Include `jakarta.json.bind.annotation.JsonbValue` in the JSON-B imports in `pojo.mustache`.</violation>
</file>

<file name="samples/client/others/java/okhttp-streaming/src/main/java/org/openapitools/client/ServerConfiguration.java">

<violation number="1" location="samples/client/others/java/okhttp-streaming/src/main/java/org/openapitools/client/ServerConfiguration.java:55">
P1: Custom values for an unrestricted server variable crash URL construction with `NullPointerException`, because `enumValues` is nullable. Guard it for null (and update `Java/ServerConfiguration.mustache`) so non-enumerated variables can be substituted.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/auth/OAuthOkHttpClient.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/auth/OAuthOkHttpClient.mustache:59">
P2: OAuth token acquisition crashes with `NullPointerException` when the token endpoint omits `Content-Type`, instead of returning an Oltu response. Handle the nullable `ResponseBody.contentType()` before converting it to a string.</violation>
</file>

<file name="samples/client/petstore/java/okhttp-3.1-duplicated-operationid/src/main/java/org/openapitools/client/Pair.java">

<violation number="1" location="samples/client/petstore/java/okhttp-3.1-duplicated-operationid/src/main/java/org/openapitools/client/Pair.java:34">
P3: Observation: The method isValidString(String) currently only checks for null (return arg != null), so empty strings ("") incorrectly appear “valid” despite the method name implying broader validation. This mismatch can cause incorrect assumptions at call sites and maintenance surprises. Recommendation: Either rename the method to reflect its actual behavior (e.g., isNotNull) or implement the intended validation (e.g., check for non-empty with !arg.isEmpty() or trim before checking). Renaming is the least invasive fix if the intent is only a null-check; expand the check if callers rely on a notion of a “valid” string.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/auth/AWS4Auth.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/auth/AWS4Auth.mustache:64">
P1: Combining AWS4 with a query-based auth scheme signs the URL before that scheme adds its query parameter, then sends a different URL; AWS rejects the request. Sign after all query authentication parameters have been applied, using the final request URI.</violation>

<violation number="2" location="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/auth/AWS4Auth.mustache:69">
P1: AWS4 requests with multipart or other binary bodies get a signature for UTF-8-decoded/re-encoded bytes, not the bytes OkHttp sends, so AWS rejects them with a signature mismatch. Preserve and sign the serialized request bytes rather than routing them through `String`.</violation>
</file>

<file name="samples/client/echo_api/java/okhttp/docs/HeaderApi.md">

<violation number="1" location="samples/client/echo_api/java/okhttp/docs/HeaderApi.md:60">
P3: The link target for `StringEnumRef` on this line uses `(.md)` which resolves to a non-existent anchor. Should link to `StringEnumRef.md` — the correct pattern is used elsewhere in the same docs directory (e.g., `BodyApi.md` line 557: `[**StringEnumRef**](StringEnumRef.md)`).</violation>
</file>

<file name="samples/client/petstore/java/okhttp-3.1/.travis.yml">

<violation number="1" location="samples/client/petstore/java/okhttp-3.1/.travis.yml:20">
P2: `before_install` makes `./gradlew` executable but `script` runs `gradle test` (system-installed Gradle) instead of `./gradlew test` (the project wrapper). This bypasses the wrapper's version pinning — the system Gradle version may differ from the one in `gradle/wrapper/gradle-wrapper.properties`, causing inconsistent or broken builds.</violation>
</file>

<file name="samples/client/others/java/okhttp-streaming/build.sbt">

<violation number="1" location="samples/client/others/java/okhttp-streaming/build.sbt:1">
P2: This `build.sbt` file contains only a `# TODO` placeholder with no actual build configuration. Every other Java sample `build.sbt` in the repository has a complete SBT build definition (organization, name, version, dependencies, etc.). SBT users cloning this sample won't be able to build the project with this file.

Either populate the file with a proper SBT build definition (following the pattern in sibling files like `samples/client/others/java/okhttp-gson-streaming/build.sbt`) or remove it if SBT is not intended to be supported.</violation>
</file>

<file name="samples/client/echo_api/java/okhttp/src/main/java/org/openapitools/client/ProgressRequestBody.java">

<violation number="1" location="samples/client/echo_api/java/okhttp/src/main/java/org/openapitools/client/ProgressRequestBody.java:55">
P3: Method and parameter both named `sink` creates confusing read at the call site `sink(sink)` where it's unclear which is the method call and which is the argument. Consider renaming the method to something descriptive like `countingSink` or `wrapWithProgressSink`.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/AbstractOpenApiSchema.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/AbstractOpenApiSchema.mustache:49">
P1: JSON-B requests/responses for oneOf/anyOf models serialize wrapper properties (`actualInstance`, `schemas`, `schemaType`, `nullable`) instead of the wrapped value. Add JSON-B composed-schema serialization/deserialization support (or exclude wrapper getters and adapt the instance) before advertising JSON-B support.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/GzipRequestInterceptor.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/GzipRequestInterceptor.mustache:18">
P3: This adds a second identical interceptor template, creating two maintenance points for one behavior. Consider rendering a shared Mustache partial/template for both OkHttp libraries.</violation>

<violation number="2" location="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/GzipRequestInterceptor.mustache:22">
P3: Zero-length request bodies are gzip-wrapped even though this interceptor must leave empty bodies untouched. Include a `contentLength() == 0` bypass before setting `Content-Encoding`.</violation>

<violation number="3" location="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/GzipRequestInterceptor.mustache:28">
P1: Large request bodies are fully compressed and retained in heap before transmission, so uploads can exhaust client memory instead of streaming. Preserve the gzip `RequestBody` with unknown length (allowing OkHttp to stream/chunk it) rather than calling `forceContentLength`.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/ApiResponse.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/okhttp/ApiResponse.mustache:42">
P2: `entry.getKey().toLowerCase()` in the caseInsensitiveResponseHeaders loop is redundant. The TreeMap already uses `String.CASE_INSENSITIVE_ORDER` as its comparator, which makes key lookups case-insensitive without transforming the stored keys. The extra `.toLowerCase()` adds unnecessary work during response construction, and `String.toLowerCase()` without an explicit `Locale` is locale-sensitive (though HTTP header names are typically ASCII).</violation>
</file>

<file name="samples/client/others/java/okhttp-streaming/src/main/java/org/openapitools/client/ServerVariable.java">

<violation number="1" location="samples/client/others/java/okhttp-streaming/src/main/java/org/openapitools/client/ServerVariable.java:32">
P2: Constructor parameter uses implementation type `HashSet<String>` instead of interface `Set<String>`, forcing callers to pass a `HashSet` specifically. Using `Set<String>` would accept any `Set` implementation (e.g., `TreeSet`, `LinkedHashSet`, unmodifiable wrappers) and follow Java's "program to an interface" convention.</violation>
</file>

<file name="samples/client/others/java/okhttp-oneOf/src/main/java/org/openapitools/client/Configuration.java">

<violation number="1" location="samples/client/others/java/okhttp-oneOf/src/main/java/org/openapitools/client/Configuration.java:38">
P3: File is missing a trailing newline at end of file. The mustache template ends with `}\n` and sibling generated files (e.g., `okhttp-gson-oneOf/Configuration.java`) end with a newline, but this file ends with `}` as the last character. Many POSIX tools and diff pipelines expect text files to end with a newline.</violation>
</file>

<file name="samples/client/others/java/okhttp-streaming/src/main/java/org/openapitools/client/StringUtil.java">

<violation number="1" location="samples/client/others/java/okhttp-streaming/src/main/java/org/openapitools/client/StringUtil.java:51">
P2: The custom `join(String[], String)` and `join(Collection<String>, String)` methods fully duplicate `String.join()` which the JDK has provided since Java 8. Since this project requires Java 11 (`java@11`), these 23 lines of custom implementation carry unnecessary maintenance burden — any future edits risk diverging from the well-tested JDK behaviour. Replace both bodies with direct delegations: `return String.join(separator, array)` and `return String.join(separator, list)` respectively.</violation>
</file>

<file name="samples/client/echo_api/java/okhttp/build.sbt">

<violation number="1" location="samples/client/echo_api/java/okhttp/build.sbt:1">
P2: The generated `build.sbt` is a placeholder with no actual SBT build configuration. The new `okhttp` generator is missing a library-specific `build.sbt.mustache` template (cf. `okhttp-gson/build.sbt.mustache` which defines project name, dependencies, etc.). Add a `build.sbt.mustache` template for the okhttp library or consider removing the file if SBT is not a supported build tool for this generator.</violation>
</file>

<file name="samples/client/others/java/okhttp-streaming/git_push.sh">

<violation number="1" location="samples/client/others/java/okhttp-streaming/git_push.sh:53">
P2: `git pull origin master` always runs after the remote setup block, but hardcodes "master". If the remote uses "main" or another default branch (modern GitHub default), this pull will fail. Suggest using the remote HEAD ref or making the branch configurable.</violation>

<violation number="2" location="samples/client/others/java/okhttp-streaming/git_push.sh:57">
P2: `git push origin master 2>&1 | grep -v 'To https'` pipes through `grep -v`, making the pipeline's exit code grep's, not git push's. If git push fails (e.g., rejected, auth failure), the pipeline still exits 0 (grep found nothing to filter), so the script silently reports success.</violation>
</file>

Note: This PR contains a large number of files. cubic only reviews up to 200 files per PR, so some files may not have been reviewed. cubic prioritizes the most important files to review.

Re-trigger cubic

@@ -0,0 +1 @@
# TODO

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: This file uses # TODO but # is not valid SBT/Scala comment syntax — SBT will fail to parse the file. Use // TODO instead (or remove the file if SBT is not needed for this sample).

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/okhttp-3.1/build.sbt, line 1:

<comment>This file uses `# TODO` but `#` is not valid SBT/Scala comment syntax — SBT will fail to parse the file. Use `// TODO` instead (or remove the file if SBT is not needed for this sample).</comment>

<file context>
@@ -0,0 +1 @@
+# TODO
</file context>
Suggested change
# TODO
// TODO

@JsonValue
{{/isJackson}}
{{#isJsonb}}
@JsonbValue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: JSON-B models with an inline enum fail compilation because generated @JsonbValue has no import. Include jakarta.json.bind.annotation.JsonbValue in the JSON-B imports in pojo.mustache.

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/Java/libraries/okhttp/modelInnerEnum.mustache, line 37:

<comment>JSON-B models with an inline enum fail compilation because generated `@JsonbValue` has no import. Include `jakarta.json.bind.annotation.JsonbValue` in the JSON-B imports in `pojo.mustache`.</comment>

<file context>
@@ -0,0 +1,82 @@
+    @JsonValue
+    {{/isJackson}}
+    {{#isJsonb}}
+    @JsonbValue
+    {{/isJsonb}}
+    public {{{dataType}}} getValue() {
</file context>

* {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
*/
{{#isGson}}
@JsonAdapter({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}.Adapter.class)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: Gson models with an inline enum fail compilation: @JsonAdapter is emitted but its annotation is not imported by pojo.mustache. Add the conditional JsonAdapter import alongside the existing Gson imports.

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/Java/libraries/okhttp/modelInnerEnum.mustache, line 5:

<comment>Gson models with an inline enum fail compilation: `@JsonAdapter` is emitted but its annotation is not imported by `pojo.mustache`. Add the conditional `JsonAdapter` import alongside the existing Gson imports.</comment>

<file context>
@@ -0,0 +1,82 @@
+   * {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
+   */
+  {{#isGson}}
+  @JsonAdapter({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}.Adapter.class)
+  {{/isGson}}
+{{#withXml}}
</file context>

throws ApiException {

SdkHttpFullRequest.Builder requestBuilder =
SdkHttpFullRequest.builder().uri(uri).method(SdkHttpMethod.fromValue(method));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: Combining AWS4 with a query-based auth scheme signs the URL before that scheme adds its query parameter, then sends a different URL; AWS rejects the request. Sign after all query authentication parameters have been applied, using the final request URI.

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/Java/libraries/okhttp/auth/AWS4Auth.mustache, line 64:

<comment>Combining AWS4 with a query-based auth scheme signs the URL before that scheme adds its query parameter, then sends a different URL; AWS rejects the request. Sign after all query authentication parameters have been applied, using the final request URI.</comment>

<file context>
@@ -0,0 +1,105 @@
+      throws ApiException {
+
+    SdkHttpFullRequest.Builder requestBuilder =
+        SdkHttpFullRequest.builder().uri(uri).method(SdkHttpMethod.fromValue(method));
+
+    ContentStreamProvider provider = new ContentStreamProvider() {
</file context>

}

/**
* Gets the token, which together with the scheme, will be sent as the value of the AdditionalHeader.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P3: Generated API docs describe an AdditionalHeader, but this authenticator sends the token in the Authorization header. Update both getter and setter Javadocs so client users see the actual header behavior.

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/Java/libraries/okhttp/auth/HttpBearerAuth.mustache, line 23:

<comment>Generated API docs describe an `AdditionalHeader`, but this authenticator sends the token in the `Authorization` header. Update both getter and setter Javadocs so client users see the actual header behavior.</comment>

<file context>
@@ -0,0 +1,52 @@
+  }
+
+  /**
+   * Gets the token, which together with the scheme, will be sent as the value of the AdditionalHeader.
+   *
+   * @return The bearer token
</file context>

*
* Taken from https://github.com/square/okhttp/issues/350
*/
class GzipRequestInterceptor implements Interceptor {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P3: This adds a second identical interceptor template, creating two maintenance points for one behavior. Consider rendering a shared Mustache partial/template for both OkHttp libraries.

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/Java/libraries/okhttp/GzipRequestInterceptor.mustache, line 18:

<comment>This adds a second identical interceptor template, creating two maintenance points for one behavior. Consider rendering a shared Mustache partial/template for both OkHttp libraries.</comment>

<file context>
@@ -0,0 +1,74 @@
+ *
+ * Taken from https://github.com/square/okhttp/issues/350
+ */
+class GzipRequestInterceptor implements Interceptor {
+    @Override
+    public Response intercept(Chain chain) throws IOException {
</file context>

@@ -0,0 +1,63 @@
/*

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P3: File is missing a trailing newline at end of file. The mustache template ends with }\n and sibling generated files (e.g., okhttp-gson-oneOf/Configuration.java) end with a newline, but this file ends with } as the last character. Many POSIX tools and diff pipelines expect text files to end with a newline.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/others/java/okhttp-oneOf/src/main/java/org/openapitools/client/Configuration.java, line 38:

<comment>File is missing a trailing newline at end of file. The mustache template ends with `}\n` and sibling generated files (e.g., `okhttp-gson-oneOf/Configuration.java`) end with a newline, but this file ends with `}` as the last character. Many POSIX tools and diff pipelines expect text files to end with a newline.</comment>

<file context>
@@ -0,0 +1,63 @@
+      client = defaultApiClient.updateAndGet(val -> {
+        if (val != null) { // changed by another thread
+          return val;
+        }
+        return apiClientFactory.get();
+      });
</file context>

apply plugin: 'idea'
apply plugin: 'eclipse'
{{#sourceFolder}}
apply plugin: 'java'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P3: apply plugin: 'java' is applied twice when sourceFolder is set — once conditionally at line 3 ({{#sourceFolder}} block) and once unconditionally at line 19. The conditional apply on line 3 is redundant: the unconditional apply on line 19 already covers all cases. Remove the duplicate to simplify the template.

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/Java/libraries/okhttp/build.gradle.mustache, line 4:

<comment>`apply plugin: 'java'` is applied twice when `sourceFolder` is set — once conditionally at line 3 (`{{#sourceFolder}}` block) and once unconditionally at line 19. The conditional apply on line 3 is redundant: the unconditional apply on line 19 already covers all cases. Remove the duplicate to simplify the template.</comment>

<file context>
@@ -0,0 +1,138 @@
+apply plugin: 'idea'
+apply plugin: 'eclipse'
+{{#sourceFolder}}
+apply plugin: 'java'
+{{/sourceFolder}}
+
</file context>


jobs:
build:
name: Build ping some object

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P3: Job name Build ping some object looks like a leftover template placeholder —er — "ping some object" doesn't describe the actual work (building and testing this Java client under Java 17/21).

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/others/java/okhttp-streaming/.github/workflows/maven.yml, line 16:

<comment>Job name `Build ping some object` looks like a leftover template placeholder —er — "ping some object" doesn't describe the actual work (building and testing this Java client under Java 17/21).</comment>

<file context>
@@ -0,0 +1,30 @@
+
+jobs:
+  build:
+    name: Build ping some object
+    runs-on: ubuntu-latest
+    strategy:
</file context>
Suggested change
name: Build ping some object
name: Build and test

rar91279 and others added 3 commits July 21, 2026 00:57
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
…rove auth parameter handling. Add missing Gson and JSON-B annotations (from AI review).
@rar91279 rar91279 changed the title Add generic okhttp generator [JAVA] Add generic okhttp generator Jul 20, 2026
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