Skip to content

[Java] generation for unsinged integers - #24764

Open
tisis2 wants to merge 7 commits into
OpenAPITools:masterfrom
tisis2:feature/unsignedJava
Open

[Java] generation for unsinged integers#24764
tisis2 wants to merge 7 commits into
OpenAPITools:masterfrom
tisis2:feature/unsignedJava

Conversation

@tisis2

@tisis2 tisis2 commented Aug 24, 2026

Copy link
Copy Markdown

fix #11087

ensure that integer with a given unsigned format (uint32/uint64) or with a given range, get generated with a type that covers their range.

uint32 will be generated as long
uint64 will be generated as BigInteger

ranges will be recognized and fitting data type is chosen depending on minimum/maximun

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.

Java | @bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08) @KannaKim (2026/07)


Summary by cubic

Generates Java types that cover unsigned and bounded integer schemas to prevent overflow. Previously uint32/uint64 and range-limited integers defaulted to signed Integer/Long; now the generator widens to Long or BigInteger based on format or bounds, honoring exclusive limits.

  • Maps uint32 to Long and uint64 to BigInteger; standard int32/int64 remain Integer/Long.

  • Infers the smallest of Integer/Long/BigInteger when min/max are set (honors exclusive bounds).

  • Adds BigInteger to typeMapping and importMapping, and imports java.math.BigInteger; applies to JavaDubboServerCodegen.

  • Keeps isInteger/isLong flags consistent for properties and parameters with widened types; tests cover format and range inference.

  • Migration

    • Regenerate clients/servers; model and parameter types may change from Integer to Long or BigInteger. Update consumers and serializers to accept Long/BigInteger.

Written for commit 95030c0. Summary will update on new commits.

Review in cubic

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

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@tisis2
tisis2 marked this pull request as draft August 24, 2026 09:24
@tisis2
tisis2 marked this pull request as ready for review August 24, 2026 14:22

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

1 issue found and verified against the latest diff

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="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java">

<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java:1980">
P2: For a one-sided integer range, the missing side is unbounded, so `Integer` or `Long` cannot represent every allowed value. Return `BigInteger` whenever either bound is absent, or otherwise evaluate both finite bounds.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment on lines +1980 to +1987
if (Optional.ofNullable(minimum).map(this::fitsInInt).orElse(true)
&& Optional.ofNullable(maximum).map(this::fitsInInt).orElse(true)) {
return typeMapping.get("integer");
} else if (Optional.ofNullable(minimum).map(this::fitsInLong).orElse(true)
&& Optional.ofNullable(maximum).map(this::fitsInLong).orElse(true)) {
return typeMapping.get("long");
}
return typeMapping.get("BigInteger");

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.

P2: For a one-sided integer range, the missing side is unbounded, so Integer or Long cannot represent every allowed value. Return BigInteger whenever either bound is absent, or otherwise evaluate both finite bounds.

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/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java, line 1980:

<comment>For a one-sided integer range, the missing side is unbounded, so `Integer` or `Long` cannot represent every allowed value. Return `BigInteger` whenever either bound is absent, or otherwise evaluate both finite bounds.</comment>

<file context>
@@ -1922,6 +1959,92 @@ public String getSchemaType(Schema p) {
+            maximum = maximum.subtract(BigDecimal.ONE);
+        }
+
+        if (Optional.ofNullable(minimum).map(this::fitsInInt).orElse(true)
+                && Optional.ofNullable(maximum).map(this::fitsInInt).orElse(true)) {
+            return typeMapping.get("integer");
</file context>
Suggested change
if (Optional.ofNullable(minimum).map(this::fitsInInt).orElse(true)
&& Optional.ofNullable(maximum).map(this::fitsInInt).orElse(true)) {
return typeMapping.get("integer");
} else if (Optional.ofNullable(minimum).map(this::fitsInLong).orElse(true)
&& Optional.ofNullable(maximum).map(this::fitsInLong).orElse(true)) {
return typeMapping.get("long");
}
return typeMapping.get("BigInteger");
if (minimum == null || maximum == null) {
return typeMapping.get("BigInteger");
} else if (fitsInInt(minimum) && fitsInInt(maximum)) {
return typeMapping.get("integer");
} else if (fitsInLong(minimum) && fitsInLong(maximum)) {
return typeMapping.get("long");
}
return typeMapping.get("BigInteger");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

wouldn't that mean that every integer without a range that was previously generated as Integer, now would be generated as BigInteger and breaking the generated API usage?

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.

Java OpenApi generator Does not support for unsigned integer data type [Uint32]

1 participant