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

[BUG] [HTML] [Python] The code example for the python client in the HTML2 documentation generator is invalid #7257

Open
3 tasks done
Gornoka opened this issue Aug 20, 2020 · 0 comments
Labels
Client: Python Good First Issue An issue that could be fixed with a simple PR Issue: Bug

Comments

@Gornoka
Copy link

Gornoka commented Aug 20, 2020

Bug Report Checklist

  • [~] Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator, yes I used the validate function of the api generator
  • [5.0.0 ] What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
Description

The automated code generation feature for example code in the HTML2 generator does not produce valid code for the authetification settings.
With the following security scheme the generator creates a code example like this

# Configure API key authorization: myAuthHeader
openapi_client.configuration.api_key['myAuthHeader'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# openapi_client.configuration.api_key_prefix['myAuthHeader'] = 'Bearer'

# Create an instance of the API class
api_instance = openapi_client.MyApi()

This can not be executed, with the following error.

Traceback:
   Error in line XXX:
        openapi_client.configuration.api_key['myAuthHeader'] =  'YOUR_API_KEY'
    AttributeError: module 'openapi_client.configuration' has no attribute  'YOUR_API_KEY'

The following code snippet can be executed, this issue probably exists for more than just header based authentifications.

    # Configure API key authorization: myAuthHeader
    api_config = openapi_client.Configuration(api_key={"myAuthHeader":  'YOUR_API_KEY'})
    # Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
    # api_config = openapi_client.Configuration(api_key={"myAuthHeader":  'YOUR_API_KEY'}, api_key_prefix={'myAuthHeader': Bearer})
    client = openapi_client.api_client.ApiClient(configuration=api_config)
    api_instance = openapi_client.MyApi(client)

This example is based upon the example within the python class definition for the Configuration class

    :Example:

    API Key Authentication Example.
    Given the following security scheme in the OpenAPI specification:
      components:
        securitySchemes:
          cookieAuth:         # name for the security scheme
            type: apiKey
            in: cookie
            name: JSESSIONID  # cookie name

    You can programmatically set the cookie:

conf = openapi_client.Configuration(
    api_key={'cookieAuth': 'abc123'}
    api_key_prefix={'cookieAuth': 'JSESSIONID'}
openapi-generator version
      openapi-generator-cli 5.0.0-beta
OpenAPI declaration file content or url
schemas:
  securitySchemes:
    ApiKeyAuth:       
      type: apiKey
      in: header      
      name: myAuthHeader  
Generation Details

using java -jar openapi generate html2 -i MyApi.yaml -o html2_doc
using java -jar openapi generate python -i MyApi.yaml -o python_client

Steps to reproduce
Related issues/PRs
Suggest a fix

Use sample Code generation which is used by the python client generator itself.
See getting started section of that generators readme.md

@spacether spacether added Good First Issue An issue that could be fixed with a simple PR Client: Python labels Mar 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client: Python Good First Issue An issue that could be fixed with a simple PR Issue: Bug
Projects
None yet
Development

No branches or pull requests

2 participants