OpenAPITools / OpenAPITools/openapi-generator

[BUG] CLI 7.0.0+ [CSharp] code generation ignores typemappings

Open
#16,431 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • [Y] Have you tested with the latest master to confirm the issue still exists?
  • [Y] Have you searched for related issues/PRs?
  • [Y] What's the actual output vs expected output?
Description

At Version 7.0.0+ (including current 7.0.1-SNAPSHOT)

Running CLI. For instance
openapi-generator-cli.sh generate -g aspnetcore -i openapi.json --type-mappings string=banana

Typemappings command line argument are ignored and not applied to generation.

The reason for this, I believe, is the following:

AbstractCSharpCodegen.java removes command line typemappings.

AbstractCSharpCodegen.java declares protected void setTypeMapping() That method is also overriden by subclasses. That method is called as part of public void processOpts()

That method creates a new typeMappings HashMap smashing current hashmap content. Values from command line configuration were added to smashed typeMapping and then they are lost.

Suggest a fix

All the model initialization seems rather complex. Maybe just keeping the customTypeMappings and the default generator typeMappings in different variables and then have a simple fallback mechanism when schema types are resolved.

I hacked a workaround similar to what I described and the issue is fixed.

Additionally:
Your cli tests pass because generation part is mocked.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with AbstractCSharpCodegen.java and trace processOpts() through setTypeMapping(), then reproduce the CLI command using the aspnetcore generator and --type-mappings string=banana. Check generated output rather than relying only on the existing CLI tests, since the issue says generation is mocked there. Done means the command-line type mapping is retained and applied during C# generation.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, java, openapi
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.