Skip to content

[BUG] [Python] Adding supporting files and custom package name with Python generator throws exception #9570

@shylacs

Description

@shylacs

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

Python generator throws an exception when adding supporting files and custom package name

openapi-generator version

5.1.1

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Some title
  version: 1.0
paths: {}
components:
  schemas: {}
  responses: {}
  parameters: {}
  examples: {}
  requestBodies: {}
  headers: {}
  securitySchemes:
    basic_auth:
      type: http
      scheme: basic
    api_key:
      type: apiKey
      name: id
      in: header
    Bearer:
      type: apiKey
      name: Authorization
      in: header
  links: {}
  callbacks: {}
tags: []
servers: []

runtime-config.yaml

packageName: "infra_sdk.runtime"
projectName: "infra-sdk-runtime"
packageVersion: "0.1.0"
appDescription: "Some description"
generatorName: "python"
templateDir: "mustache-templates/python/runtime"
files:
  deprecated-api/translation-scheme.json:
    folder: deprecatedapitranslator
    destinationFilename: translation-scheme.json
    templateType: SupportingFiles
Generation Details

java -jar openapi-generator-cli.jar generate -g python -i openapi-runtime.yaml -c config/python/runtime-config.yaml -o ../out

Steps to reproduce

Using openapi-runtime.yaml as input spec and config as runtime-config.yaml and empty templates dir, trying to generate python bindings throws below exception
Exception in thread "main" java.lang.IllegalStateException: Duplicate key init.mustache (attempted merging values SupportingFile[templateFile='init.mustache', folder='vmware_infra_sdk', destinationFilename='init.py', canOverwrite=true] and SupportingFile[templateFile='init.mustache', folder='test', destinationFilename='init.py', canOverwrite=true])

Related issues/PRs

#8420

Suggest a fix

Provide func while creating map in processUserDefinedTemplates() to use user-defined values
https://github.com/OpenAPITools/openapi-generator/blob/v5.1.1/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java#L940

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