Add Bearer authentication support to Python client (#1999)

* add bearer auth support to python

* add bearer auth support to python

* update python oas2 petstore samples

* update samples

* add bearer format

* update php symfony samle
This commit is contained in:
William Cheng 2019-01-30 22:16:53 +08:00 committed by GitHub
parent 77d2de4e3d
commit 2eb99f602a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 294 additions and 89 deletions

View File

@ -29,6 +29,7 @@ public class CodegenSecurity {
public Boolean hasMore, isBasic, isOAuth, isApiKey;
// is Basic is true for all http authentication type. Those are to differentiate basic and bearer authentication
public Boolean isBasicBasic, isBasicBearer;
public String bearerFormat;
public Map<String, Object> vendorExtensions = new HashMap<String, Object>();
// ApiKey specific
public String keyParamName;
@ -58,6 +59,12 @@ public class CodegenSecurity {
return false;
if (isBasic != null ? !isBasic.equals(that.isBasic) : that.isBasic != null)
return false;
if (isBasicBasic != null ? !isBasicBasic.equals(that.isBasicBasic) : that.isBasicBasic != null)
return false;
if (isBasicBearer != null ? !isBasicBearer.equals(that.isBasicBearer) : that.isBasicBearer != null)
return false;
if (bearerFormat != null ? !bearerFormat.equals(that.bearerFormat) : that.bearerFormat != null)
return false;
if (isOAuth != null ? !isOAuth.equals(that.isOAuth) : that.isOAuth != null)
return false;
if (isApiKey != null ? !isApiKey.equals(that.isApiKey) : that.isApiKey != null)
@ -94,6 +101,9 @@ public class CodegenSecurity {
result = 31 * result + (type != null ? type.hashCode() : 0);
result = 31 * result + (hasMore != null ? hasMore.hashCode() : 0);
result = 31 * result + (isBasic != null ? isBasic.hashCode() : 0);
result = 31 * result + (isBasicBasic != null ? isBasicBasic.hashCode() : 0);
result = 31 * result + (isBasicBearer != null ? isBasicBearer.hashCode() : 0);
result = 31 * result + (bearerFormat != null ? bearerFormat.hashCode() : 0);
result = 31 * result + (isOAuth != null ? isOAuth.hashCode() : 0);
result = 31 * result + (isApiKey != null ? isApiKey.hashCode() : 0);
result = 31 * result + (vendorExtensions != null ? vendorExtensions.hashCode() : 0);

View File

@ -3124,6 +3124,7 @@ public class DefaultCodegen implements CodegenConfig {
}
else if ("bearer".equals(securityScheme.getScheme())) {
cs.isBasicBearer = true;
cs.bearerFormat = securityScheme.getBearerFormat();
}
} else if (SecurityScheme.Type.OAUTH2.equals(securityScheme.getType())) {
cs.isKeyInHeader = cs.isKeyInQuery = cs.isKeyInCookie = cs.isApiKey = cs.isBasic = false;

View File

@ -841,6 +841,10 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
bundle.put("hasOAuthMethods", true);
bundle.put("oauthMethods", getOAuthMethods(authMethods));
}
if (hasBearerMethods(authMethods)) {
bundle.put("hasBearerMethods", true);
}
}
List<CodegenServer> servers = config.fromServers(openAPI.getServers());
@ -1194,6 +1198,16 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
return false;
}
private boolean hasBearerMethods(List<CodegenSecurity> authMethods) {
for (CodegenSecurity cs : authMethods) {
if (cs.isBasicBearer) {
return true;
}
}
return false;
}
private List<CodegenSecurity> getOAuthMethods(List<CodegenSecurity> authMethods) {
List<CodegenSecurity> oauthMethods = new ArrayList<>();

View File

@ -60,4 +60,28 @@ public class ProcessUtils {
return false;
}
/**
* Returns true if at least one operation has Bearer security schema defined
*
* @param objs Map of operations
* @return True if at least one operation has Bearer security schema defined
*/
public static boolean hasBearerMethods(Map<String, Object> objs) {
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
if (operations != null) {
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
for (CodegenOperation operation : ops) {
if (operation.authMethods != null && !operation.authMethods.isEmpty()) {
for (CodegenSecurity cs : operation.authMethods) {
if (cs.isBasicBearer) {
return true;
}
}
}
}
}
return false;
}
}

View File

@ -18,8 +18,23 @@ Method | HTTP request | Description
{{{notes}}}{{/notes}}
### Example
{{#hasAuthMethods}}{{#authMethods}}
{{#isBasic}}* Basic Authentication ({{name}}): {{/isBasic }}{{#isApiKey}}* Api Key Authentication ({{name}}): {{/isApiKey }}{{#isOAuth}}* OAuth Authentication ({{name}}): {{/isOAuth }}
{{#hasAuthMethods}}
{{#authMethods}}
{{#isBasic}}
{{^isBasicBearer}}
* Basic Authentication ({{name}}):
{{/isBasicBearer}}
{{#isBasicBearer}}
* Bearer{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} Authentication ({{name}}):
{{/isBasicBearer}}
{{/isBasic}}
{{#isApiKey}}
* Api Key Authentication ({{name}}):
{{/isApiKey }}
{{#isOAuth}}
* OAuth Authentication ({{name}}):
{{/isOAuth }}
{{> api_doc_example }}
{{/authMethods}}
{{/hasAuthMethods}}

View File

@ -4,25 +4,14 @@ import time
import {{{packageName}}}
from {{{packageName}}}.rest import ApiException
from pprint import pprint
{{> python_doc_auth_partial}}
{{#hasAuthMethods}}
configuration = {{{packageName}}}.Configuration(){{#isBasic}}
# Configure HTTP basic authorization: {{{name}}}
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'{{/isBasic}}{{#isApiKey}}
# Configure API key authorization: {{{name}}}
configuration.api_key['{{{keyParamName}}}'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['{{{keyParamName}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}}
# Configure OAuth2 access token for authorization: {{{name}}}
configuration.access_token = 'YOUR_ACCESS_TOKEN'{{/isOAuth}}
# create an instance of the API class
api_instance = {{{packageName}}}.{{{classname}}}({{{packageName}}}.ApiClient(configuration))
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
{{/allParams}}
{{/hasAuthMethods}}
{{^hasAuthMethods}}
# create an instance of the API class
api_instance = {{{packageName}}}.{{{classname}}}()
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}

View File

@ -4,19 +4,8 @@ import time
import {{{packageName}}}
from {{{packageName}}}.rest import ApiException
from pprint import pprint
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}}{{#authMethods}}
configuration = {{{packageName}}}.Configuration(){{#isBasic}}
# Configure HTTP basic authorization: {{{name}}}
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'{{/isBasic}}{{#isApiKey}}
# Configure API key authorization: {{{name}}}
configuration.api_key['{{{keyParamName}}}'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['{{{keyParamName}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}}
# Configure OAuth2 access token for authorization: {{{name}}}
configuration.access_token = 'YOUR_ACCESS_TOKEN'{{/isOAuth}}{{/authMethods}}
{{/hasAuthMethods}}
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}
{{> python_doc_auth_partial}}
# create an instance of the API class
api_instance = {{{packageName}}}.{{{classname}}}({{{packageName}}}.ApiClient(configuration))
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
@ -47,17 +36,28 @@ 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}}

View File

@ -51,10 +51,16 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
self.username = ""
# Password for HTTP basic authentication
self.password = ""
{{#authMethods}}{{#isOAuth}}
# access token for OAuth
{{#hasOAuthMethods}}
# access token for OAuth/Bearer
self.access_token = ""
{{/isOAuth}}{{/authMethods}}
{{/hasOAuthMethods}}
{{^hasOAuthMethods}}
{{#hasBearerMethods}}
# access token for OAuth/Bearer
self.access_token = ""
{{/hasBearerMethods}}
{{/hasOAuthMethods}}
# Logging Settings
self.logger = {}
self.logger["package_logger"] = logging.getLogger("{{packageName}}")
@ -218,6 +224,7 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
},
{{/isApiKey}}
{{#isBasic}}
{{^isBasicBearer}}
'{{name}}':
{
'type': 'basic',
@ -225,7 +232,21 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
'key': 'Authorization',
'value': self.get_basic_auth_token()
},
{{/isBasic}}{{#isOAuth}}
{{/isBasicBearer}}
{{#isBasicBearer}}
'{{name}}':
{
'type': 'bearer',
'in': 'header',
{{#bearerFormat}}
'format': '{{{.}}}',
{{/bearerFormat}}
'key': 'Authorization',
'value': 'Bearer ' + self.access_token
},
{{/isBasicBearer}}
{{/isBasic}}
{{#isOAuth}}
'{{name}}':
{
'type': 'oauth2',
@ -233,7 +254,8 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
'key': 'Authorization',
'value': 'Bearer ' + self.access_token
},
{{/isOAuth}}{{/authMethods}}
{{/isOAuth}}
{{/authMethods}}
}
def to_debug_report(self):

View File

@ -0,0 +1,26 @@
{{#hasAuthMethods}}
{{#authMethods}}
configuration = {{{packageName}}}.Configuration()
{{#isBasic}}
{{^isBasicBearer}}
# Configure HTTP basic authorization: {{{name}}}
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'
{{/isBasicBearer}}
{{#isBasicBearer}}
# Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}}
configuration.access_token = 'YOUR_BEARER_TOKEN'
{{/isBasicBearer}}
{{/isBasic}}
{{#isApiKey}}
# Configure API key authorization: {{{name}}}
configuration.api_key['{{{keyParamName}}}'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['{{{keyParamName}}}'] = 'Bearer'
{{/isApiKey}}
{{#isOAuth}}
# Configure OAuth2 access token for authorization: {{{name}}}
configuration.access_token = 'YOUR_ACCESS_TOKEN'
{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}

View File

@ -768,6 +768,8 @@ paths:
delete:
tags:
- fake
security:
- bearer_test: []
summary: Fake endpoint to test group parameters (optional)
description: Fake endpoint to test group parameters (optional)
operationId: testGroupParameters
@ -1096,6 +1098,10 @@ components:
http_basic_test:
type: http
scheme: basic
bearer_test:
type: http
scheme: bearer
bearerFormat: JWT
schemas:
Foo:
type: object

View File

@ -51,6 +51,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint
# create an instance of the API class
api_instance = petstore_api.AnotherFakeApi(petstore_api.ApiClient(configuration))
body = petstore_api.Client() # Client | client model
@ -158,16 +159,19 @@ Class | Method | HTTP request | Description
- **API key parameter name**: api_key
- **Location**: HTTP header
## api_key_query
- **Type**: API key
- **API key parameter name**: api_key_query
- **Location**: URL query string
## http_basic_test
- **Type**: HTTP basic authentication
## petstore_auth
- **Type**: OAuth

View File

@ -15,6 +15,7 @@ To test special tags
To test special tags and operation ID starting with number
### Example
```python
from __future__ import print_function
import time

View File

@ -27,6 +27,7 @@ creates an XmlItem
this route creates an XmlItem
### Example
```python
from __future__ import print_function
import time
@ -74,6 +75,7 @@ No authorization required
Test serialization of outer boolean types
### Example
```python
from __future__ import print_function
import time
@ -121,6 +123,7 @@ No authorization required
Test serialization of object with outer number type
### Example
```python
from __future__ import print_function
import time
@ -168,6 +171,7 @@ No authorization required
Test serialization of outer number types
### Example
```python
from __future__ import print_function
import time
@ -215,6 +219,7 @@ No authorization required
Test serialization of outer string types
### Example
```python
from __future__ import print_function
import time
@ -262,6 +267,7 @@ No authorization required
For this test, the body for this request much reference a schema named `File`.
### Example
```python
from __future__ import print_function
import time
@ -306,6 +312,7 @@ No authorization required
### Example
```python
from __future__ import print_function
import time
@ -354,6 +361,7 @@ To test \"client\" model
To test \"client\" model
### Example
```python
from __future__ import print_function
import time
@ -403,7 +411,7 @@ Fake endpoint for testing various parameters 假端點 偽のエンドポイン
### Example
* Basic Authentication (http_basic_test):
* Basic Authentication (http_basic_test):
```python
from __future__ import print_function
import time
@ -481,6 +489,7 @@ To test enum parameters
To test enum parameters
### Example
```python
from __future__ import print_function
import time
@ -542,6 +551,7 @@ Fake endpoint to test group parameters (optional)
Fake endpoint to test group parameters (optional)
### Example
```python
from __future__ import print_function
import time
@ -597,6 +607,7 @@ No authorization required
test inline additionalProperties
### Example
```python
from __future__ import print_function
import time
@ -642,6 +653,7 @@ No authorization required
test json serialization of form data
### Example
```python
from __future__ import print_function
import time

View File

@ -16,7 +16,7 @@ To test class name in snake case
### Example
* Api Key Authentication (api_key_query):
* Api Key Authentication (api_key_query):
```python
from __future__ import print_function
import time

View File

@ -22,7 +22,7 @@ Add a new pet to the store
### Example
* OAuth Authentication (petstore_auth):
* OAuth Authentication (petstore_auth):
```python
from __future__ import print_function
import time
@ -72,7 +72,7 @@ Deletes a pet
### Example
* OAuth Authentication (petstore_auth):
* OAuth Authentication (petstore_auth):
```python
from __future__ import print_function
import time
@ -126,7 +126,7 @@ Multiple status values can be provided with comma separated strings
### Example
* OAuth Authentication (petstore_auth):
* OAuth Authentication (petstore_auth):
```python
from __future__ import print_function
import time
@ -179,7 +179,7 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3
### Example
* OAuth Authentication (petstore_auth):
* OAuth Authentication (petstore_auth):
```python
from __future__ import print_function
import time
@ -232,7 +232,7 @@ Returns a single pet
### Example
* Api Key Authentication (api_key):
* Api Key Authentication (api_key):
```python
from __future__ import print_function
import time
@ -285,7 +285,7 @@ Update an existing pet
### Example
* OAuth Authentication (petstore_auth):
* OAuth Authentication (petstore_auth):
```python
from __future__ import print_function
import time
@ -335,7 +335,7 @@ Updates a pet in the store with form data
### Example
* OAuth Authentication (petstore_auth):
* OAuth Authentication (petstore_auth):
```python
from __future__ import print_function
import time
@ -389,7 +389,7 @@ uploads an image
### Example
* OAuth Authentication (petstore_auth):
* OAuth Authentication (petstore_auth):
```python
from __future__ import print_function
import time
@ -444,7 +444,7 @@ uploads an image (required)
### Example
* OAuth Authentication (petstore_auth):
* OAuth Authentication (petstore_auth):
```python
from __future__ import print_function
import time

View File

@ -18,6 +18,7 @@ Delete purchase order by ID
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
### Example
```python
from __future__ import print_function
import time
@ -66,7 +67,7 @@ Returns a map of status codes to quantities
### Example
* Api Key Authentication (api_key):
* Api Key Authentication (api_key):
```python
from __future__ import print_function
import time
@ -116,6 +117,7 @@ Find purchase order by ID
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
### Example
```python
from __future__ import print_function
import time
@ -162,6 +164,7 @@ No authorization required
Place an order for a pet
### Example
```python
from __future__ import print_function
import time

View File

@ -22,6 +22,7 @@ Create user
This can only be done by the logged in user.
### Example
```python
from __future__ import print_function
import time
@ -67,6 +68,7 @@ No authorization required
Creates list of users with given input array
### Example
```python
from __future__ import print_function
import time
@ -112,6 +114,7 @@ No authorization required
Creates list of users with given input array
### Example
```python
from __future__ import print_function
import time
@ -159,6 +162,7 @@ Delete user
This can only be done by the logged in user.
### Example
```python
from __future__ import print_function
import time
@ -204,6 +208,7 @@ No authorization required
Get user by user name
### Example
```python
from __future__ import print_function
import time
@ -250,6 +255,7 @@ No authorization required
Logs user into the system
### Example
```python
from __future__ import print_function
import time
@ -298,6 +304,7 @@ No authorization required
Logs out current logged in user session
### Example
```python
from __future__ import print_function
import time
@ -341,6 +348,7 @@ Updated user
This can only be done by the logged in user.
### Example
```python
from __future__ import print_function
import time

View File

@ -59,10 +59,8 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
self.username = ""
# Password for HTTP basic authentication
self.password = ""
# access token for OAuth
# access token for OAuth/Bearer
self.access_token = ""
# Logging Settings
self.logger = {}
self.logger["package_logger"] = logging.getLogger("petstore_api")
@ -236,7 +234,6 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
'key': 'Authorization',
'value': self.get_basic_auth_token()
},
'petstore_auth':
{
'type': 'oauth2',
@ -244,7 +241,6 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
'key': 'Authorization',
'value': 'Bearer ' + self.access_token
},
}
def to_debug_report(self):

View File

@ -178,6 +178,10 @@ Class | Method | HTTP request | Description
- **API key parameter name**: api_key_query
- **Location**: URL query string
## bearer_test
- **Type**: HTTP basic authentication
## http_basic_test
- **Type**: HTTP basic authentication

View File

@ -513,10 +513,16 @@ Fake endpoint to test group parameters (optional)
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure HTTP basic authorization: bearer_test
$config = OpenAPI\Client\Configuration::getDefaultConfiguration()
->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.
new GuzzleHttp\Client()
new GuzzleHttp\Client(),
$config
);
$associate_array['required_string_group'] = 56; // int | Required String in group parameters
$associate_array['required_boolean_group'] = True; // bool | Required Boolean in group parameters
@ -552,7 +558,7 @@ void (empty response body)
### Authorization
No authorization required
[bearer_test](../../README.md#bearer_test)
### HTTP request headers

View File

@ -2791,6 +2791,10 @@ class FakeApi
}
}
// 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());
}
$defaultHeaders = [];
if ($this->config->getUserAgent()) {

View File

@ -51,6 +51,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint
# create an instance of the API class
api_instance = petstore_api.AnotherFakeApi(petstore_api.ApiClient(configuration))
client = petstore_api.Client() # Client | client model
@ -163,16 +164,24 @@ Class | Method | HTTP request | Description
- **API key parameter name**: api_key
- **Location**: HTTP header
## api_key_query
- **Type**: API key
- **API key parameter name**: api_key_query
- **Location**: URL query string
## bearer_test
- **Type**: Bearer authentication (JWT)
## http_basic_test
- **Type**: HTTP basic authentication
## petstore_auth
- **Type**: OAuth

View File

@ -15,6 +15,7 @@ To test special tags
To test special tags and operation ID starting with number
### Example
```python
from __future__ import print_function
import time

View File

@ -13,6 +13,7 @@ Method | HTTP request | Description
### Example
```python
from __future__ import print_function
import time

View File

@ -26,6 +26,7 @@ Method | HTTP request | Description
Test serialization of outer boolean types
### Example
```python
from __future__ import print_function
import time
@ -73,6 +74,7 @@ No authorization required
Test serialization of object with outer number type
### Example
```python
from __future__ import print_function
import time
@ -120,6 +122,7 @@ No authorization required
Test serialization of outer number types
### Example
```python
from __future__ import print_function
import time
@ -167,6 +170,7 @@ No authorization required
Test serialization of outer string types
### Example
```python
from __future__ import print_function
import time
@ -214,6 +218,7 @@ No authorization required
For this test, the body for this request much reference a schema named `File`.
### Example
```python
from __future__ import print_function
import time
@ -258,6 +263,7 @@ No authorization required
### Example
```python
from __future__ import print_function
import time
@ -306,6 +312,7 @@ To test \"client\" model
To test \"client\" model
### Example
```python
from __future__ import print_function
import time
@ -355,7 +362,7 @@ Fake endpoint for testing various parameters 假端點 偽のエンドポイン
### Example
* Basic Authentication (http_basic_test):
* Basic Authentication (http_basic_test):
```python
from __future__ import print_function
import time
@ -433,6 +440,7 @@ To test enum parameters
To test enum parameters
### Example
```python
from __future__ import print_function
import time
@ -494,15 +502,20 @@ Fake endpoint to test group parameters (optional)
Fake endpoint to test group parameters (optional)
### Example
* Bearer (JWT) Authentication (bearer_test):
```python
from __future__ import print_function
import time
import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint
configuration = petstore_api.Configuration()
# Configure Bearer authorization (JWT): bearer_test
configuration.access_token = 'YOUR_BEARER_TOKEN'
# create an instance of the API class
api_instance = petstore_api.FakeApi()
api_instance = petstore_api.FakeApi(petstore_api.ApiClient(configuration))
required_string_group = 56 # int | Required String in group parameters
required_boolean_group = True # bool | Required Boolean in group parameters
required_int64_group = 56 # int | Required Integer in group parameters
@ -534,7 +547,7 @@ void (empty response body)
### Authorization
No authorization required
[bearer_test](../README.md#bearer_test)
### HTTP request headers
@ -549,6 +562,7 @@ No authorization required
test inline additionalProperties
### Example
```python
from __future__ import print_function
import time
@ -594,6 +608,7 @@ No authorization required
test json serialization of form data
### Example
```python
from __future__ import print_function
import time

View File

@ -16,7 +16,7 @@ To test class name in snake case
### Example
* Api Key Authentication (api_key_query):
* Api Key Authentication (api_key_query):
```python
from __future__ import print_function
import time

View File

@ -22,7 +22,7 @@ Add a new pet to the store
### Example
* OAuth Authentication (petstore_auth):
* OAuth Authentication (petstore_auth):
```python
from __future__ import print_function
import time
@ -72,7 +72,7 @@ Deletes a pet
### Example
* OAuth Authentication (petstore_auth):
* OAuth Authentication (petstore_auth):
```python
from __future__ import print_function
import time
@ -126,7 +126,7 @@ Multiple status values can be provided with comma separated strings
### Example
* OAuth Authentication (petstore_auth):
* OAuth Authentication (petstore_auth):
```python
from __future__ import print_function
import time
@ -179,7 +179,7 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3
### Example
* OAuth Authentication (petstore_auth):
* OAuth Authentication (petstore_auth):
```python
from __future__ import print_function
import time
@ -232,7 +232,7 @@ Returns a single pet
### Example
* Api Key Authentication (api_key):
* Api Key Authentication (api_key):
```python
from __future__ import print_function
import time
@ -285,7 +285,7 @@ Update an existing pet
### Example
* OAuth Authentication (petstore_auth):
* OAuth Authentication (petstore_auth):
```python
from __future__ import print_function
import time
@ -335,7 +335,7 @@ Updates a pet in the store with form data
### Example
* OAuth Authentication (petstore_auth):
* OAuth Authentication (petstore_auth):
```python
from __future__ import print_function
import time
@ -389,7 +389,7 @@ uploads an image
### Example
* OAuth Authentication (petstore_auth):
* OAuth Authentication (petstore_auth):
```python
from __future__ import print_function
import time
@ -444,7 +444,7 @@ uploads an image (required)
### Example
* OAuth Authentication (petstore_auth):
* OAuth Authentication (petstore_auth):
```python
from __future__ import print_function
import time

View File

@ -18,6 +18,7 @@ Delete purchase order by ID
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
### Example
```python
from __future__ import print_function
import time
@ -66,7 +67,7 @@ Returns a map of status codes to quantities
### Example
* Api Key Authentication (api_key):
* Api Key Authentication (api_key):
```python
from __future__ import print_function
import time
@ -116,6 +117,7 @@ Find purchase order by ID
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
### Example
```python
from __future__ import print_function
import time
@ -162,6 +164,7 @@ No authorization required
Place an order for a pet
### Example
```python
from __future__ import print_function
import time

View File

@ -22,6 +22,7 @@ Create user
This can only be done by the logged in user.
### Example
```python
from __future__ import print_function
import time
@ -67,6 +68,7 @@ No authorization required
Creates list of users with given input array
### Example
```python
from __future__ import print_function
import time
@ -112,6 +114,7 @@ No authorization required
Creates list of users with given input array
### Example
```python
from __future__ import print_function
import time
@ -159,6 +162,7 @@ Delete user
This can only be done by the logged in user.
### Example
```python
from __future__ import print_function
import time
@ -204,6 +208,7 @@ No authorization required
Get user by user name
### Example
```python
from __future__ import print_function
import time
@ -250,6 +255,7 @@ No authorization required
Logs user into the system
### Example
```python
from __future__ import print_function
import time
@ -298,6 +304,7 @@ No authorization required
Logs out current logged in user session
### Example
```python
from __future__ import print_function
import time
@ -341,6 +348,7 @@ Updated user
This can only be done by the logged in user.
### Example
```python
from __future__ import print_function
import time

View File

@ -1127,7 +1127,7 @@ class FakeApi(object):
body_params = None
# Authentication setting
auth_settings = [] # noqa: E501
auth_settings = ['bearer_test'] # noqa: E501
return self.api_client.call_api(
'/fake', 'DELETE',

View File

@ -59,10 +59,8 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
self.username = ""
# Password for HTTP basic authentication
self.password = ""
# access token for OAuth
# access token for OAuth/Bearer
self.access_token = ""
# Logging Settings
self.logger = {}
self.logger["package_logger"] = logging.getLogger("petstore_api")
@ -229,6 +227,14 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
'key': 'api_key_query',
'value': self.get_api_key_with_prefix('api_key_query')
},
'bearer_test':
{
'type': 'bearer',
'in': 'header',
'format': 'JWT',
'key': 'Authorization',
'value': 'Bearer ' + self.access_token
},
'http_basic_test':
{
'type': 'basic',
@ -236,7 +242,6 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
'key': 'Authorization',
'value': self.get_basic_auth_token()
},
'petstore_auth':
{
'type': 'oauth2',
@ -244,7 +249,6 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
'key': 'Authorization',
'value': 'Bearer ' + self.access_token
},
}
def to_debug_report(self):

View File

@ -166,6 +166,10 @@ Class | Method | HTTP request | Description
- **API key parameter name**: api_key_query
- **Location**: URL query string
### bearer_test
- **Type**: HTTP basic authentication
### http_basic_test
- **Type**: HTTP basic authentication

View File

@ -482,6 +482,12 @@ Fake endpoint to test group parameters (optional)
```ruby
# load the gem
require 'petstore'
# setup authorization
Petstore.configure do |config|
# Configure HTTP basic authorization: bearer_test
config.username = 'YOUR USERNAME'
config.password = 'YOUR PASSWORD'
end
api_instance = Petstore::FakeApi.new
required_string_group = 56 # Integer | Required String in group parameters
@ -518,7 +524,7 @@ nil (empty response body)
### Authorization
No authorization required
[bearer_test](../README.md#bearer_test)
### HTTP request headers

View File

@ -686,7 +686,7 @@ module Petstore
# http body (model)
post_body = nil
auth_names = []
auth_names = ['bearer_test']
data, status_code, headers = @api_client.call_api(:DELETE, local_var_path,
:header_params => header_params,
:query_params => query_params,

View File

@ -210,6 +210,13 @@ module Petstore
key: 'api_key_query',
value: api_key_with_prefix('api_key_query')
},
'bearer_test' =>
{
type: 'basic',
in: 'header',
key: 'Authorization',
value: basic_auth_token
},
'http_basic_test' =>
{
type: 'basic',

View File

@ -204,7 +204,9 @@ public class FakeApi {
@io.swagger.annotations.ApiOperation(value = "Fake endpoint to test group parameters (optional)", notes = "Fake endpoint to test group parameters (optional)", response = Void.class, tags={ "fake", })
@io.swagger.annotations.ApiOperation(value = "Fake endpoint to test group parameters (optional)", notes = "Fake endpoint to test group parameters (optional)", response = Void.class, authorizations = {
@io.swagger.annotations.Authorization(value = "bearer_test")
}, tags={ "fake", })
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 400, message = "Someting wrong", response = Void.class) })
public Response testGroupParameters(@ApiParam(value = "Required String in group parameters",required=true) @QueryParam("required_string_group") Integer requiredStringGroup

View File

@ -43,15 +43,6 @@ use OpenAPI\Server\Model\Pet;
interface PetApiInterface
{
/**
* Sets authentication method petstore_auth
*
* @param string $value Value of the petstore_auth authentication method.
*
* @return void
*/
public function setpetstore_auth($value);
/**
* Sets authentication method api_key
*
@ -61,6 +52,15 @@ interface PetApiInterface
*/
public function setapi_key($value);
/**
* Sets authentication method petstore_auth
*
* @param string $value Value of the petstore_auth authentication method.
*
* @return void
*/
public function setpetstore_auth($value);
/**
* Operation addPet
*