diff --git a/springdoc-openapi-common/src/main/java/org/springdoc/core/OpenAPIService.java b/springdoc-openapi-common/src/main/java/org/springdoc/core/OpenAPIService.java index 6a60334f8..36322a707 100644 --- a/springdoc-openapi-common/src/main/java/org/springdoc/core/OpenAPIService.java +++ b/springdoc-openapi-common/src/main/java/org/springdoc/core/OpenAPIService.java @@ -37,6 +37,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import io.swagger.v3.core.jackson.TypeNameResolver; @@ -249,6 +250,9 @@ public OpenAPI build(Locale locale) { try { ObjectMapper objectMapper = ObjectMapperProvider.createJson(springDocConfigProperties); calculatedOpenAPI = objectMapper.readValue(objectMapper.writeValueAsString(openAPI), OpenAPI.class); + objectMapper.setSerializationInclusion(Include.ALWAYS); + Map extensionsClone = objectMapper.readValue(objectMapper.writeValueAsString(openAPI.getExtensions()), Map.class); + calculatedOpenAPI.extensions(extensionsClone); } catch (JsonProcessingException e) { LOGGER.warn("Json Processing Exception occurred: {}", e.getMessage()); diff --git a/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/v30/app173/SpringDocApp173Test.java b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/v30/app173/SpringDocApp173Test.java index 39df08dbc..1990a052b 100644 --- a/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/v30/app173/SpringDocApp173Test.java +++ b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/v30/app173/SpringDocApp173Test.java @@ -22,6 +22,7 @@ package test.org.springdoc.api.v30.app173; +import java.util.Collections; import java.util.Locale; import io.swagger.v3.oas.models.OpenAPI; @@ -65,7 +66,7 @@ private void testApp(Locale locale) throws Exception { static class SpringDocTestApp { @Bean public OpenAPI openAPI() { - return new OpenAPI(); + return new OpenAPI().extensions(Collections.singletonMap("TEST", "HELLO")); } } diff --git a/springdoc-openapi-webmvc-core/src/test/resources/results/3.0.1/app173.json b/springdoc-openapi-webmvc-core/src/test/resources/results/3.0.1/app173.json index a8128527a..616425fa4 100644 --- a/springdoc-openapi-webmvc-core/src/test/resources/results/3.0.1/app173.json +++ b/springdoc-openapi-webmvc-core/src/test/resources/results/3.0.1/app173.json @@ -48,5 +48,6 @@ } } }, - "components": {} + "components": {}, + "TEST": "HELLO" }