forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PYTHON] Api doc python with multiple authentications (OpenAPITools#928)
* [PYTHON] better code snippet for API usage with authentication * update python samples
- Loading branch information
Showing
17 changed files
with
120 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
modules/openapi-generator/src/main/resources/python/api_doc_example.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
``` |
2 changes: 1 addition & 1 deletion
2
samples/client/petstore/python-asyncio/.openapi-generator/VERSION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.2.3-SNAPSHOT | ||
3.2.2-SNAPSHOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
samples/client/petstore/python-tornado/.openapi-generator/VERSION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.2.3-SNAPSHOT | ||
3.2.2-SNAPSHOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.2.3-SNAPSHOT | ||
3.2.2-SNAPSHOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.