Skip to content

Commit

Permalink
fix: Fix processing of Open API docs by API Catalog (JavaTimeModule) (#…
Browse files Browse the repository at this point in the history
…3040)

Signed-off-by: Pavel Jareš <[email protected]>
  • Loading branch information
pj892031 authored Aug 22, 2023
1 parent de6923e commit 09f5095
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
package org.zowe.apiml.apicatalog.swagger.api;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.swagger.models.ExternalDocs;
import io.swagger.models.Path;
import io.swagger.models.Scheme;
Expand Down Expand Up @@ -54,13 +56,19 @@ public String transformApiDoc(String serviceId, ApiDocInfo apiDocInfo) {
updateExternalDoc(swagger, apiDocInfo);

try {
return Json.mapper().writeValueAsString(swagger);
return initializeObjectMapper().writeValueAsString(swagger);
} catch (JsonProcessingException e) {
log.debug("Could not convert Swagger to JSON", e);
throw new ApiDocTransformationException("Could not convert Swagger to JSON");
}
}

private ObjectMapper initializeObjectMapper() {
ObjectMapper objectMapper = Json.mapper();
objectMapper.registerModule(new JavaTimeModule());
return objectMapper;
}

/**
* Updates scheme and hostname, and adds API doc link to Swagger
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.PathItem;
Expand Down Expand Up @@ -74,7 +75,7 @@ public String transformApiDoc(String serviceId, ApiDocInfo apiDocInfo) {
return initializeObjectMapper().writeValueAsString(openAPI);
} catch (JsonProcessingException e) {
log.debug("Could not convert OpenAPI to JSON", e);
throw new ApiDocTransformationException("Could not convert Swagger to JSON");
throw new ApiDocTransformationException("Could not convert Swagger to JSON: " + e.getMessage());
}
}

Expand Down Expand Up @@ -195,6 +196,8 @@ private ObjectMapper initializeObjectMapper() {
objectMapper.registerModule(simpleModule);
objectMapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);

objectMapper.registerModule(new JavaTimeModule());

return objectMapper;
}
}

0 comments on commit 09f5095

Please sign in to comment.