Skip to content

[BUG] [python-flask] [server] oneOf, anyOf Polymorphism does not work #7815

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
jethrogillgren opened this issue Oct 26, 2020 · 0 comments
Open

Comments

@jethrogillgren
Copy link

Description

Same as #7414, but with python-flask.

oneOf or anyOf elements cause invalid python code generated.

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  [...]
  File "/usr/src/app/openapi_server/controllers/default_controller.py", line 4, in <module>
    from openapi_server.models.one_of_cat_dog import OneOfCatDog  # noqa: E501
ModuleNotFoundError: No module named 'openapi_server.models.one_of_cat_dog'
openapi-generator version

4.3.1

OpenAPI declaration file content or url
openapi: "3.0.2"
info:
  version: 1.0.0
  title: Polymorphism
paths:
  /pets:
    post:
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/Cat'
                - $ref: '#/components/schemas/Dog'
              discriminator:
                propertyName: pet_type
      responses:
        '200':
          description: created
components:
  schemas:
    # Parent
    Pet:
      type: object
      required:
        - pet_type
      properties:
        pet_type:
          type: string
        eats:
          type: string
      discriminator:
        propertyName: pet_type
    # Child 1
    Dog:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          # all other properties specific to a `Dog`
          properties:
            bark:
              type: boolean
    # Child 2
    Cat:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          # all other properties specific to a `Cat`
          properties:
            climbs:
              type: boolean
Generation Details
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v4.3.1 generate --input-spec /local/openapi.yaml --generator-name python-flask --output /local
Steps to reproduce
  1. Run the above generation
  2. docker build -t openapi_server .
  3. docker run -p 8080:8080 openapi_server
Related issues/PRs

#6815
#5565
#7789

Thanks!

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