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

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

Abierto
#1,428 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Python
Estrellas
2k
Forks
293
Merge medio
34 min
PR fusionados (30 d)
1

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza ejecutando openapi-python-client generate --path spec.yaml con la reproducción mínima y sigue el procesamiento de uniones de esquemas que informa de Invalid property in union. Como en el issue no se menciona ningún archivo de código fuente ni ruta de prueba, localiza primero el manejo existente de variantes oneOf/anyOf basadas en $ref. El trabajo estará terminado cuando las variantes inline con properties y required se generen correctamente, mientras el workaround documentado de $ref siga funcionando.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
tooling
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
52/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.