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

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

Offen
#1,428 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
2k
Forks
293
Ø Merge
34 Min.
Gemergte PRs (30 T.)
1

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der Ausführung von openapi-python-client generate --path spec.yaml mit der minimalen Reproduktion und verfolge die Verarbeitung von Schema-Unions, die Invalid property in union meldet. Da im Issue keine Quelldatei oder kein Testpfad genannt wird, finde zuerst die bestehende Behandlung von $ref-basierten oneOf/anyOf-Varianten. Erledigt ist die Aufgabe, wenn Inline-Varianten mit properties und required erfolgreich generiert werden, während der dokumentierte $ref-Workaround weiterhin funktioniert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
tooling
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
52/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.