diff --git a/modules/openapi-generator/src/main/resources/php/Configuration.mustache b/modules/openapi-generator/src/main/resources/php/Configuration.mustache index 35a4ab5c5e89..23e1e74474f0 100644 --- a/modules/openapi-generator/src/main/resources/php/Configuration.mustache +++ b/modules/openapi-generator/src/main/resources/php/Configuration.mustache @@ -46,7 +46,7 @@ class Configuration protected $apiKeyPrefixes = []; /** - * Access token for OAuth + * Access token for OAuth/Bearer authentication * * @var string */ diff --git a/modules/openapi-generator/src/main/resources/php/README.mustache b/modules/openapi-generator/src/main/resources/php/README.mustache index a617b0547e0d..573e02aa2626 100644 --- a/modules/openapi-generator/src/main/resources/php/README.mustache +++ b/modules/openapi-generator/src/main/resources/php/README.mustache @@ -66,19 +66,9 @@ Please follow the [installation procedure](#installation--usage) and then run th ```php setUsername('YOUR_USERNAME') - ->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');{{/isApiKey}}{{#isOAuth}} -// Configure OAuth2 access token for authorization: {{{name}}} -$config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');{{/isOAuth}}{{/authMethods}} -{{/hasAuthMethods}} +{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}} +{{> php_doc_auth_partial}} $apiInstance = new {{invokerPackage}}\Api\{{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. @@ -114,21 +104,33 @@ Class | Method | HTTP request | Description ## Documentation For Authorization -{{^authMethods}} All endpoints do not require authorization. -{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}} -{{#authMethods}}## {{{name}}} +{{^authMethods}} +All endpoints do not require authorization. +{{/authMethods}} +{{#authMethods}} +{{#last}} Authentication schemes defined for the API:{{/last}} +## {{{name}}} -{{#isApiKey}}- **Type**: API key +{{#isApiKey}} +- **Type**: API key - **API key parameter name**: {{{keyParamName}}} - **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} {{/isApiKey}} -{{#isBasic}}- **Type**: HTTP basic authentication +{{#isBasic}} +{{^isBasicBearer}} +- **Type**: HTTP basic authentication +{{/isBasicBearer}} +{{#isBasicBearer}} +- **Type**: Bearer authentication{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} +{{/isBasicBearer}} {{/isBasic}} -{{#isOAuth}}- **Type**: OAuth +{{#isOAuth}} +- **Type**: OAuth - **Flow**: {{{flow}}} - **Authorization URL**: {{{authorizationUrl}}} - **Scopes**: {{^scopes}}N/A{{/scopes}} -{{#scopes}} - **{{{scope}}}**: {{{description}}} +{{#scopes}} +- **{{{scope}}}**: {{{description}}} {{/scopes}} {{/isOAuth}} diff --git a/modules/openapi-generator/src/main/resources/php/api.mustache b/modules/openapi-generator/src/main/resources/php/api.mustache index 9329db910b78..72e7ccd723b2 100644 --- a/modules/openapi-generator/src/main/resources/php/api.mustache +++ b/modules/openapi-generator/src/main/resources/php/api.mustache @@ -506,10 +506,18 @@ use {{invokerPackage}}\ObjectSerializer; } {{/isApiKey}} {{#isBasic}} + {{^isBasicBearer}} // this endpoint requires HTTP basic authentication if ($this->config->getUsername() !== null || $this->config->getPassword() !== null) { $headers['Authorization'] = 'Basic ' . base64_encode($this->config->getUsername() . ":" . $this->config->getPassword()); } + {{/isBasicBearer}} + {{#isBasicBearer}} + // this endpoint requires Bearer{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} authentication (access token) + if ($this->config->getAccessToken() !== null) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } + {{/isBasicBearer}} {{/isBasic}} {{#isOAuth}} // this endpoint requires OAuth (access token) diff --git a/modules/openapi-generator/src/main/resources/php/api_doc.mustache b/modules/openapi-generator/src/main/resources/php/api_doc.mustache index 262fcb8f3271..8dfc0c09bc6c 100644 --- a/modules/openapi-generator/src/main/resources/php/api_doc.mustache +++ b/modules/openapi-generator/src/main/resources/php/api_doc.mustache @@ -22,27 +22,7 @@ Method | HTTP request | Description setUsername('YOUR_USERNAME') - ->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'); -{{/isApiKey}} -{{#isOAuth}} -// Configure OAuth2 access token for authorization: {{{name}}} -$config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); -{{/isOAuth}} -{{/authMethods}} - -{{/hasAuthMethods}} +{{> php_doc_auth_partial}} $apiInstance = new {{invokerPackage}}\Api\{{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. diff --git a/modules/openapi-generator/src/main/resources/php/php_doc_auth_partial.mustache b/modules/openapi-generator/src/main/resources/php/php_doc_auth_partial.mustache new file mode 100644 index 000000000000..1c4696ab1884 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/php/php_doc_auth_partial.mustache @@ -0,0 +1,27 @@ +{{#hasAuthMethods}} +{{#authMethods}} +{{#isBasic}} +{{^isBasicBearer}} +// Configure HTTP basic authorization: {{{name}}} +$config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration() + ->setUsername('YOUR_USERNAME') + ->setPassword('YOUR_PASSWORD'); +{{/isBasicBearer}} +{{#isBasicBearer}} +// Configure Bearer{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} authorization: {{{name}}} +$config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); +{{/isBasicBearer}} +{{/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'); +{{/isApiKey}} +{{#isOAuth}} +// Configure OAuth2 access token for authorization: {{{name}}} +$config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); +{{/isOAuth}} + +{{/authMethods}} +{{/hasAuthMethods}} diff --git a/samples/client/petstore/php/OpenAPIClient-php/README.md b/samples/client/petstore/php/OpenAPIClient-php/README.md index 10e87b292a8a..e8f03bfa9867 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/README.md +++ b/samples/client/petstore/php/OpenAPIClient-php/README.md @@ -56,6 +56,8 @@ Please follow the [installation procedure](#installation--usage) and then run th setUsername('YOUR_USERNAME') ->setPassword('YOUR_PASSWORD'); + $apiInstance = new OpenAPI\Client\Api\FakeApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -500,6 +509,7 @@ To test enum parameters setApiKey('ap // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api_key_query', 'Bearer'); + $apiInstance = new OpenAPI\Client\Api\FakeClassnameTags123Api( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. diff --git a/samples/client/petstore/php/OpenAPIClient-php/docs/Api/PetApi.md b/samples/client/petstore/php/OpenAPIClient-php/docs/Api/PetApi.md index 8b2f55139f7b..690cbad82dff 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/docs/Api/PetApi.md +++ b/samples/client/petstore/php/OpenAPIClient-php/docs/Api/PetApi.md @@ -28,6 +28,7 @@ require_once(__DIR__ . '/vendor/autoload.php'); // Configure OAuth2 access token for authorization: petstore_auth $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); + $apiInstance = new OpenAPI\Client\Api\PetApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -78,6 +79,7 @@ require_once(__DIR__ . '/vendor/autoload.php'); // Configure OAuth2 access token for authorization: petstore_auth $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); + $apiInstance = new OpenAPI\Client\Api\PetApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -132,6 +134,7 @@ require_once(__DIR__ . '/vendor/autoload.php'); // Configure OAuth2 access token for authorization: petstore_auth $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); + $apiInstance = new OpenAPI\Client\Api\PetApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -185,6 +188,7 @@ require_once(__DIR__ . '/vendor/autoload.php'); // Configure OAuth2 access token for authorization: petstore_auth $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); + $apiInstance = new OpenAPI\Client\Api\PetApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -240,6 +244,7 @@ $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setApiKey('ap // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api_key', 'Bearer'); + $apiInstance = new OpenAPI\Client\Api\PetApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -291,6 +296,7 @@ require_once(__DIR__ . '/vendor/autoload.php'); // Configure OAuth2 access token for authorization: petstore_auth $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); + $apiInstance = new OpenAPI\Client\Api\PetApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -341,6 +347,7 @@ require_once(__DIR__ . '/vendor/autoload.php'); // Configure OAuth2 access token for authorization: petstore_auth $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); + $apiInstance = new OpenAPI\Client\Api\PetApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -395,6 +402,7 @@ require_once(__DIR__ . '/vendor/autoload.php'); // Configure OAuth2 access token for authorization: petstore_auth $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); + $apiInstance = new OpenAPI\Client\Api\PetApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -450,6 +458,7 @@ require_once(__DIR__ . '/vendor/autoload.php'); // Configure OAuth2 access token for authorization: petstore_auth $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); + $apiInstance = new OpenAPI\Client\Api\PetApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. diff --git a/samples/client/petstore/php/OpenAPIClient-php/docs/Api/StoreApi.md b/samples/client/petstore/php/OpenAPIClient-php/docs/Api/StoreApi.md index 8dbdc81fe260..de83fe032553 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/docs/Api/StoreApi.md +++ b/samples/client/petstore/php/OpenAPIClient-php/docs/Api/StoreApi.md @@ -22,6 +22,7 @@ For valid response try integer IDs with value < 1000. Anything above 1000 or non setApiKey('ap // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api_key', 'Bearer'); + $apiInstance = new OpenAPI\Client\Api\StoreApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -121,6 +123,7 @@ For valid response try integer IDs with value <= 5 or > 10. Other values will ge setUsername('YOUR_USERNAME') ->setPassword('YOUR_PASSWORD'); + $apiInstance = new OpenAPI\Client\Api\FakeApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -451,6 +459,7 @@ To test enum parameters setUsername('YOUR_USERNAME') - ->setPassword('YOUR_PASSWORD'); +// Configure Bearer (JWT) authorization: bearer_test +$config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); + $apiInstance = new OpenAPI\Client\Api\FakeApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. @@ -577,6 +585,7 @@ test inline additionalProperties setApiKey('ap // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api_key_query', 'Bearer'); + $apiInstance = new OpenAPI\Client\Api\FakeClassnameTags123Api( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/docs/Api/PetApi.md b/samples/openapi3/client/petstore/php/OpenAPIClient-php/docs/Api/PetApi.md index ebd48de8fe3b..7744b3c1a777 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/docs/Api/PetApi.md +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/docs/Api/PetApi.md @@ -28,6 +28,7 @@ require_once(__DIR__ . '/vendor/autoload.php'); // Configure OAuth2 access token for authorization: petstore_auth $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); + $apiInstance = new OpenAPI\Client\Api\PetApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -78,6 +79,7 @@ require_once(__DIR__ . '/vendor/autoload.php'); // Configure OAuth2 access token for authorization: petstore_auth $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); + $apiInstance = new OpenAPI\Client\Api\PetApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -132,6 +134,7 @@ require_once(__DIR__ . '/vendor/autoload.php'); // Configure OAuth2 access token for authorization: petstore_auth $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); + $apiInstance = new OpenAPI\Client\Api\PetApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -185,6 +188,7 @@ require_once(__DIR__ . '/vendor/autoload.php'); // Configure OAuth2 access token for authorization: petstore_auth $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); + $apiInstance = new OpenAPI\Client\Api\PetApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -240,6 +244,7 @@ $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setApiKey('ap // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api_key', 'Bearer'); + $apiInstance = new OpenAPI\Client\Api\PetApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -291,6 +296,7 @@ require_once(__DIR__ . '/vendor/autoload.php'); // Configure OAuth2 access token for authorization: petstore_auth $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); + $apiInstance = new OpenAPI\Client\Api\PetApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -341,6 +347,7 @@ require_once(__DIR__ . '/vendor/autoload.php'); // Configure OAuth2 access token for authorization: petstore_auth $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); + $apiInstance = new OpenAPI\Client\Api\PetApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -395,6 +402,7 @@ require_once(__DIR__ . '/vendor/autoload.php'); // Configure OAuth2 access token for authorization: petstore_auth $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); + $apiInstance = new OpenAPI\Client\Api\PetApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -450,6 +458,7 @@ require_once(__DIR__ . '/vendor/autoload.php'); // Configure OAuth2 access token for authorization: petstore_auth $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); + $apiInstance = new OpenAPI\Client\Api\PetApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/docs/Api/StoreApi.md b/samples/openapi3/client/petstore/php/OpenAPIClient-php/docs/Api/StoreApi.md index c607217ea449..7f7a1952b0aa 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/docs/Api/StoreApi.md +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/docs/Api/StoreApi.md @@ -22,6 +22,7 @@ For valid response try integer IDs with value < 1000. Anything above 1000 or non setApiKey('ap // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api_key', 'Bearer'); + $apiInstance = new OpenAPI\Client\Api\StoreApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. @@ -121,6 +123,7 @@ For valid response try integer IDs with value <= 5 or > 10. Other values will ge config->getUsername() !== null || $this->config->getPassword() !== null) { - $headers['Authorization'] = 'Basic ' . base64_encode($this->config->getUsername() . ":" . $this->config->getPassword()); + // this endpoint requires Bearer (JWT) authentication (access token) + if ($this->config->getAccessToken() !== null) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); } $defaultHeaders = []; diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Configuration.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Configuration.php index a45e571f6fb0..5a6bf9617594 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Configuration.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Configuration.php @@ -56,7 +56,7 @@ class Configuration protected $apiKeyPrefixes = []; /** - * Access token for OAuth + * Access token for OAuth/Bearer authentication * * @var string */