Skip to content

Commit

Permalink
recursively add import for parameters (#5891)
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Jun 21, 2017
1 parent 45519c5 commit d35239c
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2410,7 +2410,12 @@ public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
p.baseType = pr.datatype;
p.isContainer = true;
p.isListContainer = true;
imports.add(pr.baseType);

// recursively add import
while (pr != null) {
imports.add(pr.baseType);
pr = pr.items;
}
} else if ("object".equals(type)) { // for map parameter
Property inner = qp.getItems();
if (inner == null) {
Expand All @@ -2424,7 +2429,11 @@ public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
p.baseType = pr.datatype;
p.isContainer = true;
p.isMapContainer = true;
imports.add(pr.baseType);
// recursively add import
while (pr != null) {
imports.add(pr.baseType);
pr = pr.items;
}
} else {
Map<PropertyId, Object> args = new HashMap<PropertyId, Object>();
String format = qp.getFormat();
Expand Down Expand Up @@ -2502,6 +2511,7 @@ public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
}

} else {
LOGGER.info("proessing body parameter ...");
if (!(param instanceof BodyParameter)) {
LOGGER.error("Cannot use Parameter " + param + " as Body Parameter");
}
Expand Down Expand Up @@ -2545,6 +2555,14 @@ public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
imports.add(cp.complexType);
}
imports.add(cp.baseType);

// recursively add import
CodegenProperty innerCp = cp;
while(innerCp != null) {
imports.add(innerCp.complexType);
innerCp = innerCp.items;
}

p.items = cp;
p.dataType = cp.datatype;
p.baseType = cp.complexType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,48 +671,56 @@ public <T> T invokeAPI(String path, String method, List<Pair> queryParams, Objec

Entity<?> entity = serialize(body, formParams, contentType);

Response response;

if ("GET".equals(method)) {
response = invocationBuilder.get();
} else if ("POST".equals(method)) {
response = invocationBuilder.post(entity);
} else if ("PUT".equals(method)) {
response = invocationBuilder.put(entity);
} else if ("DELETE".equals(method)) {
response = invocationBuilder.delete();
} else if ("PATCH".equals(method)) {
response = invocationBuilder.header("X-HTTP-Method-Override", "PATCH").post(entity);
} else {
throw new ApiException(500, "unknown method type " + method);
}
Response response = null;

try {
if ("GET".equals(method)) {
response = invocationBuilder.get();
} else if ("POST".equals(method)) {
response = invocationBuilder.post(entity);
} else if ("PUT".equals(method)) {
response = invocationBuilder.put(entity);
} else if ("DELETE".equals(method)) {
response = invocationBuilder.delete();
} else if ("PATCH".equals(method)) {
response = invocationBuilder.header("X-HTTP-Method-Override", "PATCH").post(entity);
} else {
throw new ApiException(500, "unknown method type " + method);
}

statusCode = response.getStatusInfo().getStatusCode();
responseHeaders = buildResponseHeaders(response);
statusCode = response.getStatusInfo().getStatusCode();
responseHeaders = buildResponseHeaders(response);

if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
return null;
} else if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) {
if (returnType == null)
if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
return null;
else
return deserialize(response, returnType);
} else {
String message = "error";
String respBody = null;
if (response.hasEntity()) {
try {
respBody = String.valueOf(response.readEntity(String.class));
message = respBody;
} catch (RuntimeException e) {
// e.printStackTrace();
} else if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) {
if (returnType == null)
return null;
else
return deserialize(response, returnType);
} else {
String message = "error";
String respBody = null;
if (response.hasEntity()) {
try {
respBody = String.valueOf(response.readEntity(String.class));
message = respBody;
} catch (RuntimeException e) {
// e.printStackTrace();
}
}
throw new ApiException(
response.getStatus(),
message,
buildResponseHeaders(response),
respBody);
}
} finally {
try {
response.close();
} catch (Exception e) {
// it's not critical, since the response object is local in method invokeAPI; that's fine, just continue
}
throw new ApiException(
response.getStatus(),
message,
buildResponseHeaders(response),
respBody);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,48 +671,56 @@ public <T> T invokeAPI(String path, String method, List<Pair> queryParams, Objec

Entity<?> entity = serialize(body, formParams, contentType);

Response response;

if ("GET".equals(method)) {
response = invocationBuilder.get();
} else if ("POST".equals(method)) {
response = invocationBuilder.post(entity);
} else if ("PUT".equals(method)) {
response = invocationBuilder.put(entity);
} else if ("DELETE".equals(method)) {
response = invocationBuilder.delete();
} else if ("PATCH".equals(method)) {
response = invocationBuilder.header("X-HTTP-Method-Override", "PATCH").post(entity);
} else {
throw new ApiException(500, "unknown method type " + method);
}
Response response = null;

try {
if ("GET".equals(method)) {
response = invocationBuilder.get();
} else if ("POST".equals(method)) {
response = invocationBuilder.post(entity);
} else if ("PUT".equals(method)) {
response = invocationBuilder.put(entity);
} else if ("DELETE".equals(method)) {
response = invocationBuilder.delete();
} else if ("PATCH".equals(method)) {
response = invocationBuilder.header("X-HTTP-Method-Override", "PATCH").post(entity);
} else {
throw new ApiException(500, "unknown method type " + method);
}

statusCode = response.getStatusInfo().getStatusCode();
responseHeaders = buildResponseHeaders(response);
statusCode = response.getStatusInfo().getStatusCode();
responseHeaders = buildResponseHeaders(response);

if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
return null;
} else if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) {
if (returnType == null)
if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
return null;
else
return deserialize(response, returnType);
} else {
String message = "error";
String respBody = null;
if (response.hasEntity()) {
try {
respBody = String.valueOf(response.readEntity(String.class));
message = respBody;
} catch (RuntimeException e) {
// e.printStackTrace();
} else if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) {
if (returnType == null)
return null;
else
return deserialize(response, returnType);
} else {
String message = "error";
String respBody = null;
if (response.hasEntity()) {
try {
respBody = String.valueOf(response.readEntity(String.class));
message = respBody;
} catch (RuntimeException e) {
// e.printStackTrace();
}
}
throw new ApiException(
response.getStatus(),
message,
buildResponseHeaders(response),
respBody);
}
} finally {
try {
response.close();
} catch (Exception e) {
// it's not critical, since the response object is local in method invokeAPI; that's fine, just continue
}
throw new ApiException(
response.getStatus(),
message,
buildResponseHeaders(response),
respBody);
}
}

Expand Down

0 comments on commit d35239c

Please sign in to comment.