From 00a9cfdbc9d8c7812ea011c033583c8bde1aad96 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Fri, 11 Jan 2019 05:15:03 -0600 Subject: [PATCH] Python: Update api_doc_example for multiple auth (#1870) APIs may more than one auth method (for example both an app key and basic auth). This changes the example to only initialize the config option once instead of once per auth method. --- .../src/main/resources/python/api_doc_example.mustache | 6 ++---- .../src/main/resources/python/common_README.mustache | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/api_doc_example.mustache b/modules/openapi-generator/src/main/resources/python/api_doc_example.mustache index 42e0f32bf73..282bacf69c2 100644 --- a/modules/openapi-generator/src/main/resources/python/api_doc_example.mustache +++ b/modules/openapi-generator/src/main/resources/python/api_doc_example.mustache @@ -4,18 +4,16 @@ import time import {{{packageName}}} from {{{packageName}}}.rest import ApiException from pprint import pprint -{{#hasAuthMethods}}{{#isBasic}} +{{#hasAuthMethods}} +configuration = {{{packageName}}}.Configuration(){{#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 diff --git a/modules/openapi-generator/src/main/resources/python/common_README.mustache b/modules/openapi-generator/src/main/resources/python/common_README.mustache index f203456f208..194fb14b599 100644 --- a/modules/openapi-generator/src/main/resources/python/common_README.mustache +++ b/modules/openapi-generator/src/main/resources/python/common_README.mustache @@ -4,18 +4,16 @@ import time import {{{packageName}}} from {{{packageName}}}.rest import ApiException from pprint import pprint -{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}}{{#authMethods}}{{#isBasic}} +{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}}{{#authMethods}} +configuration = {{{packageName}}}.Configuration(){{#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}} {{/hasAuthMethods}}