From 67815ed5f2933ec7bc8a737dde70d76b4ccc1ec3 Mon Sep 17 00:00:00 2001 From: wing328 Date: Tue, 27 Oct 2015 19:22:25 +0800 Subject: [PATCH 1/3] add oauth support for php --- .../codegen/languages/PhpClientCodegen.java | 3 ++ .../src/main/resources/php/api.mustache | 4 +-- .../main/resources/php/configuration.mustache | 30 +++++++++++++++++++ .../php/SwaggerClient-php/lib/Api/PetApi.php | 14 ++++----- 4 files changed, 42 insertions(+), 9 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 538a5c494a6..7ce5a034474 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 @@ -333,6 +333,9 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig { // Note: backslash ("\\") is allowed for e.g. "\\DateTime" name = name.replaceAll("[^\\w\\\\]+", "_"); + // remove dollar sign + name = name.replaceAll("$", ""); + // model name cannot use reserved keyword if (reservedWords.contains(name)) { escapeReservedWord(name); // e.g. return => _return diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 78eaeb7cc6b..39c469e9851 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -170,8 +170,8 @@ use \{{invokerPackage}}\ObjectSerializer; if (isset($apiKey)) { {{#isKeyInHeader}}$headerParams['{{keyParamName}}'] = $apiKey;{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = $apiKey;{{/isKeyInQuery}} }{{/isApiKey}} - {{#isBasic}}$headerParams['Authorization'] = 'Basic '.base64_encode($this->apiClient->getConfig()->getUsername().":".$this->apiClient->getConfig()->getPassword());{{/isBasic}} - {{#isOAuth}}//TODO support oauth{{/isOAuth}} + {{#isBasic}}$headerParams['Authorization'] = 'Basic ' . base64_encode($this->apiClient->getConfig()->getUsername(). ":" .$this->apiClient->getConfig()->getPassword());{{/isBasic}} + {{#isOAuth}}$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken();{{/isOAuth}} {{/authMethods}} // make the API Call try diff --git a/modules/swagger-codegen/src/main/resources/php/configuration.mustache b/modules/swagger-codegen/src/main/resources/php/configuration.mustache index 96bc8a1b660..286ac8e2898 100644 --- a/modules/swagger-codegen/src/main/resources/php/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/php/configuration.mustache @@ -63,6 +63,13 @@ class Configuration */ protected $apiKeyPrefixes = array(); + /** + * Token for OAuth + * + * @var string + */ + protected $authToken = ''; + /** * Username for HTTP basic authentication * @@ -195,6 +202,29 @@ class Configuration return isset($this->apiKeyPrefixes[$apiKeyIdentifier]) ? $this->apiKeyPrefixes[$apiKeyIdentifier] : null; } + /** + * Sets the token for OAuth + * + * @param string $authToken Token for OAuth + * + * @return Configuration + */ + public function setAuthToken($authToken) + { + $this->$authToken = $authToken; + return $this; + } + + /** + * Gets the token for OAuth + * + * @return string Token for OAuth + */ + public function getAuthToken() + { + return $this->authToken; + } + /** * Sets the username for HTTP basic authentication * diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php index bcd91f4ffb8..cd2a3001052 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -136,7 +136,7 @@ class PetApi } - //TODO support oauth + $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken(); // make the API Call try @@ -201,7 +201,7 @@ class PetApi } - //TODO support oauth + $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken(); // make the API Call try @@ -265,7 +265,7 @@ class PetApi } - //TODO support oauth + $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken(); // make the API Call try @@ -341,7 +341,7 @@ class PetApi } - //TODO support oauth + $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken(); // make the API Call try @@ -527,7 +527,7 @@ class PetApi } - //TODO support oauth + $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken(); // make the API Call try @@ -603,7 +603,7 @@ class PetApi } - //TODO support oauth + $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken(); // make the API Call try @@ -695,7 +695,7 @@ class PetApi } - //TODO support oauth + $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken(); // make the API Call try From 964850a8de099ab9122e6fcb8d38181dde3469d6 Mon Sep 17 00:00:00 2001 From: wing328 Date: Wed, 28 Oct 2015 14:42:02 +0800 Subject: [PATCH 2/3] rename authToken to accessToken --- .../src/main/resources/php/api.mustache | 4 ++-- .../main/resources/php/configuration.mustache | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 39c469e9851..e3a9749c423 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -170,8 +170,8 @@ use \{{invokerPackage}}\ObjectSerializer; if (isset($apiKey)) { {{#isKeyInHeader}}$headerParams['{{keyParamName}}'] = $apiKey;{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = $apiKey;{{/isKeyInQuery}} }{{/isApiKey}} - {{#isBasic}}$headerParams['Authorization'] = 'Basic ' . base64_encode($this->apiClient->getConfig()->getUsername(). ":" .$this->apiClient->getConfig()->getPassword());{{/isBasic}} - {{#isOAuth}}$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken();{{/isOAuth}} + {{#isBasic}}$headerParams['Authorization'] = 'Basic ' . base64_encode($this->apiClient->getConfig()->getUsername() . ":" . $this->apiClient->getConfig()->getPassword());{{/isBasic}} + {{#isOAuth}}$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();{{/isOAuth}} {{/authMethods}} // make the API Call try diff --git a/modules/swagger-codegen/src/main/resources/php/configuration.mustache b/modules/swagger-codegen/src/main/resources/php/configuration.mustache index 286ac8e2898..14d7957fe54 100644 --- a/modules/swagger-codegen/src/main/resources/php/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/php/configuration.mustache @@ -64,11 +64,11 @@ class Configuration protected $apiKeyPrefixes = array(); /** - * Token for OAuth + * Access token for OAuth * * @var string */ - protected $authToken = ''; + protected $accessToken = ''; /** * Username for HTTP basic authentication @@ -203,26 +203,26 @@ class Configuration } /** - * Sets the token for OAuth + * Sets the access token for OAuth * - * @param string $authToken Token for OAuth + * @param string $accessToken Token for OAuth * * @return Configuration */ - public function setAuthToken($authToken) + public function setAccessToken($accessToken) { - $this->$authToken = $authToken; + $this->$accessToken = $accessToken; return $this; } /** - * Gets the token for OAuth + * Gets the access token for OAuth * - * @return string Token for OAuth + * @return string Access token for OAuth */ - public function getAuthToken() + public function getAccessToken() { - return $this->authToken; + return $this->accessToken; } /** From 6c12e5ac8bdc072375ed8edc556ecc0fc9c45198 Mon Sep 17 00:00:00 2001 From: wing328 Date: Wed, 28 Oct 2015 15:22:46 +0800 Subject: [PATCH 3/3] update php sample --- .../php/SwaggerClient-php/lib/Api/PetApi.php | 14 ++++----- .../SwaggerClient-php/lib/Configuration.php | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php index cd2a3001052..a418ac90b43 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -136,7 +136,7 @@ class PetApi } - $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken(); + $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken(); // make the API Call try @@ -201,7 +201,7 @@ class PetApi } - $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken(); + $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken(); // make the API Call try @@ -265,7 +265,7 @@ class PetApi } - $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken(); + $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken(); // make the API Call try @@ -341,7 +341,7 @@ class PetApi } - $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken(); + $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken(); // make the API Call try @@ -527,7 +527,7 @@ class PetApi } - $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken(); + $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken(); // make the API Call try @@ -603,7 +603,7 @@ class PetApi } - $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken(); + $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken(); // make the API Call try @@ -695,7 +695,7 @@ class PetApi } - $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAuthToken(); + $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken(); // make the API Call try diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php index ad715e75994..1fdac785bfd 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php @@ -63,6 +63,13 @@ class Configuration */ protected $apiKeyPrefixes = array(); + /** + * Access token for OAuth + * + * @var string + */ + protected $accessToken = ''; + /** * Username for HTTP basic authentication * @@ -195,6 +202,29 @@ class Configuration return isset($this->apiKeyPrefixes[$apiKeyIdentifier]) ? $this->apiKeyPrefixes[$apiKeyIdentifier] : null; } + /** + * Sets the access token for OAuth + * + * @param string $accessToken Token for OAuth + * + * @return Configuration + */ + public function setAccessToken($accessToken) + { + $this->$accessToken = $accessToken; + return $this; + } + + /** + * Gets the access token for OAuth + * + * @return string Access token for OAuth + */ + public function getAccessToken() + { + return $this->accessToken; + } + /** * Sets the username for HTTP basic authentication *