Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python] : Make example code snippet compilable #3148

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ from {{{packageName}}}.rest import ApiException
from pprint import pprint
{{> python_doc_auth_partial}}
{{#hasAuthMethods}}
configuration.host = "{{{basePath}}}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saigiridhar21 thanks for the PR. Please correct me if I'm wrong. I believe the default of configuration.host is already set to {{{basePath}}}. Why do we need to do it again before passing to ApiClient?:

Copy link
Contributor Author

@saigiridhar21 saigiridhar21 Jun 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wing328 Yes. You are right. My reason might not be a strong one but it is more like a hint for users that they can update host.
In our use case, we have a horizontally scaled system and we generate SDKs using one of the hosts. So, we don't specify host in the swagger spec. As a result, SDKs get generated with localhost url. A public DNS is there which load balances requests to all the hosts. So, it is expected that clients specify the host in their code.

# 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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ from {{{packageName}}}.rest import ApiException
from pprint import pprint
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}
{{> python_doc_auth_partial}}
configuration.host = "{{{basePath}}}"
# 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}}
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/python-asyncio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ from petstore_api.rest import ApiException
from pprint import pprint


configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.AnotherFakeApi(petstore_api.ApiClient(configuration))
body = petstore_api.Client() # Client | client model
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/python-asyncio/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ configuration = petstore_api.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.FakeApi(petstore_api.ApiClient(configuration))
number = 3.4 # float | None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ configuration.api_key['api_key_query'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['api_key_query'] = 'Bearer'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.FakeClassnameTags123Api(petstore_api.ApiClient(configuration))
body = petstore_api.Client() # Client | client model
Expand Down
9 changes: 9 additions & 0 deletions samples/client/petstore/python-asyncio/docs/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
body = petstore_api.Pet() # Pet | Pet object that needs to be added to the store
Expand Down Expand Up @@ -89,6 +90,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
pet_id = 56 # int | Pet id to delete
Expand Down Expand Up @@ -149,6 +151,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
status = ['status_example'] # list[str] | Status values that need to be considered for filter
Expand Down Expand Up @@ -208,6 +211,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
tags = ['tags_example'] # list[str] | Tags to filter by
Expand Down Expand Up @@ -269,6 +273,7 @@ configuration.api_key['api_key'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['api_key'] = 'Bearer'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
pet_id = 56 # int | ID of pet to return
Expand Down Expand Up @@ -327,6 +332,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
body = petstore_api.Pet() # Pet | Pet object that needs to be added to the store
Expand Down Expand Up @@ -385,6 +391,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
pet_id = 56 # int | ID of pet that needs to be updated
Expand Down Expand Up @@ -444,6 +451,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
pet_id = 56 # int | ID of pet to update
Expand Down Expand Up @@ -504,6 +512,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
pet_id = 56 # int | ID of pet to update
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/python-asyncio/docs/StoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ configuration.api_key['api_key'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['api_key'] = 'Bearer'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.StoreApi(petstore_api.ApiClient(configuration))

Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/python-tornado/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ from petstore_api.rest import ApiException
from pprint import pprint


configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.AnotherFakeApi(petstore_api.ApiClient(configuration))
body = petstore_api.Client() # Client | client model
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/python-tornado/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ configuration = petstore_api.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.FakeApi(petstore_api.ApiClient(configuration))
number = 3.4 # float | None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ configuration.api_key['api_key_query'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['api_key_query'] = 'Bearer'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.FakeClassnameTags123Api(petstore_api.ApiClient(configuration))
body = petstore_api.Client() # Client | client model
Expand Down
9 changes: 9 additions & 0 deletions samples/client/petstore/python-tornado/docs/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
body = petstore_api.Pet() # Pet | Pet object that needs to be added to the store
Expand Down Expand Up @@ -89,6 +90,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
pet_id = 56 # int | Pet id to delete
Expand Down Expand Up @@ -149,6 +151,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
status = ['status_example'] # list[str] | Status values that need to be considered for filter
Expand Down Expand Up @@ -208,6 +211,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
tags = ['tags_example'] # list[str] | Tags to filter by
Expand Down Expand Up @@ -269,6 +273,7 @@ configuration.api_key['api_key'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['api_key'] = 'Bearer'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
pet_id = 56 # int | ID of pet to return
Expand Down Expand Up @@ -327,6 +332,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
body = petstore_api.Pet() # Pet | Pet object that needs to be added to the store
Expand Down Expand Up @@ -385,6 +391,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
pet_id = 56 # int | ID of pet that needs to be updated
Expand Down Expand Up @@ -444,6 +451,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
pet_id = 56 # int | ID of pet to update
Expand Down Expand Up @@ -504,6 +512,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
pet_id = 56 # int | ID of pet to update
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/python-tornado/docs/StoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ configuration.api_key['api_key'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['api_key'] = 'Bearer'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.StoreApi(petstore_api.ApiClient(configuration))

Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ from petstore_api.rest import ApiException
from pprint import pprint


configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.AnotherFakeApi(petstore_api.ApiClient(configuration))
body = petstore_api.Client() # Client | client model
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/python/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ configuration = petstore_api.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.FakeApi(petstore_api.ApiClient(configuration))
number = 3.4 # float | None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ configuration.api_key['api_key_query'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['api_key_query'] = 'Bearer'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.FakeClassnameTags123Api(petstore_api.ApiClient(configuration))
body = petstore_api.Client() # Client | client model
Expand Down
9 changes: 9 additions & 0 deletions samples/client/petstore/python/docs/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
body = petstore_api.Pet() # Pet | Pet object that needs to be added to the store
Expand Down Expand Up @@ -89,6 +90,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
pet_id = 56 # int | Pet id to delete
Expand Down Expand Up @@ -149,6 +151,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
status = ['status_example'] # list[str] | Status values that need to be considered for filter
Expand Down Expand Up @@ -208,6 +211,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
tags = ['tags_example'] # list[str] | Tags to filter by
Expand Down Expand Up @@ -269,6 +273,7 @@ configuration.api_key['api_key'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['api_key'] = 'Bearer'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
pet_id = 56 # int | ID of pet to return
Expand Down Expand Up @@ -327,6 +332,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
body = petstore_api.Pet() # Pet | Pet object that needs to be added to the store
Expand Down Expand Up @@ -385,6 +391,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
pet_id = 56 # int | ID of pet that needs to be updated
Expand Down Expand Up @@ -444,6 +451,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
pet_id = 56 # int | ID of pet to update
Expand Down Expand Up @@ -504,6 +512,7 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration))
pet_id = 56 # int | ID of pet to update
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/python/docs/StoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ configuration.api_key['api_key'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['api_key'] = 'Bearer'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.StoreApi(petstore_api.ApiClient(configuration))

Expand Down
1 change: 1 addition & 0 deletions samples/openapi3/client/petstore/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ from petstore_api.rest import ApiException
from pprint import pprint


configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.AnotherFakeApi(petstore_api.ApiClient(configuration))
client = petstore_api.Client() # Client | client model
Expand Down
2 changes: 2 additions & 0 deletions samples/openapi3/client/petstore/python/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ configuration = petstore_api.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.FakeApi(petstore_api.ApiClient(configuration))
number = 3.4 # float | None
Expand Down Expand Up @@ -610,6 +611,7 @@ configuration = petstore_api.Configuration()
# Configure Bearer authorization (JWT): bearer_test
configuration.access_token = 'YOUR_BEARER_TOKEN'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.FakeApi(petstore_api.ApiClient(configuration))
required_string_group = 56 # int | Required String in group parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ configuration.api_key['api_key_query'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['api_key_query'] = 'Bearer'

configuration.host = "http://petstore.swagger.io:80/v2"
# create an instance of the API class
api_instance = petstore_api.FakeClassnameTags123Api(petstore_api.ApiClient(configuration))
client = petstore_api.Client() # Client | client model
Expand Down
Loading