Skip to content

Commit

Permalink
Reduce redundancy in python docs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fabianvf committed Feb 6, 2020
1 parent 8d6286d commit 9f9d094
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 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}}

0 comments on commit 9f9d094

Please sign in to comment.