Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #7257
Closed
Open
Issue created Aug 20, 2020 by Administrator@rootContributor3 of 3 checklist items completed3/3 checklist items

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

Created by: Gornoka

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

Assignee
Assign to
Time tracking