Skip to content

[BUG][python] access_token gets set to None when hasHttpBearerMethods #15766

@ToneyAlexander

Description

@ToneyAlexander

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

For the python generator, the access_token passed to configuration gets set to None when hasOAuthMethods or hasHttpBearerMethods are True. I'm not completely sure how it is supposed to behave for hasOAuthMethods, but it seems to be a bug for the hasHttpBearerMethods use case since that one expects a token in requests.

openapi-generator version

6.6.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Swagger Petstore - OpenAPI 3.0
  version: 1.0.11
paths:
  /pet:
    put:
      tags:
        - pet
      summary: Update an existing pet
      description: Update an existing pet by Id
      operationId: updatePet
      requestBody:
        description: Update an existent pet in the store
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
        required: true
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'          
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
  schemas:
    Pet:
      required:
        - name
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 10
        name:
          type: string
          example: doggie
      xml:
        name: pet
  requestBodies:
    Pet:
      description: Pet object that needs to be added to the store
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Pet'
        application/xml:
          schema:
            $ref: '#/components/schemas/Pet'
security:
  - bearerAuth: []
Generation Details

Take the yaml given and run it through the master docker image with

docker run -v /input_openapi.yaml:/openapi.yaml -it IMAGE_ID generate -g python -i /openapi.yaml -o /
Steps to reproduce

Configuration.py has the lines:
self.access_token = access_token
"""Access token
"""
self.access_token = None
"""access token for OAuth/Bearer
"""

Suggest a fix

Relevant code:
https://github.com/OpenAPITools/openapi-generator/blob/bc7bdca87f7a215c0bd1fe08aa58291e2f85af62/modules/openapi-generator/src/main/resources/python/configuration.mustache#L186C9-L206

It seems like removing the Bearer conditional statement there would fix the issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions