[BUG] [python-nextgen] generated example is NOT runnable in success when OpenAPI spec has no auth methods
Created by: itaru2622
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The generated example is not runnable in success when OpenAPI spec has no auth methods, even the configuration param is tuned to meet remote server. The above caused by the below generated example code, creating ApiClient instance without configuration param. It is less kindness as example code because other part is ready to run.
configuration = openapi_client.Configuration(
host = "http://localhost" # endpoint URL is easy to tune.
)
# Enter a context with an instance of the API client
with openapi_client.ApiClient() as api_client: # <= call without configuration param, it needs to add param to get success.
openapi-generator version
latest official docker image of openapitools/openapi-generator-cli:latest
$ docker images --digests | grep openapitools/openapi-generator-cli
openapitools/openapi-generator-cli latest sha256:6936f1696187c7041eaee822f7fe3e77c0c295e68509de15fa583eba991fed52 c25a5bb3ea9a
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
$ docker run -it --rm -v /tmp/out:/out openapitools/openapi-generator-cli:latest generate -g python-nextgen -o /out -i https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/generic.yaml
$ cat /tmp/out/docs/DefaultApi.md | grep -n openapi_client.ApiClient
34:with openapi_client.ApiClient() as api_client:
Related issues/PRs
None?
Suggest a fix
The following patch fixes this issue. below patch will be sent pull request later.
diff --git a/modules/openapi-generator/src/main/resources/python-nextgen/api_doc_example.mustache b/modules/openapi-generator/src/main/resources/python-nextgen/api_doc_example.mustache
index 59ceada0a8d..d8b29f7bd6c 100644
--- a/modules/openapi-generator/src/main/resources/python-nextgen/api_doc_example.mustache
+++ b/modules/openapi-generator/src/main/resources/python-nextgen/api_doc_example.mustache
@@ -7,12 +7,7 @@ from {{{packageName}}}.rest import ApiException
from pprint import pprint
{{> python_doc_auth_partial}}
# Enter a context with an instance of the API client
-{{#hasAuthMethods}}
{{#asyncio}}async {{/asyncio}}with {{{packageName}}}.ApiClient(configuration) as api_client:
-{{/hasAuthMethods}}
-{{^hasAuthMethods}}
-{{#asyncio}}async {{/asyncio}}with {{{packageName}}}.ApiClient() as api_client:
-{{/hasAuthMethods}}
# Create an instance of the API class
api_instance = {{{packageName}}}.{{{classname}}}(api_client)
{{#allParams}}