Skip to content

Commit

Permalink
Merge pull request #283 from swagger-api/issue-8722
Browse files Browse the repository at this point in the history
Issue 8722
  • Loading branch information
HugoMario authored Jan 25, 2019
2 parents 820f9f9 + a0e4394 commit 2cdbb45
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 286 deletions.
4 changes: 2 additions & 2 deletions src/main/resources/handlebars/php/ObjectSerializer.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class ObjectSerializer
// determine file name
if (array_key_exists('Content-Disposition', $httpHeaders) &&
preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match)) {
$filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . self::sanitizeFilename($match[1]);
$filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . DIRECTORY_SEPARATOR . self::sanitizeFilename($match[1]);
} else {
$filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), '');
}
Expand All @@ -283,7 +283,7 @@ class ObjectSerializer
// If a discriminator is defined and points to a valid subclass, use it.
$discriminator = $class::DISCRIMINATOR;
if (!empty($discriminator) && isset($data->{$discriminator}) && is_string($data->{$discriminator})) {
$subclass = '{{backslash}}{{invokerPackage}}\Model\\' . $data->{$discriminator};
$subclass = '\{{invokerPackage}}\Model\\' . $data->{$discriminator};
if (is_subclass_of($subclass, $class)) {
$class = $subclass;
}
Expand Down
50 changes: 26 additions & 24 deletions src/main/resources/handlebars/php/README.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# {{packagePath}}
{{#appDescription}}{{{appDescription}}}{{/appDescription}}
{{#appDescription}}
{{{appDescription}}}
{{/appDescription}}

This PHP package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:

Expand Down Expand Up @@ -64,34 +66,35 @@ Please follow the [installation procedure](#installation--usage) and then run th
```php
<?php
require_once(__DIR__ . '/vendor/autoload.php');
{{#apiInfo}}{{#apis}}{{#@first}}{{#operations}}{{#operation}}{{#@first}}{{#has ../this 'auth-methods'}}{{#authMethods}}{{#is this 'basic'}}
{{#apiInfo}}{{#apis}}{{#@first}}{{#operations}}{{#operation}}{{#contents}}{{#@first}}{{#hasAuthMethods}}{{#authMethods}}{{#isBasic}}
// Configure HTTP basic authorization: {{{name}}}
$config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()
->setUsername('YOUR_USERNAME')
->setPassword('YOUR_PASSWORD');{{/is}}{{#is this 'api-key'}}
->setPassword('YOUR_PASSWORD');{{/isBasic}}{{#isApiKey}}
// Configure API key authorization: {{{name}}}
$config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setApiKey('{{{keyParamName}}}', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setApiKeyPrefix('{{{keyParamName}}}', 'Bearer');{{/is}}{{#is this 'oauth'}}
// $config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setApiKeyPrefix('{{{keyParamName}}}', 'Bearer');{{/isApiKey}}{{#isOAuth}}
// Configure OAuth2 access token for authorization: {{{name}}}
$config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');{{/is}}{{/authMethods}}
{{/has}}
$config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');{{/isOAuth}}{{/authMethods}}
{{/hasAuthMethods}}

$apiInstance = new {{concat apiPackage '\\' classname}}(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(){{#has ../this 'auth-methods'}},
$config{{/has}}
new GuzzleHttp\Client(){{#hasAuthMethods}},
$config{{/hasAuthMethods}}
);
{{#allParams}}${{paramName}} = {{{example}}}; // {{{dataType}}} | {{{description}}}
{{/allParams}}
{{#parameters}}${{paramName}} = {{{example}}}; // {{{dataType}}} | {{{description}}}
{{/parameters}}

try {
{{#returnType}}$result = {{/returnType}}$apiInstance->{{{operationId}}}({{#allParams}}${{paramName}}{{#has this 'more'}}, {{/has}}{{/allParams}});{{#returnType}}
{{#returnType}}$result = {{/returnType}}$apiInstance->{{{operationId}}}({{#parameters}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}});{{#returnType}}
print_r($result);{{/returnType}}
} catch (Exception $e) {
echo 'Exception when calling {{classname}}->{{operationId}}: ', $e->getMessage(), PHP_EOL;
}
{{/@first}}{{/operation}}{{/operations}}{{/@first}}{{/apis}}{{/apiInfo}}
{{/@first}}{{/contents}}{{/operation}}{{/operations}}{{/@first}}{{/apis}}{{/apiInfo}}
?>
```

Expand All @@ -115,25 +118,24 @@ Class | Method | HTTP request | Description
{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}}
{{#authMethods}}## {{{name}}}

{{#is this 'api-key'}}- **Type**: API key
{{#isApiKey}}- **Type**: API key
- **API key parameter name**: {{{keyParamName}}}
- **Location**: {{#is this 'key-in-query'}}URL query string{{/is}}{{#is this 'key-in-header'}}HTTP header{{/is}}
{{/is}}
{{#is this 'basic'}}- **Type**: HTTP basic authentication
{{/is}}
{{#is this 'oauth'}}- **Type**: OAuth
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
{{/isApiKey}}
{{#isBasic}}- **Type**: HTTP basic authentication
{{/isBasic}}
{{#isOAuth}}- **Type**: OAuth
- **Flow**: {{{flow}}}
- **Authorization URL**: {{{authorizationUrl}}}
- **Scopes**: {{^scopes}}N/A{{/scopes}}

{{#each scopes}} - **{{{@key}}}**: {{this}}
{{/each}}
{{/is}}
{{#scopes}} - **{{{scope}}}**: {{{description}}}
{{/scopes}}
{{/isOAuth}}

{{/authMethods}}

## Author

{{#apiInfo}}{{#apis}}{{#has ../../../this 'more'}}{{infoEmail}}
{{/has}}{{/apis}}{{/apiInfo}}
{{#apiInfo}}{{#apis}}{{^hasMore}}{{infoEmail}}
{{/hasMore}}{{/apis}}{{/apiInfo}}

Loading

0 comments on commit 2cdbb45

Please sign in to comment.