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

オープン
#25,547 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

  • #25549 @AndreyVMarkelov による — マージされずにクローズ

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
csharp
領域
devtools

調査の方向性

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 {}.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Java
スター
26.9k
フォーク
7.8k
平均マージ
2日 10時間
マージ済み PR(30日)
180

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

OpenAPITools/openapi-generator のほかの issue

OpenAPITools/openapi-generator の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。