openapi-generators / openapi-generators/openapi-python-client

Inline oneOf variants with properties/required fail: "Invalid property in union"

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

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

主要言語
Python
スター
2k
フォーク
293
平均マージ
34分
マージ済み PR(30日)
1

説明

Description

When a schema uses oneOf with inline object variants (each having properties and required but no $ref), the generator fails with:

Invalid property in union <property_name>

This happens regardless of whether anyOf or oneOf is used. The issue is that the generator cannot process inline discriminated union variants that define their own properties — it expects $ref pointers to named component schemas.

Minimal Reproduction

openapi: "3.0.3"
info:
  title: Test
  version: "1.0"
paths: {}
components:
  schemas:
    MyModel:
      type: object
      properties:
        rules:
          type: array
          items:
            type: object
            oneOf:
              - properties:
                  rule_type:
                    type: string
                    enum: ["type_a"]
                  value_a:
                    type: string
                required: ["rule_type", "value_a"]
              - properties:
                  rule_type:
                    type: string
                    enum: ["type_b"]
                  value_b:
                    type: integer
                required: ["rule_type", "value_b"]
$ openapi-python-client generate --path spec.yaml
Unable to process schema /components/schemas/MyModel:
Invalid property in union rules_item

Workaround

Extracting each variant into a named component schema and using $ref works:

components:
  schemas:
    RuleTypeA:
      type: object
      properties:
        rule_type:
          type: string
          enum: ["type_a"]
        value_a:
          type: string
      required: ["rule_type", "value_a"]
    RuleTypeB:
      type: object
      properties:
        rule_type:
          type: string
          enum: ["type_b"]
        value_b:
          type: integer
      required: ["rule_type", "value_b"]
    MyModel:
      type: object
      properties:
        rules:
          type: array
          items:
            oneOf:
              - $ref: "#/components/schemas/RuleTypeA"
              - $ref: "#/components/schemas/RuleTypeB"

Related

  • #868 — similar "Invalid property in union" error with anyOf/allOf combinations
  • Both inline oneOf and anyOf variants trigger the same failure

Version

  • openapi-python-client: 0.28.2

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

調査の方向性

まず最小限の再現ケースで openapi-python-client generate --path spec.yaml を実行し、Invalid property in union を報告するスキーマユニオンの処理を追跡してください。Issue にはソースファイルやテストパスが記載されていないため、最初に $ref ベースの oneOf/anyOf バリアントを既存のどのように処理しているかを見つけてください。propertiesrequired を持つインラインバリアントが正常に生成され、文書化された $ref の回避策も引き続き機能すれば完了です。

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

評価

技術スタック
python
領域
tooling
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
52/100

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

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