From acdc5328fe5da0178024b721846912f08c749751 Mon Sep 17 00:00:00 2001 From: nmonterroso Date: Fri, 19 Jun 2015 11:24:56 -0700 Subject: [PATCH] deserialize thrown exceptions --- .../codegen/languages/PhpClientCodegen.java | 33 +++++++++++-------- .../src/main/resources/php/api.mustache | 25 +++++++++++--- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java index ad9ca3aa9b14..073c7ff1c96b 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java @@ -248,7 +248,26 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public Map postProcessOperations(Map objs) { objs = addNamespaces(super.postProcessOperations(objs)); + objs = formatImports(objs); + return objs; + } + + @Override + public Map postProcessSupportingFileData(Map objs) { + return addNamespaces(super.postProcessSupportingFileData(objs)); + } + + protected Map addNamespaces(Map objs) { + objs.put("rootNamespace", rootNamespace); + objs.put("invokerNamespace", invokerNamespace); + objs.put("apiNamespace", apiNamespace); + objs.put("modelNamespace", modelNamespace); + + return objs; + } + + protected Map formatImports(Map objs) { if (objs.containsKey("imports")) { List> imports = new ArrayList>(); LinkedHashMap newImport; @@ -273,18 +292,4 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig { return objs; } - - @Override - public Map postProcessSupportingFileData(Map objs) { - return addNamespaces(super.postProcessSupportingFileData(objs)); - } - - protected Map addNamespaces(Map objs) { - objs.put("rootNamespace", rootNamespace); - objs.put("invokerNamespace", invokerNamespace); - objs.put("apiNamespace", apiNamespace); - objs.put("modelNamespace", modelNamespace); - - return objs; - } } diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 5798ef6f8825..704f1c5ebab3 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -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}} }