Skip to content

[BUG] Broken generation of anyOf model in python client #8044

@generall

Description

@generall

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

Python client model is generated with broken validation in case of anyOf specification.
Model entry point tends to validate any option with the fields from latest entrance, which make it impossible to create instance other that the last option of anyOf.

openapi-generator version

latest + v5.0.0-beta3

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: Bug API
  version: 0.1.0

paths:
  /test/:
  
    post:
      summary: Update points in collection
      operationId: update_points
      requestBody:
        description: Points update operations
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/PayloadInterface"
  
      responses:
        200:
          description: successful operation


components:
  schemas:
    PayloadInterface:
      anyOf:
      - properties:
          type:
            enum:
            - keyword
            type: string
          value:
            type: string
        required:
        - type
        - value
        type: object
      - properties:
          type:
            enum:
            - float
            type: string
          value:
            format: double
            type: number
        required:
        - type
        - value
        type: object
Generation Details
docker run --rm \
    -u $(id -u ${USER}):$(id -g ${USER}) \
    -v "${PWD}:/local" openapitools/openapi-generator-cli:latest generate \
    -i /local/openapi.yaml \
    -g python \
    -o /local/test_client
Steps to reproduce
  • Generate client with given specification and command.
  • Try to create model PayloadInterface with model = PayloadInterface(value="text", type="keyword")
  • Observe error: Invalid value for 'type' (keyword), must be one of ['float']
Related issues/PRs
Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions