Skip to content

[BUG][python-experimental] generation of oneOf interfaces not working for oneOf usage in properties - leads to import error #6161

@niderhoff

Description

@niderhoff

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used? 4.3.1-SNAPSHOT (jar)
  • Have you search for related issues/PRs? yes found Fix generation of oneOf interfaces for oneOf usage in properties #5400 but nothing related to python client
  • What's the actual output vs expected output? classes should be generated
Description

When using oneOf to match properties inside a schema, the oneOf-classes are not generated which leads to an import error.

openapi-generator version
$ java -jar /c/Develop/projects/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar version
4.3.1-SNAPSHOT
OpenAPI declaration file content or url
openapi: "3.0.3"
info:
  version: 0.0.0
  title: Simple API
paths:
  /:
    get:
      responses:
        200:
          description: OK

components:
  schemas:

    TransA:
      type: object
      properties:
        function:
          type: string
          default: abs
      required:
        - function

    TransB:
      type: object
      properties:
        function:
          type: string
          default: bin
      required:
        - function


    TransParent:
        type: "object"
        properties:
          transformation:
            oneOf:
              - $ref: '#/components/schemas/TransA'
              - $ref: '#/components/schemas/TransB'
Command line used for generation
java -jar /c/Develop/projects/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i test_openapi.yaml -g python-experimental -o test_openapi/ && cp -r test_openapi/openapi_client .
Steps to reproduce
import openapi_client

output:

Traceback (most recent call last):
  File "c:\Develop\projects\openapi\openapi_client\models\trans_parent.py", line 33, in <module>
    from openapi_client.models import one_of_trans_a_trans_b
ImportError: cannot import name 'one_of_trans_a_trans_b'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:/Develop/projects/openapi/apicheck.py", line 1, in <module>
    import openapi_client
  File "c:\Develop\projects\openapi\openapi_client\__init__.py", line 38, in <module>
    from openapi_client.models.trans_parent import TransParent
  File "c:\Develop\projects\openapi\openapi_client\models\trans_parent.py", line 36, in <module>
    'openapi_client.models.one_of_trans_a_trans_b']
KeyError: 'openapi_client.models.one_of_trans_a_trans_b'
Related issues/PRs

original PR adding this functionality: #5341
background info: #5791
similar PR: #5400 (merged)
similar issues: #5903 (open), #5730 (open)

Suggest a fix

Implement generation of models.one_of_xxxx-classes

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