openapi-generators / openapi-generators/openapi-python-client
Inline oneOf variants with properties/required fail: "Invalid property in union"
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 2k
- 分支
- 293
- 平均合併
- 34 分鐘
- 30 天內合併 PR
- 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/allOfcombinations - Both inline
oneOfandanyOfvariants trigger the same failure
Version
- openapi-python-client: 0.28.2
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
先使用最小重現執行 openapi-python-client generate --path spec.yaml,並追蹤回報 Invalid property in union 的 schema union 處理流程。Issue 中沒有指定原始碼檔案或測試路徑,因此先找到現有對基於 $ref 的 oneOf/anyOf 變體的處理方式。完成的標準是:具有 properties 和 required 的內嵌變體能成功產生,同時文件中的 $ref workaround 仍然有效。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- tooling
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 52/100