question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Broken generation of anyOf model in python client

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pbortlovcommented, Mar 16, 2021

#8892 Is it connected?

0reactions
spacethercommented, Sep 16, 2022

This works in python-experimental please use it

Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG][PYTHON] Using Openapi 3.0 Inheritance/Polymorphism ...
[BUG][PYTHON] Using Openapi 3.0 Inheritance/Polymorphism keywords (allOf, anyOf, oneOf) causes generation of UNKNOWNBASETYPE model. #8892.
Read more >
DataStax Python Driver - CHANGELOG
DETERMINISTIC clause in AGGREGATE misplaced in CQL generation (PYTHON-963). graph module import cause a DLL issue on Windows due to its cythonizing failure ......
Read more >
What's New In Python 3.9 — Python 3.11.1 documentation
For the majority of use cases, users can leverage the Abstract Syntax Tree (AST) generation and compilation stage, using the ast module. The...
Read more >
Troubleshoot Dataflow errors - Google Cloud
If you run into problems with your Dataflow pipeline or job, this page lists error messages that you might see and provides suggestions...
Read more >
An adventure in OpenAPI V3 code generation | Mux blog
OpenAPI Generator is a comprehensive Java application which can generate client and server side code from your OpenAPI models.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found