Skip to content

Commit

Permalink
Extensions in subobjects of OpenAPI no longer work. Fixes #2449.
Browse files Browse the repository at this point in the history
  • Loading branch information
bnasslahsen committed Feb 28, 2024
1 parent 9b6de3a commit e893628
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ private Map<String, ApiResponse> getGenericMapResponse(Class<?> beanType) {

LinkedHashMap<String, ApiResponse> genericApiResponsesClone;
try {
ObjectMapper objectMapper = ObjectMapperProvider.createJson(springDocConfigProperties);
ObjectMapper objectMapper = new ObjectMapper();
genericApiResponsesClone = objectMapper.readValue(objectMapper.writeValueAsString(genericApiResponseMap), ApiResponses.class);
return genericApiResponsesClone;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,12 @@ public OpenAPI build(Locale locale) {
}
else {
try {
ObjectMapper objectMapper = ObjectMapperProvider.createJson(springDocConfigProperties);
ObjectMapper objectMapper = new ObjectMapper();
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());
calculatedOpenAPI = openAPI;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Map;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.junit.jupiter.api.Test;
import org.springdoc.core.utils.Constants;
import test.org.springdoc.api.v30.AbstractSpringDocV30Test;
Expand Down Expand Up @@ -68,7 +69,9 @@ private void testApp(Locale locale) throws Exception {
static class SpringDocTestApp {
@Bean
public OpenAPI openAPI() {
return new OpenAPI().extensions(Map.of("TEST", "HELLO"));
return new OpenAPI()
.info(new Info().extensions(Map.of("TEST", "HELLO")))
.extensions(Map.of("TEST", "HELLO"));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"openapi": "3.0.1",
"info": {
"title": "OpenAPI definition",
"version": "v0"
"TEST": "HELLO"
},
"servers": [
{
Expand Down

0 comments on commit e893628

Please sign in to comment.