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
Version
- openapi-python-client: 0.28.2
Description
When a schema uses
oneOfwith inline object variants (each havingpropertiesandrequiredbut no$ref), the generator fails with:This happens regardless of whether
anyOforoneOfis used. The issue is that the generator cannot process inline discriminated union variants that define their own properties — it expects$refpointers to named component schemas.Minimal Reproduction
Workaround
Extracting each variant into a named component schema and using
$refworks:Related
anyOf/allOfcombinationsoneOfandanyOfvariants trigger the same failureVersion