OpenAPITools / OpenAPITools/openapi-generator
[BUG] Schema mappings in configuration file do not work
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
I'm getting an error when I try to generate a model with a schema mappings defined in a config file.
openapi-generator version
6.4.0
OpenAPI declaration file content or url
Generation Details
Generating with --schema-mappings argument on the command line works:
openapi-generator-cli generate -i common_components.yaml -g cpp-pistache-server --schema-mapping Arm=org.openapitools.server.model.Arm
Steps to reproduce
If I try to move the schema mapping to a config file, I get an error:
openapi-generator-cli generate -i common_components.yaml -g cpp-pistache-server --config config.yaml
Config.yaml looks like this:
schemaMappings: "Arm=org.openapitools.server.model.Arm"
Results in the following error:
[main] ERROR o.o.c.config.CodegenConfigurator - Cannot construct instance of `java.util.LinkedHashMap` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('Arm=org.openapitools.server.model.Arm')
at [Source: (File); line: 2, column: 1] (through reference chain: org.openapitools.codegen.config.GeneratorSettings["schemaMappings"])
[main] ERROR o.o.c.config.CodegenConfigurator - Cannot construct instance of `java.util.LinkedHashMap` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('Arm=org.openapitools.server.model.Arm')
at [Source: (File); line: 2, column: 1] (through reference chain: org.openapitools.codegen.config.GeneratorSettings["schemaMappings"])
Exception in thread "main" java.lang.RuntimeException: Unable to deserialize config file: config.yaml
at org.openapitools.codegen.config.CodegenConfigurator.readDynamicSettings(CodegenConfigurator.java:171)
at org.openapitools.codegen.config.CodegenConfigurator.fromFile(CodegenConfigurator.java:90)
at org.openapitools.codegen.cmd.Generate.execute(Generate.java:314)
at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Related issues/PRs
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with CodegenConfigurator.readDynamicSettings and fromFile, then inspect GeneratorSettings.schemaMappings while reproducing the command using config.yaml. Compare the config-file value with the working --schema-mapping argument; done means the schema mapping is accepted from config.yaml and generation completes without the deserialization error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100