Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add localdate type and add mapper module detect #45

Merged
merged 3 commits into from
Mar 30, 2023
Merged
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
10 changes: 9 additions & 1 deletion features/src/test/java/com/openapi/forge/MethodCallHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -132,7 +134,13 @@ public String getPropertyOnObject(
Class.forName(packageName + "." + latestResponseType, false, classLoader);
Method getProp = propClass.getDeclaredMethod("get" + StringUtils.capitalize(propName));
getProp.setAccessible(true); // Otherwise causes IllegalAccessException.
return getProp.invoke(resultOfMethodCall).toString();
Object resultObject = getProp.invoke(resultOfMethodCall);
// Default ZonedDateTime formatting doesn't match with ISO format.
if (resultObject instanceof ZonedDateTime) {
return DateTimeFormatter.ISO_INSTANT.format((ZonedDateTime) resultObject);
} else {
return resultObject.toString();
}
} catch (ClassNotFoundException e) {
throw new RuntimeException("This is probably an issue with the test code:\t\r\n" + e);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
Expand Down
3 changes: 2 additions & 1 deletion helpers/createReturnStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const createReturnStatement = (responseSchema) => {
returnStatement = "responseBodyString";
break;
default:
mapperStatements = `ObjectMapper deserMapper = new ObjectMapper();\n`;
mapperStatements = `ObjectMapper deserMapper = new ObjectMapper();deserMapper.findAndRegisterModules();\n`;

mapperStatements += `${responseType} ${toParamName(
responseType
)} = deserMapper.readValue(responseBodyString, ${mapperListHandle(
Expand Down
1 change: 1 addition & 0 deletions helpers/typeConvert.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const fromFormat = (propFormat, shouldBox) => {
case "double":
return shouldBox ? "Double" : "double";
case "date":
return "LocalDate";
case "date-time":
return "ZonedDateTime";
case "byte":
Expand Down
2 changes: 2 additions & 0 deletions template/ApiClient.java.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import java.time.ZonedDateTime;
import java.time.LocalDate;

import okhttp3.*;
import com.fasterxml.jackson.databind.*;
Expand Down Expand Up @@ -61,6 +62,7 @@ public class ApiClient{{_tag.name}} implements IApiClient{{_tag.name}} {
var requestUri = _baseAddress.concat("{{setPathParameters @root.path _sortedParameters}}"){{#if (queryParametersExist _sortedParameters)}}.concat(queryString.toString()){{/if}};
{{#if (bodyParameterExists _sortedParameters)}}
ObjectMapper serMapper = new ObjectMapper();
serMapper.findAndRegisterModules();
String jsonBody = serMapper.writeValueAsString(body);
RequestBody httpBody = RequestBody.create(jsonBody, MediaType.parse("application/json; charset=utf-8"));
{{/if}}
Expand Down
2 changes: 2 additions & 0 deletions template/ApiModel.java.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package {{_options.[generator.package]}};

import java.time.ZonedDateTime;
import java.util.List;
import java.time.LocalDate;


{{#each components.schemas}}
{{> model}}
Expand Down
2 changes: 1 addition & 1 deletion template/IApiClient.java.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.JsonMappingException;
import java.io.IOException;
import java.util.HashMap;
import java.time.ZonedDateTime;

import java.time.LocalDate;

// <summary>
// {{_info.title}}
Expand Down