forked from loafle/openapi-generator-original
deserialize thrown exceptions
This commit is contained in:
@@ -248,7 +248,26 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
objs = addNamespaces(super.postProcessOperations(objs));
|
||||
objs = formatImports(objs);
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||
return addNamespaces(super.postProcessSupportingFileData(objs));
|
||||
}
|
||||
|
||||
protected Map<String, Object> addNamespaces(Map<String, Object> objs) {
|
||||
objs.put("rootNamespace", rootNamespace);
|
||||
objs.put("invokerNamespace", invokerNamespace);
|
||||
objs.put("apiNamespace", apiNamespace);
|
||||
objs.put("modelNamespace", modelNamespace);
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
protected Map<String, Object> formatImports(Map<String, Object> objs) {
|
||||
if (objs.containsKey("imports")) {
|
||||
List<Map<String, String>> imports = new ArrayList<Map<String, String>>();
|
||||
LinkedHashMap<String, String> newImport;
|
||||
@@ -273,18 +292,4 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||
return addNamespaces(super.postProcessSupportingFileData(objs));
|
||||
}
|
||||
|
||||
protected Map<String, Object> addNamespaces(Map<String, Object> objs) {
|
||||
objs.put("rootNamespace", rootNamespace);
|
||||
objs.put("invokerNamespace", invokerNamespace);
|
||||
objs.put("apiNamespace", apiNamespace);
|
||||
objs.put("modelNamespace", modelNamespace);
|
||||
|
||||
return objs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace {{apiNamespace}};
|
||||
|
||||
use {{invokerNamespace}}\Configuration;
|
||||
use {{invokerNamespace}}\ApiClient;
|
||||
use {{invokerNamespace}}\ApiException;
|
||||
|
||||
{{#imports}}
|
||||
use {{{import}}};
|
||||
@@ -128,16 +129,30 @@ class {{classname}} {
|
||||
$authSettings = array({{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}});
|
||||
|
||||
// make the API Call
|
||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams, $authSettings);
|
||||
try {
|
||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams, $authSettings);
|
||||
} catch (ApiException $e) {
|
||||
$throw = $e;
|
||||
|
||||
{{#returnType}}if(! $response) {
|
||||
switch ($e->getCode()) { {{#responses}}{{#dataType}}
|
||||
case {{code}}:
|
||||
$data = $this->apiClient->deserialize($e->getResponseBody(), '{{dataType}}');
|
||||
$throw = new ApiException("{{message}}", $e->getCode(), $e->getResponseHeaders(), $data);
|
||||
break;{{/dataType}}{{/responses}}
|
||||
}
|
||||
|
||||
throw $throw;
|
||||
}
|
||||
{{#returnType}}
|
||||
if(!$response) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$responseObject = $this->apiClient->deserialize($response,'{{returnType}}');
|
||||
return $responseObject;{{/returnType}}
|
||||
return $responseObject;
|
||||
{{/returnType}}
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user