Skip to content

Commit

Permalink
[Python] 5094 followup - Reduce redundancy in docs (OpenAPITools#5161)
Browse files Browse the repository at this point in the history
* Reduce redundancy in python docs

This is a followup to PR OpenAPITools#5094, which had a few unresolved comments at
merge time. This reduces the amount of redundant lines in the api
example doc templates, and ensures that referenced Configuration objects
are actually instantiated.

* Regenerate samples
  • Loading branch information
fabianvf authored and MikailBag committed Mar 23, 2020
1 parent f36ab8a commit c6837ed
Show file tree
Hide file tree
Showing 32 changed files with 133 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,17 @@ import {{{packageName}}}
from {{{packageName}}}.rest import ApiException
from pprint import pprint
{{> python_doc_auth_partial}}
{{#hasAuthMethods}}
# Defining host is optional and default to {{{basePath}}}
configuration.host = "{{{basePath}}}"
# Enter a context with an instance of the API client
{{#hasAuthMethods}}
with {{{packageName}}}.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = {{{packageName}}}.{{{classname}}}(api_client)
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
{{/allParams}}
{{/hasAuthMethods}}
{{^hasAuthMethods}}
# Enter a context with an instance of the API client
with {{{packageName}}}.ApiClient() as api_client:
{{/hasAuthMethods}}
# Create an instance of the API class
api_instance = {{{packageName}}}.{{{classname}}}(api_client)
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
{{/allParams}}
{{/hasAuthMethods}}

try:
{{#summary}} # {{{.}}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@ import time
import {{{packageName}}}
from pprint import pprint
{{> python_doc_auth_partial}}
{{#hasAuthMethods}}
# Defining host is optional and default to {{{basePath}}}
configuration.host = "{{{basePath}}}"
# Enter a context with an instance of the API client
{{#hasAuthMethods}}
with {{{packageName}}}.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = {{{packageName}}}.{{{classname}}}(api_client)
{{/hasAuthMethods}}
{{^hasAuthMethods}}
# Enter a context with an instance of the API client
with {{{packageName}}}.ApiClient(configuration) as api_client:
with {{{packageName}}}.ApiClient() as api_client:
{{/hasAuthMethods}}
# Create an instance of the API class
api_instance = {{{packageName}}}.{{{classname}}}(api_client)
{{/hasAuthMethods}}
{{#requiredParams}}{{^defaultValue}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}
{{/defaultValue}}{{/requiredParams}}{{#optionalParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} if omitted the server will use the default value of {{{defaultValue}}}{{/defaultValue}}
{{/optionalParams}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ configuration.api_key['{{{keyParamName}}}'] = 'YOUR_API_KEY'
configuration.access_token = 'YOUR_ACCESS_TOKEN'
{{/isOAuth}}
{{/authMethods}}

# Defining host is optional and default to {{{basePath}}}
configuration.host = "{{{basePath}}}"
{{/hasAuthMethods}}
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 @@ -482,6 +482,7 @@ configuration.password = 'YOUR_PASSWORD'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ configuration.api_key['api_key_query'] = 'YOUR_API_KEY'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
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 @@ -35,6 +35,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down Expand Up @@ -95,6 +96,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down Expand Up @@ -159,6 +161,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down Expand Up @@ -222,6 +225,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down Expand Up @@ -287,6 +291,7 @@ configuration.api_key['api_key'] = 'YOUR_API_KEY'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down Expand Up @@ -349,6 +354,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down Expand Up @@ -411,6 +417,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down Expand Up @@ -474,6 +481,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down Expand Up @@ -538,6 +546,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
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 @@ -90,6 +90,7 @@ configuration.api_key['api_key'] = 'YOUR_API_KEY'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import petstore_api
from pprint import pprint

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
with petstore_api.ApiClient() as api_client:
# Create an instance of the API class
api_instance = petstore_api.AnotherFakeApi(api_client)
body = petstore_api.Client() # client.Client | client model
Expand Down
29 changes: 15 additions & 14 deletions samples/client/petstore/python-experimental/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import petstore_api
from pprint import pprint

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
with petstore_api.ApiClient() as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
xml_item = petstore_api.XmlItem() # xml_item.XmlItem | XmlItem Body
Expand Down Expand Up @@ -92,7 +92,7 @@ import petstore_api
from pprint import pprint

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
with petstore_api.ApiClient() as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
body = True # bool | Input boolean as post body (optional)
Expand Down Expand Up @@ -148,7 +148,7 @@ import petstore_api
from pprint import pprint

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
with petstore_api.ApiClient() as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
body = petstore_api.OuterComposite() # outer_composite.OuterComposite | Input composite as post body (optional)
Expand Down Expand Up @@ -204,7 +204,7 @@ import petstore_api
from pprint import pprint

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
with petstore_api.ApiClient() as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
body = petstore_api.OuterEnum("placed") # outer_enum.OuterEnum | Input enum as post body (optional)
Expand Down Expand Up @@ -260,7 +260,7 @@ import petstore_api
from pprint import pprint

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
with petstore_api.ApiClient() as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
body = petstore_api.OuterNumber(3.4) # outer_number.OuterNumber | Input number as post body (optional)
Expand Down Expand Up @@ -316,7 +316,7 @@ import petstore_api
from pprint import pprint

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
with petstore_api.ApiClient() as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
body = 'body_example' # str | Input string as post body (optional)
Expand Down Expand Up @@ -372,7 +372,7 @@ import petstore_api
from pprint import pprint

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
with petstore_api.ApiClient() as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
body = petstore_api.FileSchemaTestClass() # file_schema_test_class.FileSchemaTestClass |
Expand Down Expand Up @@ -424,7 +424,7 @@ import petstore_api
from pprint import pprint

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
with petstore_api.ApiClient() as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
query = 'query_example' # str |
Expand Down Expand Up @@ -480,7 +480,7 @@ import petstore_api
from pprint import pprint

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
with petstore_api.ApiClient() as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
body = petstore_api.Client() # client.Client | client model
Expand Down Expand Up @@ -536,7 +536,7 @@ import petstore_api
from pprint import pprint

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
with petstore_api.ApiClient() as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)

Expand Down Expand Up @@ -599,6 +599,7 @@ configuration.password = 'YOUR_PASSWORD'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down Expand Up @@ -690,7 +691,7 @@ import petstore_api
from pprint import pprint

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
with petstore_api.ApiClient() as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
enum_header_string_array = ['enum_header_string_array_example'] # [str] | Header parameter enum test (string array) (optional)
Expand Down Expand Up @@ -761,7 +762,7 @@ import petstore_api
from pprint import pprint

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
with petstore_api.ApiClient() as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
required_string_group = 56 # int | Required String in group parameters
Expand Down Expand Up @@ -832,7 +833,7 @@ import petstore_api
from pprint import pprint

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
with petstore_api.ApiClient() as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
param = {'key': 'param_example'} # {str: (str,)} | request body
Expand Down Expand Up @@ -885,7 +886,7 @@ import petstore_api
from pprint import pprint

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
with petstore_api.ApiClient() as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
param = 'param_example' # str | field1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ configuration.api_key['api_key_query'] = 'YOUR_API_KEY'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down
9 changes: 9 additions & 0 deletions samples/client/petstore/python-experimental/docs/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down Expand Up @@ -94,6 +95,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down Expand Up @@ -166,6 +168,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down Expand Up @@ -229,6 +232,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down Expand Up @@ -294,6 +298,7 @@ configuration.api_key['api_key'] = 'YOUR_API_KEY'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down Expand Up @@ -356,6 +361,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down Expand Up @@ -418,6 +424,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down Expand Up @@ -489,6 +496,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down Expand Up @@ -564,6 +572,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN'

# Defining host is optional and default to http://petstore.swagger.io:80/v2
configuration.host = "http://petstore.swagger.io:80/v2"

# Enter a context with an instance of the API client
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
Expand Down
Loading

0 comments on commit c6837ed

Please sign in to comment.