swagger-api / swagger-api/swagger-codegen
[CSharp] Discriminator mapping is not working correctly.
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Discriminator mapping is outputting the class name instead of the mapping name.
Swagger-codegen version
3.0.31
Swagger declaration file content or url
schema: https://gist.github.com/rafaladamczyk/7e4979d1f722f8cb185b8732a30dc189
generated model: https://gist.github.com/rafaladamczyk/37502a538c79d2d09f6d07c7711c4fd4
Command line used for generation
java -jar .\sgen.jar generate -i .\animal.json -l csharp -o Example
Steps to reproduce
- Run csharp code generator against an open api schema with discriminator mappings defined, such as the example provided above.
- Observe the generated model of a base class. It specifies incorrect discriminator values for the derived classes.
Actual:

Expected:

Related issues/PRs
didn't find any
Suggest a fix/enhancement
It seems that given a (name, value) mapping, the code generator is incorrectly picking value, dereferencing it and outputting the dereferenced class name.
Instead it should output the name.
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
Run the provided Java command with the linked OpenAPI schema and inspect the generated C# base model, comparing its discriminator values with the expected image. Trace how the C# generator handles each discriminator mapping, then verify that generated values use the mapping names rather than dereferenced class names.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100