forked from loafle/openapi-generator-original
[PYTHON] Api doc python with multiple authentications (#928)
* [PYTHON] better code snippet for API usage with authentication * update python samples
This commit is contained in:
committed by
William Cheng
parent
5ad471cc6e
commit
6bc3c70115
@@ -18,47 +18,14 @@ Method | HTTP request | Description
|
|||||||
{{{notes}}}{{/notes}}
|
{{{notes}}}{{/notes}}
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
```python
|
{{#hasAuthMethods}}{{#authMethods}}
|
||||||
from __future__ import print_function
|
{{#isBasic}}* Basic Authentication ({{name}}): {{/isBasic }}{{#isApiKey}}* Api Key Authentication ({{name}}): {{/isApiKey }}{{#isOAuth}}* OAuth Authentication ({{name}}): {{/isOAuth }}
|
||||||
import time
|
{{> api_doc_example }}
|
||||||
import {{{packageName}}}
|
{{/authMethods}}
|
||||||
from {{{packageName}}}.rest import ApiException
|
|
||||||
from pprint import pprint
|
|
||||||
{{#hasAuthMethods}}{{#authMethods}}{{#isBasic}}
|
|
||||||
# Configure HTTP basic authorization: {{{name}}}
|
|
||||||
configuration = {{{packageName}}}.Configuration()
|
|
||||||
configuration.username = 'YOUR_USERNAME'
|
|
||||||
configuration.password = 'YOUR_PASSWORD'{{/isBasic}}{{#isApiKey}}
|
|
||||||
# Configure API key authorization: {{{name}}}
|
|
||||||
configuration = {{{packageName}}}.Configuration()
|
|
||||||
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 = {{{packageName}}}.Configuration()
|
|
||||||
configuration.access_token = 'YOUR_ACCESS_TOKEN'{{/isOAuth}}{{/authMethods}}
|
|
||||||
|
|
||||||
# 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}}
|
||||||
{{^hasAuthMethods}}
|
{{^hasAuthMethods}}
|
||||||
|
{{> api_doc_example }}
|
||||||
# create an instance of the API class
|
|
||||||
api_instance = {{{packageName}}}.{{{classname}}}()
|
|
||||||
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
|
|
||||||
{{/allParams}}
|
|
||||||
{{/hasAuthMethods}}
|
{{/hasAuthMethods}}
|
||||||
|
|
||||||
try:
|
|
||||||
{{#summary}} # {{{.}}}
|
|
||||||
{{/summary}} {{#returnType}}api_response = {{/returnType}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}){{#returnType}}
|
|
||||||
pprint(api_response){{/returnType}}
|
|
||||||
except ApiException as e:
|
|
||||||
print("Exception when calling {{classname}}->{{operationId}}: %s\n" % e)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}}
|
{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}}
|
||||||
Name | Type | Description | Notes
|
Name | Type | Description | Notes
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
```python
|
||||||
|
from __future__ import print_function
|
||||||
|
import time
|
||||||
|
import {{{packageName}}}
|
||||||
|
from {{{packageName}}}.rest import ApiException
|
||||||
|
from pprint import pprint
|
||||||
|
{{#hasAuthMethods}}{{#isBasic}}
|
||||||
|
# Configure HTTP basic authorization: {{{name}}}
|
||||||
|
configuration = {{{packageName}}}.Configuration()
|
||||||
|
configuration.username = 'YOUR_USERNAME'
|
||||||
|
configuration.password = 'YOUR_PASSWORD'{{/isBasic}}{{#isApiKey}}
|
||||||
|
# Configure API key authorization: {{{name}}}
|
||||||
|
configuration = {{{packageName}}}.Configuration()
|
||||||
|
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 = {{{packageName}}}.Configuration()
|
||||||
|
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}}
|
||||||
|
{{/allParams}}
|
||||||
|
{{/hasAuthMethods}}
|
||||||
|
|
||||||
|
try:
|
||||||
|
{{#summary}} # {{{.}}}
|
||||||
|
{{/summary}} {{#returnType}}api_response = {{/returnType}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}){{#returnType}}
|
||||||
|
pprint(api_response){{/returnType}}
|
||||||
|
except ApiException as e:
|
||||||
|
print("Exception when calling {{classname}}->{{operationId}}: %s\n" % e)
|
||||||
|
```
|
||||||
@@ -1 +1 @@
|
|||||||
3.2.3-SNAPSHOT
|
3.2.2-SNAPSHOT
|
||||||
@@ -353,6 +353,8 @@ Fake endpoint for testing various parameters 假端點 偽のエンドポイン
|
|||||||
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* Basic Authentication (http_basic_test):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ To test class name in snake case
|
|||||||
To test class name in snake case
|
To test class name in snake case
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* Api Key Authentication (api_key_query):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ Method | HTTP request | Description
|
|||||||
Add a new pet to the store
|
Add a new pet to the store
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -70,6 +72,8 @@ void (empty response body)
|
|||||||
Deletes a pet
|
Deletes a pet
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -123,6 +127,8 @@ Finds Pets by status
|
|||||||
Multiple status values can be provided with comma separated strings
|
Multiple status values can be provided with comma separated strings
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -175,6 +181,8 @@ Finds Pets by tags
|
|||||||
Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -227,6 +235,8 @@ Find pet by ID
|
|||||||
Returns a single pet
|
Returns a single pet
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* Api Key Authentication (api_key):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -279,6 +289,8 @@ Name | Type | Description | Notes
|
|||||||
Update an existing pet
|
Update an existing pet
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -328,6 +340,8 @@ void (empty response body)
|
|||||||
Updates a pet in the store with form data
|
Updates a pet in the store with form data
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -381,6 +395,8 @@ void (empty response body)
|
|||||||
uploads an image
|
uploads an image
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -435,6 +451,8 @@ Name | Type | Description | Notes
|
|||||||
uploads an image (required)
|
uploads an image (required)
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ Returns pet inventories by status
|
|||||||
Returns a map of status codes to quantities
|
Returns a map of status codes to quantities
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* Api Key Authentication (api_key):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
3.2.3-SNAPSHOT
|
3.2.2-SNAPSHOT
|
||||||
@@ -353,6 +353,8 @@ Fake endpoint for testing various parameters 假端點 偽のエンドポイン
|
|||||||
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* Basic Authentication (http_basic_test):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ To test class name in snake case
|
|||||||
To test class name in snake case
|
To test class name in snake case
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* Api Key Authentication (api_key_query):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ Method | HTTP request | Description
|
|||||||
Add a new pet to the store
|
Add a new pet to the store
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -70,6 +72,8 @@ void (empty response body)
|
|||||||
Deletes a pet
|
Deletes a pet
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -123,6 +127,8 @@ Finds Pets by status
|
|||||||
Multiple status values can be provided with comma separated strings
|
Multiple status values can be provided with comma separated strings
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -175,6 +181,8 @@ Finds Pets by tags
|
|||||||
Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -227,6 +235,8 @@ Find pet by ID
|
|||||||
Returns a single pet
|
Returns a single pet
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* Api Key Authentication (api_key):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -279,6 +289,8 @@ Name | Type | Description | Notes
|
|||||||
Update an existing pet
|
Update an existing pet
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -328,6 +340,8 @@ void (empty response body)
|
|||||||
Updates a pet in the store with form data
|
Updates a pet in the store with form data
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -381,6 +395,8 @@ void (empty response body)
|
|||||||
uploads an image
|
uploads an image
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -435,6 +451,8 @@ Name | Type | Description | Notes
|
|||||||
uploads an image (required)
|
uploads an image (required)
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ Returns pet inventories by status
|
|||||||
Returns a map of status codes to quantities
|
Returns a map of status codes to quantities
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* Api Key Authentication (api_key):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
3.2.3-SNAPSHOT
|
3.2.2-SNAPSHOT
|
||||||
@@ -353,6 +353,8 @@ Fake endpoint for testing various parameters 假端點 偽のエンドポイン
|
|||||||
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* Basic Authentication (http_basic_test):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ To test class name in snake case
|
|||||||
To test class name in snake case
|
To test class name in snake case
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* Api Key Authentication (api_key_query):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ Method | HTTP request | Description
|
|||||||
Add a new pet to the store
|
Add a new pet to the store
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -70,6 +72,8 @@ void (empty response body)
|
|||||||
Deletes a pet
|
Deletes a pet
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -123,6 +127,8 @@ Finds Pets by status
|
|||||||
Multiple status values can be provided with comma separated strings
|
Multiple status values can be provided with comma separated strings
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -175,6 +181,8 @@ Finds Pets by tags
|
|||||||
Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -227,6 +235,8 @@ Find pet by ID
|
|||||||
Returns a single pet
|
Returns a single pet
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* Api Key Authentication (api_key):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -279,6 +289,8 @@ Name | Type | Description | Notes
|
|||||||
Update an existing pet
|
Update an existing pet
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -328,6 +340,8 @@ void (empty response body)
|
|||||||
Updates a pet in the store with form data
|
Updates a pet in the store with form data
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -381,6 +395,8 @@ void (empty response body)
|
|||||||
uploads an image
|
uploads an image
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
@@ -435,6 +451,8 @@ Name | Type | Description | Notes
|
|||||||
uploads an image (required)
|
uploads an image (required)
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* OAuth Authentication (petstore_auth):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ Returns pet inventories by status
|
|||||||
Returns a map of status codes to quantities
|
Returns a map of status codes to quantities
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
* Api Key Authentication (api_key):
|
||||||
```python
|
```python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
|
|||||||
Reference in New Issue
Block a user