Skip to content

Commit

Permalink
[python] : Make example code snippet compilable (OpenAPITools#3148)
Browse files Browse the repository at this point in the history
* feat(python): Making example compilable

* feat(python): Updating pet project

* feat(python): Updating comments

* feat(documentation): Fixing comments style

* feat(documentation): Updating documentation

* feat(documentation): Fixing comments style
  • Loading branch information
saigiridhar21 authored and wing328 committed Jun 28, 2019
1 parent a41448a commit 6578cef
Show file tree
Hide file tree
Showing 31 changed files with 262 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ from {{{packageName}}}.rest import ApiException
from pprint import pprint
{{> python_doc_auth_partial}}
{{#hasAuthMethods}}
# create an instance of the API class
# Defining host is optional and default to {{{basePath}}}
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}}
{{/allParams}}
{{/hasAuthMethods}}
{{^hasAuthMethods}}
# create an instance of the API class
# Create an instance of the API class
api_instance = {{{packageName}}}.{{{classname}}}()
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
{{/allParams}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ from {{{packageName}}}.rest import ApiException
from pprint import pprint
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}
{{> python_doc_auth_partial}}
# create an instance of the API class
# Defining host is optional and default to {{{basePath}}}
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}}
{{/allParams}}
Expand Down
4 changes: 3 additions & 1 deletion samples/client/petstore/python-asyncio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ from petstore_api.rest import ApiException
from pprint import pprint


# create an instance of the API class
# Defining host is optional and default to http://petstore.swagger.io:80/v2
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.AnotherFakeApi()
body = petstore_api.Client() # Client | client model

Expand Down
28 changes: 15 additions & 13 deletions samples/client/petstore/python-asyncio/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.FakeApi()
xml_item = petstore_api.XmlItem() # XmlItem | XmlItem Body

Expand Down Expand Up @@ -88,7 +88,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.FakeApi()
body = True # bool | Input boolean as post body (optional)

Expand Down Expand Up @@ -141,7 +141,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.FakeApi()
body = petstore_api.OuterComposite() # OuterComposite | Input composite as post body (optional)

Expand Down Expand Up @@ -194,7 +194,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.FakeApi()
body = 3.4 # float | Input number as post body (optional)

Expand Down Expand Up @@ -247,7 +247,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.FakeApi()
body = 'body_example' # str | Input string as post body (optional)

Expand Down Expand Up @@ -300,7 +300,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.FakeApi()
body = petstore_api.FileSchemaTestClass() # FileSchemaTestClass |

Expand Down Expand Up @@ -350,7 +350,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.FakeApi()
query = 'query_example' # str |
body = petstore_api.User() # User |
Expand Down Expand Up @@ -404,7 +404,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.FakeApi()
body = petstore_api.Client() # Client | client model

Expand Down Expand Up @@ -463,7 +463,9 @@ configuration = petstore_api.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

# create an instance of the API class
# Defining host is optional and default to http://petstore.swagger.io:80/v2
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
double = 3.4 # float | None
Expand Down Expand Up @@ -543,7 +545,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.FakeApi()
enum_header_string_array = ['enum_header_string_array_example'] # list[str] | Header parameter enum test (string array) (optional)
enum_header_string = '-efg' # str | Header parameter enum test (string) (optional) (default to '-efg')
Expand Down Expand Up @@ -611,7 +613,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.FakeApi()
required_string_group = 56 # int | Required String in group parameters
required_boolean_group = True # bool | Required Boolean in group parameters
Expand Down Expand Up @@ -672,7 +674,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.FakeApi()
param = {'key': 'param_example'} # dict(str, str) | request body

Expand Down Expand Up @@ -723,7 +725,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.FakeApi()
param = 'param_example' # str | field1
param2 = 'param2_example' # str | field2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ 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'

# create an instance of the API class
# Defining host is optional and default to http://petstore.swagger.io:80/v2
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
36 changes: 27 additions & 9 deletions samples/client/petstore/python-asyncio/docs/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

# create an instance of the API class
# Defining host is optional and default to http://petstore.swagger.io:80/v2
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,7 +91,9 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

# create an instance of the API class
# Defining host is optional and default to http://petstore.swagger.io:80/v2
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
api_key = 'api_key_example' # str | (optional)
Expand Down Expand Up @@ -149,7 +153,9 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

# create an instance of the API class
# Defining host is optional and default to http://petstore.swagger.io:80/v2
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,7 +214,9 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

# create an instance of the API class
# Defining host is optional and default to http://petstore.swagger.io:80/v2
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,7 +277,9 @@ 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'

# create an instance of the API class
# Defining host is optional and default to http://petstore.swagger.io:80/v2
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,7 +337,9 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

# create an instance of the API class
# Defining host is optional and default to http://petstore.swagger.io:80/v2
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,7 +397,9 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

# create an instance of the API class
# Defining host is optional and default to http://petstore.swagger.io:80/v2
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
name = 'name_example' # str | Updated name of the pet (optional)
Expand Down Expand Up @@ -444,7 +458,9 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

# create an instance of the API class
# Defining host is optional and default to http://petstore.swagger.io:80/v2
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
additional_metadata = 'additional_metadata_example' # str | Additional data to pass to server (optional)
Expand Down Expand Up @@ -504,7 +520,9 @@ configuration = petstore_api.Configuration()
# Configure OAuth2 access token for authorization: petstore_auth
configuration.access_token = 'YOUR_ACCESS_TOKEN'

# create an instance of the API class
# Defining host is optional and default to http://petstore.swagger.io:80/v2
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
required_file = '/path/to/file' # file | file to upload
Expand Down
10 changes: 6 additions & 4 deletions samples/client/petstore/python-asyncio/docs/StoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.StoreApi()
order_id = 'order_id_example' # str | ID of the order that needs to be deleted

Expand Down Expand Up @@ -86,7 +86,9 @@ 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'

# create an instance of the API class
# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"
# Create an instance of the API class
api_instance = petstore_api.StoreApi(petstore_api.ApiClient(configuration))

try:
Expand Down Expand Up @@ -136,7 +138,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.StoreApi()
order_id = 56 # int | ID of pet that needs to be fetched

Expand Down Expand Up @@ -190,7 +192,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.StoreApi()
body = petstore_api.Order() # Order | order placed for purchasing the pet

Expand Down
16 changes: 8 additions & 8 deletions samples/client/petstore/python-asyncio/docs/UserApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.UserApi()
body = petstore_api.User() # User | Created user object

Expand Down Expand Up @@ -81,7 +81,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.UserApi()
body = [petstore_api.User()] # list[User] | List of user object

Expand Down Expand Up @@ -132,7 +132,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.UserApi()
body = [petstore_api.User()] # list[User] | List of user object

Expand Down Expand Up @@ -185,7 +185,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.UserApi()
username = 'username_example' # str | The name that needs to be deleted

Expand Down Expand Up @@ -237,7 +237,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.UserApi()
username = 'username_example' # str | The name that needs to be fetched. Use user1 for testing.

Expand Down Expand Up @@ -291,7 +291,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.UserApi()
username = 'username_example' # str | The user name for login
password = 'password_example' # str | The password for login in clear text
Expand Down Expand Up @@ -346,7 +346,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.UserApi()

try:
Expand Down Expand Up @@ -395,7 +395,7 @@ import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint

# create an instance of the API class
# Create an instance of the API class
api_instance = petstore_api.UserApi()
username = 'username_example' # str | name that need to be deleted
body = petstore_api.User() # User | Updated user object
Expand Down
4 changes: 3 additions & 1 deletion samples/client/petstore/python-tornado/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ from petstore_api.rest import ApiException
from pprint import pprint


# create an instance of the API class
# Defining host is optional and default to http://petstore.swagger.io:80/v2
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
Loading

0 comments on commit 6578cef

Please sign in to comment.