OpenAPITools / OpenAPITools/openapi-generator
[BUG] Issue with python client and open api spec with discriminator
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The recursion is in generated test/openapi_client/model_utils.py, reached through test/openapi_client/api_client.py during the provided Java generation command. Reproduce the issue with the supplied YAML and generated Python client, then verify that the discriminator request no longer raises RecursionError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, python
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100