diff --git a/docs/generators/groovy.md b/docs/generators/groovy.md
index e8d04d05ce81..29fdb38e7fcb 100644
--- a/docs/generators/groovy.md
+++ b/docs/generators/groovy.md
@@ -93,6 +93,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -122,6 +123,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
- ArrayList
+- BigInteger
- Boolean
- Date
- Double
diff --git a/docs/generators/java-camel.md b/docs/generators/java-camel.md
index 10213f64b802..64f66ea62142 100644
--- a/docs/generators/java-camel.md
+++ b/docs/generators/java-camel.md
@@ -170,6 +170,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -198,6 +199,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/java-helidon-client.md b/docs/generators/java-helidon-client.md
index 8a87fada3826..53f4b1a109db 100644
--- a/docs/generators/java-helidon-client.md
+++ b/docs/generators/java-helidon-client.md
@@ -93,6 +93,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -121,6 +122,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/java-helidon-server.md b/docs/generators/java-helidon-server.md
index 1527e389ad6a..d7e31769d5bb 100644
--- a/docs/generators/java-helidon-server.md
+++ b/docs/generators/java-helidon-server.md
@@ -95,6 +95,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -123,6 +124,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/java-inflector.md b/docs/generators/java-inflector.md
index 8053570ee1c7..5f1acf2dd18c 100644
--- a/docs/generators/java-inflector.md
+++ b/docs/generators/java-inflector.md
@@ -95,6 +95,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -123,6 +124,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/java-micronaut-client.md b/docs/generators/java-micronaut-client.md
index e0075fa21ce8..d294d83d950e 100644
--- a/docs/generators/java-micronaut-client.md
+++ b/docs/generators/java-micronaut-client.md
@@ -116,6 +116,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -144,6 +145,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/java-micronaut-server.md b/docs/generators/java-micronaut-server.md
index 84e247ddb86a..09f5a8fbade1 100644
--- a/docs/generators/java-micronaut-server.md
+++ b/docs/generators/java-micronaut-server.md
@@ -115,6 +115,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|CompletedFileUpload|io.micronaut.http.multipart.CompletedFileUpload|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
@@ -144,6 +145,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/java-microprofile.md b/docs/generators/java-microprofile.md
index 2dfaf5e0bcf4..6658ae0b8664 100644
--- a/docs/generators/java-microprofile.md
+++ b/docs/generators/java-microprofile.md
@@ -139,6 +139,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -167,6 +168,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/java-msf4j.md b/docs/generators/java-msf4j.md
index 5a450378071a..fb5b4ea386ac 100644
--- a/docs/generators/java-msf4j.md
+++ b/docs/generators/java-msf4j.md
@@ -101,6 +101,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -129,6 +130,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/java-pkmst.md b/docs/generators/java-pkmst.md
index d4fbfd9ad901..9b18dc75848d 100644
--- a/docs/generators/java-pkmst.md
+++ b/docs/generators/java-pkmst.md
@@ -102,6 +102,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -130,6 +131,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/java-play-framework.md b/docs/generators/java-play-framework.md
index d9948ceb7ebc..4f90f8298a2f 100644
--- a/docs/generators/java-play-framework.md
+++ b/docs/generators/java-play-framework.md
@@ -105,6 +105,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -133,6 +134,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/java-undertow-server.md b/docs/generators/java-undertow-server.md
index 9ffaffc0f561..0bdde0db0a5f 100644
--- a/docs/generators/java-undertow-server.md
+++ b/docs/generators/java-undertow-server.md
@@ -95,6 +95,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -123,6 +124,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/java-vertx-web.md b/docs/generators/java-vertx-web.md
index 99befa626be4..9966540f2963 100644
--- a/docs/generators/java-vertx-web.md
+++ b/docs/generators/java-vertx-web.md
@@ -96,6 +96,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -124,6 +125,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/java-vertx.md b/docs/generators/java-vertx.md
index 8764f3610561..2c5acbaed309 100644
--- a/docs/generators/java-vertx.md
+++ b/docs/generators/java-vertx.md
@@ -98,6 +98,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -126,6 +127,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/java-wiremock.md b/docs/generators/java-wiremock.md
index 80a270223a72..08cb85281523 100644
--- a/docs/generators/java-wiremock.md
+++ b/docs/generators/java-wiremock.md
@@ -95,6 +95,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -123,6 +124,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/java.md b/docs/generators/java.md
index 6740780102b9..2b1f9d940eff 100644
--- a/docs/generators/java.md
+++ b/docs/generators/java.md
@@ -139,6 +139,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -167,6 +168,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/jaxrs-cxf-cdi.md b/docs/generators/jaxrs-cxf-cdi.md
index d7be87c2a622..a20c7b1d6225 100644
--- a/docs/generators/jaxrs-cxf-cdi.md
+++ b/docs/generators/jaxrs-cxf-cdi.md
@@ -114,6 +114,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -142,6 +143,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/jaxrs-cxf-client.md b/docs/generators/jaxrs-cxf-client.md
index ec8e4535d969..deb6b093dc10 100644
--- a/docs/generators/jaxrs-cxf-client.md
+++ b/docs/generators/jaxrs-cxf-client.md
@@ -103,6 +103,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -131,6 +132,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/jaxrs-cxf-extended.md b/docs/generators/jaxrs-cxf-extended.md
index 9e5f7c1786c2..2134e2a787bc 100644
--- a/docs/generators/jaxrs-cxf-extended.md
+++ b/docs/generators/jaxrs-cxf-extended.md
@@ -125,6 +125,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -153,6 +154,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/jaxrs-cxf.md b/docs/generators/jaxrs-cxf.md
index 7323d6be98fb..a942f820ce95 100644
--- a/docs/generators/jaxrs-cxf.md
+++ b/docs/generators/jaxrs-cxf.md
@@ -120,6 +120,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -148,6 +149,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/jaxrs-jersey.md b/docs/generators/jaxrs-jersey.md
index 98804c588ea5..dddcb4c3c1db 100644
--- a/docs/generators/jaxrs-jersey.md
+++ b/docs/generators/jaxrs-jersey.md
@@ -101,6 +101,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -129,6 +130,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/jaxrs-resteasy-eap.md b/docs/generators/jaxrs-resteasy-eap.md
index 96482de456fd..0c5891c6c074 100644
--- a/docs/generators/jaxrs-resteasy-eap.md
+++ b/docs/generators/jaxrs-resteasy-eap.md
@@ -102,6 +102,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -130,6 +131,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/jaxrs-resteasy.md b/docs/generators/jaxrs-resteasy.md
index 5c99da79a439..a1b67fc02c8c 100644
--- a/docs/generators/jaxrs-resteasy.md
+++ b/docs/generators/jaxrs-resteasy.md
@@ -101,6 +101,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -129,6 +130,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/jaxrs-spec.md b/docs/generators/jaxrs-spec.md
index c3bb79c787cc..3d0b0067a97b 100644
--- a/docs/generators/jaxrs-spec.md
+++ b/docs/generators/jaxrs-spec.md
@@ -115,6 +115,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -143,6 +144,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/docs/generators/spring.md b/docs/generators/spring.md
index adf5726a9d8a..d3f29285d74f 100644
--- a/docs/generators/spring.md
+++ b/docs/generators/spring.md
@@ -163,6 +163,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|Array|java.util.List|
|ArrayList|java.util.ArrayList|
|BigDecimal|java.math.BigDecimal|
+|BigInteger|java.math.BigInteger|
|Date|java.util.Date|
|DateTime|org.joda.time.*|
|File|java.io.File|
@@ -191,6 +192,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES
+- BigInteger
- Boolean
- Double
- Float
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java
index 554f98183fc7..3d81e8f598ba 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java
@@ -61,6 +61,8 @@
import java.io.File;
import java.io.IOException;
import java.io.Writer;
+import java.math.BigDecimal;
+import java.math.BigInteger;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
@@ -87,6 +89,11 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
private final Logger LOGGER = LoggerFactory.getLogger(AbstractJavaCodegen.class);
private static final String ARTIFACT_VERSION_DEFAULT_VALUE = "1.0.0";
private static final ZoneId UTC = ZoneId.of("UTC");
+
+ private static final BigDecimal INTEGER_MIN_VALUE = BigDecimal.valueOf(Integer.MIN_VALUE);
+ private static final BigDecimal INTEGER_MAX_VALUE = BigDecimal.valueOf(Integer.MAX_VALUE);
+ private static final BigDecimal LONG_MIN_VALUE = BigDecimal.valueOf(Long.MIN_VALUE);
+ private static final BigDecimal LONG_MAX_VALUE = BigDecimal.valueOf(Long.MAX_VALUE);
public static final String DEFAULT_LIBRARY = "";
public static final String DATE_LIBRARY = "dateLibrary";
@@ -294,6 +301,7 @@ public AbstractJavaCodegen() {
"Double",
"Integer",
"Long",
+ "BigInteger",
"Float",
"Object",
"byte[]"
@@ -304,8 +312,10 @@ public AbstractJavaCodegen() {
typeMapping.put("date", "Date");
typeMapping.put("file", "File");
typeMapping.put("AnyType", "Object");
+ typeMapping.put("BigInteger", "BigInteger");
importMapping.put("BigDecimal", "java.math.BigDecimal");
+ importMapping.put("BigInteger", "java.math.BigInteger");
importMapping.put("UUID", "java.util.UUID");
importMapping.put("URI", "java.net.URI");
importMapping.put("File", "java.io.File");
@@ -1909,6 +1919,34 @@ public String toExampleValue(Schema p) {
@Override
public String getSchemaType(Schema p) {
+ if (ModelUtils.isIntegerSchema(p)) {
+ // legacy, non-standard `uint32`/`uint64` integer formats: since Java has no native
+ // unsigned integer types, widen them to a type that can hold the full unsigned range
+ String typeFromFormat = null;
+ if ("uint32".equals(p.getFormat())) {
+ typeFromFormat = typeMapping.get("long");
+ } else if ("uint64".equals(p.getFormat())) {
+ typeFromFormat = typeMapping.get("BigInteger");
+ } else if (SchemaTypeUtil.INTEGER32_FORMAT.equals(p.getFormat())) {
+ typeFromFormat = typeMapping.get("integer");
+ } else if (SchemaTypeUtil.INTEGER64_FORMAT.equals(p.getFormat())) {
+ typeFromFormat = typeMapping.get("long");
+ }
+
+ if(typeFromFormat != null) {
+ return typeFromFormat;
+ }
+
+ if (hasIntegerBounds(p)) {
+ String inferredType = bestFittingIntegerType(
+ p.getMinimum(), Boolean.TRUE.equals(p.getExclusiveMinimum()),
+ p.getMaximum(), Boolean.TRUE.equals(p.getExclusiveMaximum())
+ );
+
+ return inferredType;
+ }
+ }
+
String openAPIType = super.getSchemaType(p);
// don't apply renaming on types from the typeMapping
@@ -1922,6 +1960,92 @@ public String getSchemaType(Schema p) {
return toModelName(openAPIType);
}
+ private boolean hasIntegerBounds(Schema p) {
+ return p.getMinimum() != null || p.getMaximum() != null;
+ }
+
+ /**
+ * Determine the smallest Java integer type (Integer, Long or BigInteger) that can represent every
+ * value in the given [minimum, maximum] range. Missing bounds are treated as unbounded on that side.
+ */
+ private String bestFittingIntegerType(BigDecimal minimum, boolean exclusiveMinimum,
+ BigDecimal maximum, boolean exclusiveMaximum) {
+
+ if (exclusiveMinimum && minimum != null) {
+ minimum = minimum.add(BigDecimal.ONE);
+ }
+ if (exclusiveMaximum && maximum != null) {
+ 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");
+ } 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");
+ }
+
+ private Boolean fitsInInt(BigDecimal value) {
+ return value.compareTo(INTEGER_MIN_VALUE) >= 0 && value.compareTo(INTEGER_MAX_VALUE) <= 0;
+ }
+
+ private Boolean fitsInLong(BigDecimal value) {
+ return value.compareTo(LONG_MIN_VALUE) >= 0 && value.compareTo(LONG_MAX_VALUE) <= 0;
+ }
+
+ @Override
+ protected void updatePropertyForInteger(CodegenProperty property, Schema p) {
+ // legacy, non-standard `uint32`/`uint64` integer formats (see getSchemaType above)
+ property.isNumeric = Boolean.TRUE;
+
+ if ("uint32".equals(p.getFormat())) {
+ property.isLong = Boolean.TRUE;
+ return;
+ } else if ("uint64".equals(p.getFormat())) {
+ property.isNumeric = Boolean.TRUE;
+ return;
+ } else if (SchemaTypeUtil.INTEGER32_FORMAT.equals(p.getFormat())) {
+ property.isInteger = Boolean.TRUE;
+ return;
+ } else if (SchemaTypeUtil.INTEGER64_FORMAT.equals(p.getFormat())) {
+ property.isLong = Boolean.TRUE;
+ return;
+ }
+
+ if (hasIntegerBounds(p)) {
+ String inferredType = bestFittingIntegerType(
+ p.getMinimum(), Boolean.TRUE.equals(p.getExclusiveMinimum()),
+ p.getMaximum(), Boolean.TRUE.equals(p.getExclusiveMaximum())
+ );
+
+ if (typeMapping.get("long").equals(inferredType)) {
+ property.isLong = Boolean.TRUE;
+ }
+ if (typeMapping.get("integer").equals(inferredType)) {
+ property.isInteger = Boolean.TRUE;
+ }
+ return;
+ }
+
+ super.updatePropertyForInteger(property, p);
+ }
+
+ @Override
+ public void postProcessParameter(CodegenParameter parameter) {
+ // keep isLong/isInteger in sync with the widened dataType from uint32/uint64 formats and
+ // range-inferred Long/BigInteger types (see getSchemaType/updatePropertyForInteger above)
+ if (typeMapping.get("long").equals(parameter.dataType)) {
+ parameter.isInteger = false;
+ parameter.isLong = true;
+ } else if (typeMapping.get("BigInteger").equals(parameter.dataType)) {
+ parameter.isInteger = false;
+ parameter.isLong = false;
+ }
+ }
+
@Override
public String toOperationId(String operationId) {
// throw exception if method name is empty
@@ -2072,6 +2196,14 @@ public void postProcessResponseWithProperty(CodegenResponse response, CodegenPro
// the response data types should not contain bean validation annotations.
property.dataType = removeAnnotations(property.dataType);
response.dataType = removeAnnotations(response.dataType);
+
+ if (typeMapping.get("long").equals(response.dataType)) {
+ response.isInteger = false;
+ response.isLong = true;
+ } else if (typeMapping.get("BigInteger").equals(response.dataType)) {
+ response.isInteger = false;
+ response.isLong = false;
+ }
}
/**
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaDubboServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaDubboServerCodegen.java
index cde832075961..395e4bc644cf 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaDubboServerCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaDubboServerCodegen.java
@@ -140,6 +140,7 @@ public JavaDubboServerCodegen() {
typeMapping.clear();
typeMapping.put("integer", "Integer");
typeMapping.put("long", "Long");
+ typeMapping.put("BigInteger", "BigInteger");
typeMapping.put("float", "Float");
typeMapping.put("double", "Double");
typeMapping.put("boolean", "Boolean");
diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java
index b3940c9078ba..da52b4673cb9 100644
--- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java
+++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java
@@ -52,6 +52,7 @@
import java.io.File;
import java.io.IOException;
+import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -149,6 +150,78 @@ Iterator librariesNotSupportingJackson() {
}
+ @Test
+ public void testUint32AndUint64Formats() {
+ final JavaClientCodegen codegen = new JavaClientCodegen();
+
+ CodegenProperty uint32Property = codegen.fromProperty("uint32Value", new IntegerSchema().format("uint32"));
+ Assertions.assertEquals(uint32Property.dataType, "Long");
+ Assertions.assertEquals(uint32Property.baseType, "Long");
+ Assertions.assertTrue(uint32Property.isLong);
+ Assertions.assertFalse(uint32Property.isInteger);
+
+ CodegenProperty uint64Property = codegen.fromProperty("uint64Value", new IntegerSchema().format("uint64"));
+ Assertions.assertEquals(uint64Property.dataType, "BigInteger");
+ Assertions.assertEquals(uint64Property.baseType, "BigInteger");
+ Assertions.assertFalse(uint64Property.isLong);
+ Assertions.assertFalse(uint64Property.isInteger);
+ }
+
+ @Test
+ public void testIntegerTypeInferredFromRangeWhenFormatIsMissing() {
+ final JavaClientCodegen codegen = new JavaClientCodegen();
+
+ // small range with no format: stays the default Integer
+ CodegenProperty smallRange = codegen.fromProperty("smallRange",
+ new IntegerSchema().format(null).minimum(BigDecimal.ZERO).maximum(BigDecimal.valueOf(255)));
+ Assertions.assertEquals(smallRange.dataType, "Integer");
+ Assertions.assertTrue(smallRange.isInteger);
+ Assertions.assertFalse(smallRange.isLong);
+
+ // range exceeding Integer bounds with no format: widen to Long
+ CodegenProperty exceedsInteger = codegen.fromProperty("exceedsInteger",
+ new IntegerSchema().format(null).maximum(BigDecimal.valueOf(Integer.MAX_VALUE).add(BigDecimal.ONE)));
+ Assertions.assertEquals(exceedsInteger.dataType, "Long");
+ Assertions.assertTrue(exceedsInteger.isLong);
+ Assertions.assertFalse(exceedsInteger.isInteger);
+
+ // range exceeding Long bounds with no format: widen to BigInteger
+ CodegenProperty exceedsLong = codegen.fromProperty("exceedsLong",
+ new IntegerSchema().format(null).maximum(BigDecimal.valueOf(Long.MAX_VALUE).add(BigDecimal.ONE)));
+ Assertions.assertEquals(exceedsLong.dataType, "BigInteger");
+ Assertions.assertFalse(exceedsLong.isLong);
+ Assertions.assertFalse(exceedsLong.isInteger);
+
+ // exclusiveMaximum pushes the effective bound just over the Integer limit
+ CodegenProperty exclusiveMax = codegen.fromProperty("exclusiveMax",
+ new IntegerSchema().format(null).maximum(BigDecimal.valueOf(Integer.MAX_VALUE).add(BigDecimal.valueOf(2))).exclusiveMaximum(true));
+ Assertions.assertEquals(exclusiveMax.dataType, "Long");
+ Assertions.assertTrue(exclusiveMax.isLong);
+ }
+
+ @Test
+ public void testResponseTypeInferredFromRangeKeepsIntegerFlagsInSync() {
+ final JavaClientCodegen codegen = new JavaClientCodegen();
+
+ ApiResponse exceedsIntegerResponse = new ApiResponse().content(new Content().addMediaType(
+ "application/json",
+ new MediaType().schema(new IntegerSchema().format(null).maximum(BigDecimal.valueOf(Integer.MAX_VALUE).add(BigDecimal.ONE)))
+ ));
+ CodegenResponse longResponse = codegen.fromResponse("200", exceedsIntegerResponse);
+ Assertions.assertEquals(longResponse.dataType, "Long");
+ Assertions.assertTrue(longResponse.isLong);
+ Assertions.assertFalse(longResponse.isInteger);
+
+ ApiResponse exceedsLongResponse = new ApiResponse().content(new Content().addMediaType(
+ "application/json",
+ new MediaType().schema(new IntegerSchema().format(null).maximum(BigDecimal.valueOf(Long.MAX_VALUE).add(BigDecimal.ONE)))
+ ));
+ CodegenResponse bigIntegerResponse = codegen.fromResponse("200", exceedsLongResponse);
+ Assertions.assertEquals(bigIntegerResponse.dataType, "BigInteger");
+ Assertions.assertFalse(bigIntegerResponse.isLong);
+ Assertions.assertFalse(bigIntegerResponse.isInteger);
+ }
+
@Test
public void arraysInRequestBody() {
OpenAPI openAPI = TestUtils.createOpenAPI();
diff --git a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerInterface.java b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerInterface.java
index d5faaeaaa5fe..1d353e5026db 100644
--- a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerInterface.java
+++ b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerInterface.java
@@ -580,7 +580,7 @@ public interface PathHandlerInterface {
}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=true, isNumeric=false, isInteger=false, isShort=false, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isPassword=false, isFreeFormObject=false, isArray=false, isMap=false, isOptional=false, isEnum=false, isInnerEnum=false, isEnumRef=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, isNew=false, isOverridden=null, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='setCookie', nameInPascalCase='SetCookie', nameInSnakeCase='SET_COOKIE', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, isVoid=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, hasSanitizedName=true, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=null, dependentRequired=null, contains=null}, CodegenProperty{openApiType='integer', baseName='X-Rate-Limit', complexType='null', getter='getxRateLimit', setter='setxRateLimit', description='calls per hour allowed by the user', dataType='Integer', datatypeWithEnum='Integer', dataFormat='int32', name='xRateLimit', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.X-Rate-Limit;', baseType='Integer', containerType='null', containerTypeMapped='null', title='null', unescapedDescription='calls per hour allowed by the user', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{
"format" : "int32",
"type" : "integer"
-}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=false, isNumeric=true, isInteger=true, isShort=true, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isPassword=false, isFreeFormObject=false, isArray=false, isMap=false, isOptional=false, isEnum=false, isInnerEnum=false, isEnumRef=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, isNew=false, isOverridden=null, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='xRateLimit', nameInPascalCase='XRateLimit', nameInSnakeCase='X_RATE_LIMIT', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, isVoid=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, hasSanitizedName=true, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=int32, dependentRequired=null, contains=null}, CodegenProperty{openApiType='string', baseName='X-Expires-After', complexType='Date', getter='getxExpiresAfter', setter='setxExpiresAfter', description='date in UTC when token expires', dataType='Date', datatypeWithEnum='Date', dataFormat='date-time', name='xExpiresAfter', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.X-Expires-After;', baseType='Date', containerType='null', containerTypeMapped='null', title='null', unescapedDescription='date in UTC when token expires', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{
+}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=false, isNumeric=true, isInteger=true, isShort=false, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isPassword=false, isFreeFormObject=false, isArray=false, isMap=false, isOptional=false, isEnum=false, isInnerEnum=false, isEnumRef=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, isNew=false, isOverridden=null, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='xRateLimit', nameInPascalCase='XRateLimit', nameInSnakeCase='X_RATE_LIMIT', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, isVoid=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, hasSanitizedName=true, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=int32, dependentRequired=null, contains=null}, CodegenProperty{openApiType='string', baseName='X-Expires-After', complexType='Date', getter='getxExpiresAfter', setter='setxExpiresAfter', description='date in UTC when token expires', dataType='Date', datatypeWithEnum='Date', dataFormat='date-time', name='xExpiresAfter', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.X-Expires-After;', baseType='Date', containerType='null', containerTypeMapped='null', title='null', unescapedDescription='date in UTC when token expires', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{
"format" : "date-time",
"type" : "string"
}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, isPrimitiveType=false, isModel=false, isContainer=false, isString=false, isNumeric=false, isInteger=false, isShort=false, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=true, isUuid=false, isUri=false, isEmail=false, isPassword=false, isFreeFormObject=false, isArray=false, isMap=false, isOptional=false, isEnum=false, isInnerEnum=false, isEnumRef=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, isNew=false, isOverridden=null, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='xExpiresAfter', nameInPascalCase='XExpiresAfter', nameInSnakeCase='X_EXPIRES_AFTER', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, isVoid=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, hasSanitizedName=true, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=date-time, dependentRequired=null, contains=null}]