diff --git a/pom.xml b/pom.xml index fb1d5310c2..d0b0c115a6 100644 --- a/pom.xml +++ b/pom.xml @@ -85,12 +85,11 @@ org.apache.maven.surefire - surefire-junit4 + surefire-testng ${surefire-version} - none:none -javaagent:${settings.localRepository}/org/jmockit/jmockit/${jmockit-version}/jmockit-${jmockit-version}.jar -XX:+IgnoreUnrecognizedVMOptions --add-opens=java.base/java.util=ALL-UNNAMED diff --git a/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java b/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java index a496894a08..93059b9f3f 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java +++ b/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java @@ -1815,12 +1815,23 @@ protected void processPropertySchemaContainerTypes(CodegenProperty codegenProper } private void handleMinMaxValues(Schema propertySchema, CodegenProperty codegenProperty) { - if (propertySchema.getMinimum() != null) { - codegenProperty.minimum = String.valueOf(propertySchema.getMinimum().longValue()); - } - if (propertySchema.getMaximum() != null) { - codegenProperty.maximum = String.valueOf(propertySchema.getMaximum().longValue()); - } + if (propertySchema.getMaximum() != null) { + long maximumLongValue = propertySchema.getMaximum().longValue(); + if (maximumLongValue > Integer.MAX_VALUE || maximumLongValue < Integer.MIN_VALUE) { + codegenProperty.maximum = String.valueOf(propertySchema.getMaximum().longValue()) + "L"; + } else { + codegenProperty.maximum = String.valueOf(propertySchema.getMaximum().longValue()); + } + } + if (propertySchema.getMinimum() != null) { + long minimumLongValue = propertySchema.getMinimum().longValue(); + if (minimumLongValue > Integer.MAX_VALUE || minimumLongValue < Integer.MIN_VALUE) { + codegenProperty.minimum = String.valueOf(propertySchema.getMinimum().longValue()) + "L"; + } else { + codegenProperty.minimum = String.valueOf(propertySchema.getMinimum().longValue()); + } + } + if (propertySchema.getExclusiveMinimum() != null) { codegenProperty.exclusiveMinimum = propertySchema.getExclusiveMinimum(); } @@ -2582,8 +2593,26 @@ public CodegenParameter fromParameter(Parameter parameter, Set imports) // validation // handle maximum, minimum properly for int/long by removing the trailing ".0" if (parameterSchema instanceof IntegerSchema) { - codegenParameter.maximum = parameterSchema.getMaximum() == null ? null : String.valueOf(parameterSchema.getMaximum().longValue()); - codegenParameter.minimum = parameterSchema.getMinimum() == null ? null : String.valueOf(parameterSchema.getMinimum().longValue()); + if (parameterSchema.getMaximum() == null) { + codegenParameter.maximum = null; + } else { + long maximumLongValue = parameterSchema.getMaximum().longValue(); + if (maximumLongValue > Integer.MAX_VALUE || maximumLongValue < Integer.MIN_VALUE) { + codegenParameter.maximum = String.valueOf(parameterSchema.getMaximum().longValue()) + "L"; + } else { + codegenParameter.maximum = String.valueOf(parameterSchema.getMaximum().longValue()); + } + } + if (parameterSchema.getMinimum() == null) { + codegenParameter.minimum = null; + } else { + long minimumLongValue = parameterSchema.getMinimum().longValue(); + if (minimumLongValue > Integer.MAX_VALUE || minimumLongValue < Integer.MIN_VALUE) { + codegenParameter.minimum = String.valueOf(parameterSchema.getMinimum().longValue()) + "L"; + } else { + codegenParameter.minimum = String.valueOf(parameterSchema.getMinimum().longValue()); + } + } } else { codegenParameter.maximum = parameterSchema.getMaximum() == null ? null : String.valueOf(parameterSchema.getMaximum()); codegenParameter.minimum = parameterSchema.getMinimum() == null ? null : String.valueOf(parameterSchema.getMinimum()); diff --git a/src/test/java/io/swagger/codegen/v3/generators/DefaultCodegenConfigTest.java b/src/test/java/io/swagger/codegen/v3/generators/DefaultCodegenConfigTest.java index 0a9fdf4ba0..7ff33affea 100644 --- a/src/test/java/io/swagger/codegen/v3/generators/DefaultCodegenConfigTest.java +++ b/src/test/java/io/swagger/codegen/v3/generators/DefaultCodegenConfigTest.java @@ -91,7 +91,7 @@ public void testPutAdditionalProperties() throws Exception { @Test public void testNumberSchemaMinMax() { - Schema schema = new NumberSchema() + Schema schema = new NumberSchema() .minimum(BigDecimal.valueOf(50)) .maximum(BigDecimal.valueOf(1000)); @@ -101,6 +101,21 @@ public void testNumberSchemaMinMax() { Assert.assertEquals(codegenProperty.minimum, "50"); Assert.assertEquals(codegenProperty.maximum, "1000"); } + + @Test + public void testNumberSchemaMinMaxForLong() { + Schema schema = new NumberSchema() + .minimum(BigDecimal.valueOf(50)) + .maximum(BigDecimal.valueOf(Integer.MAX_VALUE + 1L)); + + schema.setFormat("int64"); + + final DefaultCodegenConfig codegen = new P_DefaultCodegenConfig(); + CodegenProperty codegenProperty = codegen.fromProperty("test", schema); + + Assert.assertEquals(codegenProperty.minimum, "50"); + Assert.assertEquals(codegenProperty.maximum, Integer.MAX_VALUE + 1L + "L"); + } @Test public void testFromOperation_BodyParamsUnique() {