swagger-api / swagger-api/swagger-codegen

[CSharp] Discriminator mapping is not working correctly.

Open
#11,709 0 comments 0 reactions 0 assignees View on GitHub

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
  1. Run csharp code generator against an open api schema with discriminator mappings defined, such as the example provided above.
  2. Observe the generated model of a base class. It specifies incorrect discriminator values for the derived classes.

Actual:
image

Expected:
image

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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.