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