mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-18 21:47:04 +00:00
[python-experimental] Support schema property which has $ref to 'oneOf' schema (#6262)
* Add reference to oneOf schema * Add model showing unit test failure with ref to oneOf schema * Updates get_discriminator_class to return visited_composed_classes * Fixes broken test, adds is_valid_type * move unit test to test_drawing.py file * Add more unit tests * invoke git pull from spacether fork * invoke git pull from spacether fork * Improve unit tests Co-authored-by: Justin Black <justin.a.black@gmail.com>
This commit is contained in:
@@ -1138,6 +1138,31 @@ def attempt_convert_item(input_value, valid_classes, path_to_item,
|
||||
return input_value
|
||||
|
||||
|
||||
def is_valid_type(input_class_simple, valid_classes):
|
||||
"""
|
||||
Args:
|
||||
input_class_simple (class): the class of the input_value that we are
|
||||
checking
|
||||
valid_classes (tuple): the valid classes that the current item
|
||||
should be
|
||||
Returns:
|
||||
bool
|
||||
"""
|
||||
valid_type = input_class_simple in valid_classes
|
||||
if not valid_type and issubclass(input_class_simple, OpenApiModel):
|
||||
for valid_class in valid_classes:
|
||||
if not valid_class.discriminator:
|
||||
continue
|
||||
discr_propertyname_py = list(valid_class.discriminator.keys())[0]
|
||||
discriminator_classes = (
|
||||
valid_class.discriminator[discr_propertyname_py].values()
|
||||
)
|
||||
valid_type = is_valid_type(input_class_simple, discriminator_classes)
|
||||
if valid_type:
|
||||
return True
|
||||
return valid_type
|
||||
|
||||
|
||||
def validate_and_convert_types(input_value, required_types_mixed, path_to_item,
|
||||
from_server, _check_type, configuration=None):
|
||||
"""Raises a TypeError is there is a problem, otherwise returns value
|
||||
@@ -1170,7 +1195,7 @@ def validate_and_convert_types(input_value, required_types_mixed, path_to_item,
|
||||
valid_classes, child_req_types_by_current_type = results
|
||||
|
||||
input_class_simple = get_simple_class(input_value)
|
||||
valid_type = input_class_simple in set(valid_classes)
|
||||
valid_type = is_valid_type(input_class_simple, valid_classes)
|
||||
if not valid_type:
|
||||
if configuration:
|
||||
# if input_value is not valid_type try to convert it
|
||||
|
||||
Reference in New Issue
Block a user