Skip to content

Commit 2e4be72

Browse files
committed
feat: Compatibility with exclusiveMinimum in OpenAPI 3.0.0 vs. 3.1.0
(#22943)
1 parent 8009dac commit 2e4be72

1 file changed

Lines changed: 38 additions & 6 deletions

File tree

  • modules/openapi-generator/src/main/java/org/openapitools/codegen/utils

modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,8 @@ public static boolean hasValidation(Schema sc) {
835835
sc.getMaximum() != null ||
836836
sc.getExclusiveMaximum() != null ||
837837
sc.getExclusiveMinimum() != null ||
838+
sc.getExclusiveMaximumValue() != null ||
839+
sc.getExclusiveMinimumValue() != null ||
838840
sc.getUniqueItems() != null
839841
);
840842
}
@@ -1869,15 +1871,44 @@ public static void syncValidationProperties(Schema schema, IJsonSchemaValidation
18691871
if (multipleOf != null) vSB.withMultipleOf();
18701872

18711873
BigDecimal minimum = schema.getMinimum();
1872-
if (minimum != null) vSB.withMinimum();
1873-
18741874
BigDecimal maximum = schema.getMaximum();
1875-
if (maximum != null) vSB.withMaximum();
1876-
18771875
Boolean exclusiveMinimum = schema.getExclusiveMinimum();
1878-
if (exclusiveMinimum != null) vSB.withExclusiveMinimum();
1879-
18801876
Boolean exclusiveMaximum = schema.getExclusiveMaximum();
1877+
1878+
// === START: Added code to handle OpenAPI 3.1.0+ numeric exclusiveMinimum/exclusiveMaximum ===
1879+
// Logic synced from OpenAPINormalizer#normalizeExclusiveMinMax31()
1880+
BigDecimal exclusiveMinValue = schema.getExclusiveMinimumValue();
1881+
if (exclusiveMinValue != null) {
1882+
if (minimum == null) {
1883+
minimum = exclusiveMinValue;
1884+
exclusiveMinimum = Boolean.TRUE;
1885+
} else {
1886+
int cmp = exclusiveMinValue.compareTo(minimum);
1887+
if (cmp >= 0) {
1888+
minimum = exclusiveMinValue;
1889+
exclusiveMinimum = Boolean.TRUE;
1890+
}
1891+
}
1892+
}
1893+
1894+
BigDecimal exclusiveMaxValue = schema.getExclusiveMaximumValue();
1895+
if (exclusiveMaxValue != null) {
1896+
if (maximum == null) {
1897+
maximum = exclusiveMaxValue;
1898+
exclusiveMaximum = Boolean.TRUE;
1899+
} else {
1900+
int cmp = exclusiveMaxValue.compareTo(maximum);
1901+
if (cmp <= 0) {
1902+
maximum = exclusiveMaxValue;
1903+
exclusiveMaximum = Boolean.TRUE;
1904+
}
1905+
}
1906+
}
1907+
// === END: Added code ===
1908+
1909+
if (minimum != null) vSB.withMinimum();
1910+
if (maximum != null) vSB.withMaximum();
1911+
if (exclusiveMinimum != null) vSB.withExclusiveMinimum();
18811912
if (exclusiveMaximum != null) vSB.withExclusiveMaximum();
18821913

18831914
LinkedHashSet<String> setValidations = vSB.build();
@@ -2207,6 +2238,7 @@ public static boolean hasCommonAttributesDefined(Schema schema) {
22072238
if (schema.getNullable() != null || schema.getDefault() != null ||
22082239
schema.getMinimum() != null || schema.getMaximum() != null ||
22092240
schema.getExclusiveMaximum() != null || schema.getExclusiveMinimum() != null ||
2241+
schema.getExclusiveMaximumValue() != null || schema.getExclusiveMinimumValue() != null ||
22102242
schema.getMinLength() != null || schema.getMaxLength() != null ||
22112243
schema.getMinItems() != null || schema.getMaxItems() != null ||
22122244
schema.getReadOnly() != null || schema.getWriteOnly() != null ||

0 commit comments

Comments
 (0)