OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.24k stars 6.43k forks source link

[BUG] Issue with python client and open api spec with discriminator #8851

Open luciotudisco opened 3 years ago

luciotudisco commented 3 years ago

Bug Report Checklist

Description

Issue with python client and open api spec with discriminator object

openapi-generator version

openapi-generator-cli-5.0.1.jar

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Test Inheritance
  version: 1.0.0
servers:
  - url: /
paths:
  /test:
    get:
      operationId: test
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Dog"
        required: true
      responses:
        "200":
          description: Success
        default:
          description: Unexpected Error

components:
  schemas:
    Pet:
      type: object
      required:
        - petType
      properties:
        petType:
          type: string
      discriminator:
        propertyName: petType
        mapping:
          dog: Dog
    Cat:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          properties:
            name:
              type: string
    Dog:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          properties:
            bark:
              type: string
    Lizard:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          properties:
            lovesRocks:
              type: boolean
Generation Details
Steps to reproduce

Generate the python client using openapi-generator-cli-5.0.1.jar

java -jar openapi-generator-cli-5.0.1.jar generate -g python -i api.yaml -o out

The execute the following code:

dog = Dog(name='Nora', pet_type='dog')
configuration = Configuration(host=f"http://localhost")
api_client = ApiClient(configuration=configuration)
self.api_instance = DefaultApi(api_client)
self.api_instance.test(dog=dog)

The following error happens:

File "test/openapi_client/api_client.py", line 771, in __call__
    return self.callable(self, *args, **kwargs)
  File "test/openapi_client/api/default_api.py", line 102, in __test
    return self.call_with_http_info(**kwargs)
  File "test/openapi_client/api_client.py", line 818, in call_with_http_info
    self.__validate_inputs(kwargs)
  File "test/openapi_client/api_client.py", line 712, in __validate_inputs
    fixed_val = validate_and_convert_types(
  File "test/openapi_client/model_utils.py", line 1386, in validate_and_convert_types
    results = get_required_type_classes(required_types_mixed, spec_property_naming)
  File "test/openapi_client/model_utils.py", line 1017, in get_required_type_classes
    valid_classes.extend(get_possible_classes(required_type, spec_property_naming))
  File "test/openapi_client/model_utils.py", line 977, in get_possible_classes
    possible_classes.extend(get_discriminated_classes(cls))
  File "test/openapi_client/model_utils.py", line 964, in get_discriminated_classes
    possible_classes.extend(get_discriminated_classes(discr_cls))
  File "test/openapi_client/model_utils.py", line 964, in get_discriminated_classes
    possible_classes.extend(get_discriminated_classes(discr_cls))
  File "test/openapi_client/model_utils.py", line 964, in get_discriminated_classes
    possible_classes.extend(get_discriminated_classes(discr_cls))
  [Previous line repeated 970 more times]
  File "test/openapi_client/model_utils.py", line 960, in get_discriminated_classes
    if is_type_nullable(cls):
  File "test/openapi_client/model_utils.py", line 1319, in is_type_nullable
    for t in input_type._composed_schemas.get('oneOf', ()):
  File "test/openapi_client/model_utils.py", line 42, in __get__
    if self.result_key in vars(self):
RecursionError: maximum recursion depth exceeded while calling a Python object
Related issues/PRs
Suggest a fix
auto-labeler[bot] commented 3 years ago

👍 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.