Bug Report Checklist
Description
When adding a custom model template with the Python generator, an exception is thrown.
openapi-generator version
5.0.0
OpenAPI declaration file content or url
# api.yaml
openapi: 3.0.3
info:
title: API
description: API
version: 1.0.0
servers:
- url: 'https://localhost:80'
paths: {}
components:
schemas:
Test:
type: object
Generation Details
Following the instructions from https://github.com/OpenAPITools/openapi-generator/blob/master/docs/customization.md:
# config.yaml
templateDir: templates
files:
model-stub.mustache:
templateType: Model
destinationFilename: .pyi
$ java -jar openapi-generator-cli-5.0.0.jar generate -g python -c config.yaml -i api.yaml -o gen/
[main] INFO o.o.codegen.DefaultGenerator - Generating with dryRun=false
[main] WARN o.o.c.ignore.CodegenIgnoreProcessor - Output directory does not exist, or is inaccessible. No file (.openapi-generator-ignore) will be evaluated.
[main] INFO o.o.codegen.DefaultGenerator - OpenAPI Generator: python (client)
[main] INFO o.o.codegen.DefaultGenerator - Generator 'python' is considered experimental.
[main] INFO o.o.c.l.PythonLegacyClientCodegen - Environment variable PYTHON_POST_PROCESS_FILE not defined so the Python code may not be properly formatted. To define it, try 'export PYTHON_POST_PROCESS_FILE="/usr/local/bin/yapf -i"' (Linux/Mac)
[main] INFO o.o.c.l.PythonLegacyClientCodegen - NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).
[main] INFO o.o.c.languages.PythonClientCodegen - generateAliasAsModel is hard coded to true in this generator. Alias models will only be generated if they contain validations or enums
Exception in thread "main" java.lang.IllegalStateException: Duplicate key SupportingFile[templateFile='__init__model.mustache', folder='openapi_client/models', destinationFilename='__init__.py', canOverwrite=true]
at java.util.stream.Collectors.lambda$throwingMerger$0(Collectors.java:133)
at java.util.HashMap.merge(HashMap.java:1254)
at java.util.stream.Collectors.lambda$toMap$58(Collectors.java:1320)
at java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1384)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566)
at org.openapitools.codegen.DefaultGenerator.processUserDefinedTemplates(DefaultGenerator.java:941)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:869)
at org.openapitools.codegen.cmd.Generate.execute(Generate.java:432)
at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Steps to reproduce
- Create the above
api.yaml.
- Create the above
config.yaml.
- Create an empty
templates directory.
- Run the above
generate command.
Expected result
Should create a gen/openapi_client/model/test.pyi file according to templates/model-stub.mustache.
Related issues/PRs
Suggest a fix
It would appear that the use of templateType: model is causing the generator to add __init__model.mustache to the file list multiple times. There does not appear to be a way to prevent this.
As I am not redefining or providing a template for __init__model.mustache, it should not be trying to add it again.
Bug Report Checklist
Description
When adding a custom model template with the Python generator, an exception is thrown.
openapi-generator version
5.0.0
OpenAPI declaration file content or url
Generation Details
Following the instructions from https://github.com/OpenAPITools/openapi-generator/blob/master/docs/customization.md:
Steps to reproduce
api.yaml.config.yaml.templatesdirectory.generatecommand.Expected result
Should create a
gen/openapi_client/model/test.pyifile according totemplates/model-stub.mustache.Related issues/PRs
Suggest a fix
It would appear that the use of
templateType: modelis causing the generator to add__init__model.mustacheto the file list multiple times. There does not appear to be a way to prevent this.As I am not redefining or providing a template for
__init__model.mustache, it should not be trying to add it again.