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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<central-publishing-maven-plugin.version>0.11.0
</central-publishing-maven-plugin.version>
<flatten-maven-plugin.version>1.5.0</flatten-maven-plugin.version>
<swagger-api.version>2.2.52</swagger-api.version>
<swagger-api.version>2.2.53</swagger-api.version>
<swagger-ui.version>5.32.11</swagger-ui.version>
<gmavenplus-plugin.version>1.13.1</gmavenplus-plugin.version>
<jjwt.version>0.9.1</jjwt.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,6 @@ protected OpenAPI getOpenApi(String serverBaseUrl, Locale locale) {
}
getPaths(mappingsMap, finalLocale, openAPI);

removeNullKeyComponentProperties(openAPI);

if (springDocConfigProperties.isTrimKotlinIndent())
this.trimIndent(openAPI);

Expand Down Expand Up @@ -465,23 +463,6 @@ private Locale selectLocale(Locale inputLocale) {
return inputLocale == null ? Locale.getDefault() : inputLocale;
}

/**
* Removes {@code null}-keyed entries from the component schema properties. Swagger-core
* inserts a {@code null} property key when resolving a {@code @JsonUnwrapped} member whose
* content is a {@code $ref} (for example Spring HATEOAS {@code EntityModel.getContent()}
* with HAL disabled), which otherwise breaks JSON serialization of the document.
*
* @param openAPI the open api
*/
private static void removeNullKeyComponentProperties(OpenAPI openAPI) {
if (openAPI.getComponents() == null || openAPI.getComponents().getSchemas() == null) {
return;
}
for (Schema<?> schema : openAPI.getComponents().getSchemas().values()) {
SpringDocUtils.removeNullKeyProperties(schema);
}
}

/**
* Indents are removed for properties that are mainly used as “explanations” using Open API.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import org.springdoc.core.converters.OAS31ModelConverter;
import org.springdoc.core.converters.PolymorphicModelConverter;
import org.springdoc.core.converters.PropertyCustomizingConverter;
import org.springdoc.core.converters.PropertyNamingStrategyConverter;
import org.springdoc.core.converters.ResponseSupportConverter;
import org.springdoc.core.converters.SchemaPropertyDeprecatingConverter;
import org.springdoc.core.converters.WebFluxSupportConverter;
Expand Down Expand Up @@ -295,19 +294,6 @@ PolymorphicModelConverter polymorphicModelConverter(ObjectMapperProvider objectM
return new PolymorphicModelConverter(objectMapperProvider);
}

/**
* Property naming strategy converter property naming strategy converter.
*
* @param objectMapperProvider the object mapper provider
* @return the property naming strategy converter
*/
@Bean
@ConditionalOnMissingBean
@Lazy(false)
PropertyNamingStrategyConverter propertyNamingStrategyConverter(ObjectMapperProvider objectMapperProvider) {
return new PropertyNamingStrategyConverter(objectMapperProvider);
}

/**
* Open api builder open api builder.
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema.RequiredMode;
import io.swagger.v3.oas.models.SpecVersion;
import io.swagger.v3.oas.models.media.Schema;
import jakarta.validation.OverridesAttribute;
import jakarta.validation.constraints.DecimalMax;
Expand Down Expand Up @@ -307,7 +306,6 @@ else if (OPENAPI_STRING_TYPE.equals(type)) {
schema.setMaximum(BigDecimal.valueOf(((Range) anno).max()));
}
});
fixOAS31ExclusiveConstraints(schema);
if (schema!=null && annotatedNotNull(annotations)) {
String specVersion = schema.getSpecVersion().name();
if (!"V30".equals(specVersion)) {
Expand Down Expand Up @@ -576,28 +574,4 @@ private static JsonProperty getJsonProperty(Field f) {
if (g != null) return g.getAnnotation(JsonProperty.class);
return null;
}

/**
* Swagger-core 2.2.49 introduced so that {@link Positive} and {@link Negative} are introspected.
* It does not correctly use the fact that exclusiveMinimum/exclusiveMaximum are values in OAS31.
* <p>
* Tracked under <a href="https://github.com/swagger-api/swagger-core/issues/5170">swagger-core#5170</a>.
*
* @param schema the schema to fix
*/
public static void fixOAS31ExclusiveConstraints(Schema<?> schema) {
if (schema == null) {
return;
}
if (schema.getSpecVersion().equals(SpecVersion.V31)) {
if (schema.getExclusiveMaximumValue() != null && schema.getMaximum() != null
&& schema.getMaximum().compareTo(schema.getExclusiveMaximumValue()) == 0) {
schema.setMaximum(null);
}
if (schema.getExclusiveMinimumValue() != null && schema.getMinimum() != null &&
schema.getMinimum().compareTo(schema.getExclusiveMinimumValue()) == 0) {
schema.setMinimum(null);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;

import com.fasterxml.jackson.core.type.TypeReference;
Expand Down Expand Up @@ -181,60 +180,9 @@ else if (schema.getItems() != null && schema.getItems().getType() != null
if (schema.getProperties() != null) {
schema.getProperties().forEach((key, value) -> handleSchemaTypes(value));
}
fixNullOnlyAdditionalProperties(schema);
}
}

/**
* Fix additionalProperties incorrectly set to {"type": "null"} when @Nullable
* propagates from a Map field to its Object value type (resolved as "any type" = {}).
* <p>
* Tracked under <a href="https://github.com/swagger-api/swagger-core/issues/5115">swagger-core#5115</a>.
*
* @param schema the schema to fix
*/
public static void fixNullOnlyAdditionalProperties(Schema<?> schema) {
if (schema == null) {
return;
}
Object additionalProperties = schema.getAdditionalProperties();
if (additionalProperties instanceof Schema<?> addPropSchema) {
boolean isNullOnlyType = false;
Set<String> types = addPropSchema.getTypes();
boolean onlyNullTypeOAS31 = types != null && types.size() == 1 && types.contains("null");
boolean onlyNullTypeOAS30 = types == null && "null".equals(addPropSchema.getType());
if (onlyNullTypeOAS31 || onlyNullTypeOAS30) {
isNullOnlyType = true;
}
if (isNullOnlyType && addPropSchema.get$ref() == null
&& addPropSchema.getProperties() == null && addPropSchema.getFormat() == null) {
addPropSchema.setTypes(null);
addPropSchema.setType(null);
}
}
if (schema.getProperties() != null) {
schema.getProperties().values().forEach(SpringDocUtils::fixNullOnlyAdditionalProperties);
}
}

/**
* Removes {@code null}-keyed entries from a schema's properties map (and its nested
* schemas). When swagger-core resolves a {@code @JsonUnwrapped} member (for example
* Spring HATEOAS {@code EntityModel.getContent()} with HAL disabled), the unwrapped
* property schemas may have a {@code null} name and get inserted into the properties map
* under a {@code null} key. Such a key cannot be serialized by Jackson, which fails the
* whole OpenAPI document with {@code "Null key for a Map not allowed in JSON"}.
*
* @param schema the schema to fix
*/
public static void removeNullKeyProperties(Schema<?> schema) {
if (schema == null || schema.getProperties() == null) {
return;
}
schema.getProperties().keySet().removeIf(Objects::isNull);
schema.getProperties().values().forEach(SpringDocUtils::removeNullKeyProperties);
}

/**
* Handle schema types.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import org.springframework.web.bind.annotation.RestController
* Reproduces the swagger-core `@JsonUnwrapped` null-property-key issue: when the unwrapped
* member resolves to a `$ref` (a named component model), swagger-core adds a `null`-keyed
* entry to the enclosing schema properties, which breaks JSON serialization of the document.
*
* Fixed upstream by <a href="https://github.com/swagger-api/swagger-core/pull/5193">PR 5193</a>
*/
@RestController
class NullKeyController {
Expand Down
Loading
Loading