[BUG][C#] Generic host loses object oneOf values during serialization

Open
#25,547 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

  • #25549 by @AndreyVMarkelov — closed without merging

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
csharp
Domain
devtools

Research direction

Reproduce with the generation command and the spec in the issue, then deserialize {"name":"a","size":2} to Entry using the JsonSerializerOptions from the generated HostConfiguration and serialize it back. Linked pull request #25549 is already open against this bug, so review it before starting. Done means the round trip keeps name and size and the output is no longer {}.

Written by the indexing model from the issue text.

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

The C# generichost client serializes an object oneOf without a discriminator to {}, losing the selected variant's properties.

openapi-generator version

Reproduced on master 57edb417ea3fb15de7bc523a133c9cc016acab19 (7.28.0-SNAPSHOT).

OpenAPI declaration file content
openapi: 3.0.3
info:
  title: oneOf reproduction
  version: 1.0.0
paths: {}
components:
  schemas:
    Entry:
      oneOf:
        - $ref: '#/components/schemas/FileEntry'
        - $ref: '#/components/schemas/FolderEntry'
    FileEntry:
      type: object
      required: [name, size]
      properties:
        name:
          type: string
        size:
          type: integer
    FolderEntry:
      type: object
      required: [name, id]
      properties:
        name:
          type: string
        id:
          type: string
Generation Details
java -jar openapi-generator-cli.jar generate -g csharp --library generichost -i spec.yaml -o client --additional-properties=packageName=OneOfRepro
Steps to reproduce

With JsonSerializerOptions configured by generated HostConfiguration, deserialize {"name":"a","size":2} to Entry, then serialize it. Expected: the same object. Actual: {}.

Related issues/PRs

No matching issue found.

Suggest a fix

Write the active object variant's properties when serializing an object oneOf without a discriminator, preserving any properties declared on the wrapper.

Dominant language
Java
Stars
26.9k
Forks
7.8k
Avg merge
2d 23m
Merged PRs (30d)
177

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

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.

More from OpenAPITools/openapi-generator

All issues in OpenAPITools/openapi-generator

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.