swagger-api / swagger-api/swagger-codegen

OneOf schema issues with C# code generation

Open
#11,826 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

OneOf schema issues with C# code generation

Please see attached Issue.png

The one on the left (1) is the “broken” one that won’t compile and the one to the right (2) is my “hotfix” to get this class to compile. However, I don’t actually know what model to use for the AppliesTo property and just randomly picked the AppliesToOffer class. In this scenario, if the server is returning AppliesToOfferProduct or AppliesToOfferProductSegment I will not be able to use those additional properties that those models have as my generated client code is unaware of those extra properties. If I pick the AppliesToOfferProductSegment, I will get deserialization errors if any mandatory properties in this model are not returned by the server e.g if the server response is the AppliesToOffer base class.

Swagger-codegen version

3.x

Swagger declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement

ExampleAPI.docx
IssueCsharp

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 attached ExampleAPI.docx and IssueCsharp image, then reproduce the problem using Swagger Codegen 3.x with the C# generator. Compare the generated OneOf models for AppliesToOffer, AppliesToOfferProduct, and AppliesToOfferProductSegment; done means the generated client compiles and handles each server response without losing variant properties or causing deserialization errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.