swagger-api / swagger-api/swagger-codegen

[csharp] JsonSubtypes discriminator property missing in serialized json

Open
#9,261 2 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

When using inheritance for api model objects, with a discriminator property, the JsonSubTypes converter doesn't include this property in the serialized json string (whereas it is used during deserialization).
This leads to unusable code, as the serialized object cannot be posted/put to an api endpoint which needs to deserialize the object on the server side.

Swagger-codegen version

2.4.3-SNAPSHOT

Related issues/PRs

#8455 describes an example for inherited model objects

Suggest a fix/enhancement

Suggested fix: make use of JsonSubtypesConverterBuilder for supporting serialization of discriminator properties.
Example of using JsonSubtypesConverterBuilder for serialization and deserialization

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 the C# JsonSubTypes converter behavior and the JsonSubtypesConverterBuilder serialization example linked in the issue. Reproduce serialization for an inherited API model with a discriminator property, then verify that the serialized JSON includes the discriminator and remains usable for server-side deserialization.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
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.