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

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

Open
#1,428 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2k
Forks
293
Avg merge
34m
Merged PRs (30d)
1

Description

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

Contributor guide

Open the contributing guide

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.

Research direction

Start by running openapi-python-client generate --path spec.yaml with the minimal reproduction and trace the schema-union processing that reports Invalid property in union. No source file or test path is named in the issue, so locate the existing handling for $ref-based oneOf/anyOf variants first. Done means inline variants with properties and required generate successfully, while the documented $ref workaround remains working.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.