Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,11 @@
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<artifactId>surefire-testng</artifactId>
<version>${surefire-version}</version>
</dependency>
</dependencies>
<configuration>
<testNGArtifactName>none:none</testNGArtifactName>
<argLine>-javaagent:${settings.localRepository}/org/jmockit/jmockit/${jmockit-version}/jmockit-${jmockit-version}.jar -XX:+IgnoreUnrecognizedVMOptions --add-opens=java.base/java.util=ALL-UNNAMED</argLine>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -2582,8 +2593,26 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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() {
Expand Down