Skip to content

Commit a7bbc3f

Browse files
authored
Merge pull request #3284 from Mattias-Sehlstedt/update-swagger-core-2
Upgrade swagger-core from version 2.2.48 to 2.2.49
2 parents aac6ed6 + c8d4c0e commit a7bbc3f

5 files changed

Lines changed: 31 additions & 24 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<central-publishing-maven-plugin.version>0.7.0
5555
</central-publishing-maven-plugin.version>
5656
<flatten-maven-plugin.version>1.5.0</flatten-maven-plugin.version>
57-
<swagger-api.version>2.2.48</swagger-api.version>
57+
<swagger-api.version>2.2.49</swagger-api.version>
5858
<swagger-ui.version>5.32.2</swagger-ui.version>
5959
<gmavenplus-plugin.version>1.13.1</gmavenplus-plugin.version>
6060
<jjwt.version>0.9.1</jjwt.version>

springdoc-openapi-starter-common/src/main/java/org/springdoc/api/AbstractOpenApiResource.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,6 @@ protected OpenAPI getOpenApi(String serverBaseUrl, Locale locale) {
385385
}
386386
getPaths(mappingsMap, finalLocale, openAPI);
387387

388-
if (OpenApiVersion.OPENAPI_3_1 == springDocConfigProperties.getApiDocs().getVersion())
389-
handleComponentSchemaTypes(openAPI);
390-
391388
if (springDocConfigProperties.isTrimKotlinIndent())
392389
this.trimIndent(openAPI);
393390

@@ -458,20 +455,6 @@ private void trimIndent(OpenAPI openAPI) {
458455
trimPaths(openAPI);
459456
}
460457

461-
/**
462-
* Fix component schemas for OAS 3.1 post-processing.
463-
*
464-
* @param openAPI the open api
465-
*/
466-
private static void handleComponentSchemaTypes(OpenAPI openAPI) {
467-
if (openAPI.getComponents() == null || openAPI.getComponents().getSchemas() == null) {
468-
return;
469-
}
470-
for (Schema<?> schema : openAPI.getComponents().getSchemas().values()) {
471-
SpringDocUtils.fixNullOnlyAdditionalProperties(schema);
472-
}
473-
}
474-
475458
/**
476459
* Trim the indent for descriptions in the 'components' of open api.
477460
*

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/providers/ObjectMapperProvider.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import io.swagger.v3.core.util.Yaml;
3636
import io.swagger.v3.core.util.Yaml31;
3737
import io.swagger.v3.oas.models.OpenAPI;
38-
import io.swagger.v3.core.util.PrimitiveType;
3938
import io.swagger.v3.oas.models.media.Schema;
4039
import org.springdoc.core.mixins.SortedOpenAPIMixin;
4140
import org.springdoc.core.mixins.SortedOpenAPIMixin31;
@@ -81,14 +80,10 @@ public ObjectMapperProvider(SpringDocConfigProperties springDocConfigProperties)
8180
if (springDocConfigProperties.isExplicitObjectSchema()) {
8281
System.setProperty(Schema.EXPLICIT_OBJECT_SCHEMA_PROPERTY, "true");
8382
}
84-
else {
85-
PrimitiveType.explicitObjectType = false;
86-
}
8783
}
8884
else {
8985
jsonMapper = Json.mapper();
9086
yamlMapper = Yaml.mapper();
91-
PrimitiveType.explicitObjectType = null;
9287
}
9388
}
9489

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/utils/SchemaUtils.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import com.fasterxml.jackson.annotation.JsonProperty;
1313
import io.swagger.v3.oas.annotations.Parameter;
1414
import io.swagger.v3.oas.annotations.media.Schema.RequiredMode;
15+
import io.swagger.v3.oas.models.SpecVersion;
1516
import io.swagger.v3.oas.models.media.Schema;
16-
import jakarta.validation.Constraint;
1717
import jakarta.validation.OverridesAttribute;
1818
import jakarta.validation.constraints.DecimalMax;
1919
import jakarta.validation.constraints.DecimalMin;
@@ -296,6 +296,7 @@ else if (OPENAPI_STRING_TYPE.equals(type)) {
296296
schema.setMaximum(BigDecimal.valueOf(((Range) anno).max()));
297297
}
298298
});
299+
fixOAS31ExclusiveConstraints(schema);
299300
if (schema!=null && annotatedNotNull(annotations)) {
300301
String specVersion = schema.getSpecVersion().name();
301302
if (!"V30".equals(specVersion)) {
@@ -541,4 +542,30 @@ private static JsonProperty getJsonProperty(Field f) {
541542
if (g != null) return g.getAnnotation(JsonProperty.class);
542543
return null;
543544
}
545+
546+
/**
547+
* Swagger-core 2.2.49 introduced so that {@link Positive} and {@link Negative} are introspected.
548+
* It does not correctly use the fact that exclusiveMinimum/exclusiveMaximum are values in OAS31.
549+
* <p>
550+
* Tracked under <a href="https://github.com/swagger-api/swagger-core/issues/5170">swagger-core#5170</a>.
551+
*
552+
* @param schema the schema to fix
553+
*/
554+
public static void fixOAS31ExclusiveConstraints(Schema<?> schema) {
555+
if (schema == null) {
556+
return;
557+
}
558+
if (schema.getSpecVersion().equals(SpecVersion.V31)) {
559+
if (schema.getExclusiveMaximumValue() != null && schema.getMaximum() != null) {
560+
if (schema.getMaximum().compareTo(schema.getExclusiveMaximumValue()) == 0) {
561+
schema.setMaximum(null);
562+
}
563+
}
564+
if (schema.getExclusiveMinimumValue() != null && schema.getMinimum() != null) {
565+
if (schema.getMinimum().compareTo(schema.getExclusiveMinimumValue()) == 0) {
566+
schema.setMinimum(null);
567+
}
568+
}
569+
}
570+
}
544571
}

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/utils/SpringDocUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ else if (schema.getItems() != null && schema.getItems().getType() != null
187187
/**
188188
* Fix additionalProperties incorrectly set to {"type": "null"} when @Nullable
189189
* propagates from a Map field to its Object value type (resolved as "any type" = {}).
190+
* <p>
191+
* Tracked under <a href="https://github.com/swagger-api/swagger-core/issues/5115">swagger-core#5115</a>.
190192
*
191193
* @param schema the schema to fix
192194
*/

0 commit comments

Comments
 (0)