Skip to content

[BUG] [python-flask] Polymorphism causes imports to non-existent models #4421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
5 of 6 tasks
frjonsen opened this issue Nov 8, 2019 · 2 comments
Open
5 of 6 tasks

Comments

@frjonsen
Copy link

frjonsen commented Nov 8, 2019

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?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

When attempting to use polymorphism as described here in the specification controllers will contain import statements to models which have not been generated

openapi-generator version

Tested with 4.1.3, as well as snapshots of 4.2.1 and 5.0.0. Issue exists in all tested versions.

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Python polymorphism bug
  version: 1.0.0
paths:
  "/foo":
    post:
      responses:
        "200":
          description: "Success"
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: "#/components/schemas/Bar"
                  - $ref: "#/components/schemas/Baz"
components:
  schemas:
    Foo:
      type: object
      properties:
        prop1:
          type: string
    Bar:
      allOf:
        - $ref: "#/components/schemas/Foo"
        - type: object
          properties:
            prop2:
              type: string
    Baz:
      allOf:
        - $ref: "#/components/schemas/Foo"
        - type: object
          properties:
            prop3:
              type: string
Command line used for generation

java -jar openapi-generator-cli-4.1.3.jar generate -g python-flask -i openapi.yml

Steps to reproduce
  1. Copy above yaml to openapi.yml
  2. Run command from above

openapi_server/controllers/default_controller.py now contains the line
from openapi_server.models.any_of_bar_baz import AnyOfBarBaz. AnyOfBarBaz is not a model which has been generated.

@auto-labeler
Copy link

auto-labeler bot commented Nov 8, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@AIexG
Copy link
Contributor

AIexG commented Nov 8, 2019

Unfortunately the default codegen still doesn't support heterogeneous lists as of now, polymorphism itself works, even though not perfectly. I've seen lots of issues being related to the same problem (e.g. #15 #500 #2845 #4239)

The branch improve_flatten also improves the generation of inhereted classes and removes generation of "bar_allOf.*" files, if they are a problem with your generator. Though it does not yet fix problems with anyOf Edit: branch doesn't exist anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants