From 5ae3489b64abd3ff7b3e247fd5eb3b4c8c0c8a24 Mon Sep 17 00:00:00 2001
From: Justin Black <justin.a.black@gmail.com>
Date: Fri, 18 Nov 2022 14:27:20 -0800
Subject: [PATCH 1/4] Template update

---
 .../main/resources/python/schemas.handlebars  | 45 ++++++++++++-------
 1 file changed, 29 insertions(+), 16 deletions(-)

diff --git a/modules/openapi-generator/src/main/resources/python/schemas.handlebars b/modules/openapi-generator/src/main/resources/python/schemas.handlebars
index 22999b13062..f06267b4045 100644
--- a/modules/openapi-generator/src/main/resources/python/schemas.handlebars
+++ b/modules/openapi-generator/src/main/resources/python/schemas.handlebars
@@ -141,6 +141,19 @@ class ValidationMetadata(frozendict.frozendict):
         return self.get('validated_path_to_schemas')
 
 
+def add_deeper_validated_schemas(validation_metadata: ValidationMetadata, path_to_schemas: dict):
+    # this is called if validation_ran_earlier and current and deeper locations need to be added
+    current_path_to_item = validation_metadata.path_to_item
+    other_path_to_schemas = {}
+    for path_to_item, schemas in validation_metadata.validated_path_to_schemas.items():
+        if len(path_to_item) < len(current_path_to_item):
+            continue
+        path_begins_with_current_path = path_to_item[:len(current_path_to_item)] == current_path_to_item
+        if path_begins_with_current_path:
+            other_path_to_schemas[path_to_item] = schemas
+    update(path_to_schemas, other_path_to_schemas)
+
+
 class Singleton:
     """
     Enums and singletons are the same
@@ -385,9 +398,9 @@ class Schema:
             because value is of the correct type, and validation was run earlier when the instance was created
         """
         _path_to_schemas = {}
-        if validation_metadata.validated_path_to_schemas:
-            update(_path_to_schemas, validation_metadata.validated_path_to_schemas)
-        if not validation_metadata.validation_ran_earlier(cls):
+        if validation_metadata.validation_ran_earlier(cls):
+            add_deeper_validated_schemas(validation_metadata, _path_to_schemas)
+        else:
             other_path_to_schemas = cls._validate_oapg(arg, validation_metadata=validation_metadata)
             update(_path_to_schemas, other_path_to_schemas)
         # loop through it make a new class for each entry
@@ -1325,6 +1338,7 @@ class ListBase(ValidatorBase):
                 validated_path_to_schemas=validation_metadata.validated_path_to_schemas
             )
             if item_validation_metadata.validation_ran_earlier(item_cls):
+                add_deeper_validated_schemas(item_validation_metadata, path_to_schemas)
                 continue
             other_path_to_schemas = item_cls._validate_oapg(
                 value, validation_metadata=item_validation_metadata)
@@ -1588,6 +1602,7 @@ class DictBase(Discriminable, ValidatorBase):
                 validated_path_to_schemas=validation_metadata.validated_path_to_schemas
             )
             if arg_validation_metadata.validation_ran_earlier(schema):
+                add_deeper_validated_schemas(arg_validation_metadata, path_to_schemas)
                 continue
             other_path_to_schemas = schema._validate_oapg(value, validation_metadata=arg_validation_metadata)
             update(path_to_schemas, other_path_to_schemas)
@@ -1676,6 +1691,7 @@ class DictBase(Discriminable, ValidatorBase):
             validated_path_to_schemas=validation_metadata.validated_path_to_schemas
         )
         if updated_vm.validation_ran_earlier(discriminated_cls):
+            add_deeper_validated_schemas(updated_vm, _path_to_schemas)
             return _path_to_schemas
         other_path_to_schemas = discriminated_cls._validate_oapg(arg, validation_metadata=updated_vm)
         update(_path_to_schemas, other_path_to_schemas)
@@ -1774,18 +1790,11 @@ def cast_to_allowed_types(
     if isinstance(arg, Schema):
         # store the already run validations
         schema_classes = set()
-        source_schema_was_unset = len(arg.__class__.__bases__) == 2 and UnsetAnyTypeSchema in arg.__class__.__bases__
-        if not source_schema_was_unset:
-            """
-            Do not include UnsetAnyTypeSchema and its base class because
-            it did not exist in the original spec schema definition
-            It was added to ensure that all instances are of type Schema and the allowed base types
-            """
-            for cls in arg.__class__.__bases__:
-                if cls is Singleton:
-                    # Skip Singleton
-                    continue
-                schema_classes.add(cls)
+        for cls in arg.__class__.__bases__:
+            if cls is Singleton:
+                # Skip Singleton
+                continue
+            schema_classes.add(cls)
         validated_path_to_schemas[path_to_item] = schema_classes
 
     type_error = ApiTypeError(f"Invalid type. Required value type is str and passed type was {type(arg)} at {path_to_item}")
@@ -1838,6 +1847,7 @@ class ComposedBase(Discriminable):
         path_to_schemas = defaultdict(set)
         for allof_cls in cls.MetaOapg.all_of():
             if validation_metadata.validation_ran_earlier(allof_cls):
+                add_deeper_validated_schemas(validation_metadata, path_to_schemas)
                 continue
             other_path_to_schemas = allof_cls._validate_oapg(arg, validation_metadata=validation_metadata)
             update(path_to_schemas, other_path_to_schemas)
@@ -1858,6 +1868,7 @@ class ComposedBase(Discriminable):
                 continue
             if validation_metadata.validation_ran_earlier(oneof_cls):
                 oneof_classes.append(oneof_cls)
+                add_deeper_validated_schemas(validation_metadata, path_to_schemas)
                 continue
             try:
                 path_to_schemas = oneof_cls._validate_oapg(arg, validation_metadata=validation_metadata)
@@ -1915,6 +1926,7 @@ class ComposedBase(Discriminable):
         for anyof_cls in cls.MetaOapg.any_of():
             if validation_metadata.validation_ran_earlier(anyof_cls):
                 anyof_classes.append(anyof_cls)
+                add_deeper_validated_schemas(validation_metadata, path_to_schemas)
                 continue
 
             try:
@@ -2044,6 +2056,7 @@ class ComposedBase(Discriminable):
 
         if discriminated_cls is not None and not updated_vm.validation_ran_earlier(discriminated_cls):
             # TODO use an exception from this package here
+            add_deeper_validated_schemas(updated_vm, path_to_schemas)
             assert discriminated_cls in path_to_schemas[updated_vm.path_to_item]
         return path_to_schemas
 
@@ -2492,4 +2505,4 @@ LOG_CACHE_USAGE = False
 
 def log_cache_usage(cache_fn):
     if LOG_CACHE_USAGE:
-        print(cache_fn.__name__, cache_fn.cache_info())
+        print(cache_fn.__name__, cache_fn.cache_info())
\ No newline at end of file
-- 
GitLab


From 530055e62dae5f6848453f6409010faa26bbfa55 Mon Sep 17 00:00:00 2001
From: Justin Black <justin.a.black@gmail.com>
Date: Fri, 18 Nov 2022 14:28:31 -0800
Subject: [PATCH 2/4] Adds test file

---
 .../petstore/python/tests_manual/test_pet.py  | 37 +++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 samples/openapi3/client/petstore/python/tests_manual/test_pet.py

diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_pet.py b/samples/openapi3/client/petstore/python/tests_manual/test_pet.py
new file mode 100644
index 00000000000..e82f29ccaa3
--- /dev/null
+++ b/samples/openapi3/client/petstore/python/tests_manual/test_pet.py
@@ -0,0 +1,37 @@
+ coding: utf-8
+
+"""
+    OpenAPI Petstore
+    This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\  # noqa: E501
+    The version of the OpenAPI document: 1.0.0
+    Generated by: https://openapi-generator.tech
+"""
+
+import decimal
+import unittest
+
+from petstore_api.model import pet
+from petstore_api.model import category
+
+
+class TesttPet(unittest.TestCase):
+    """ParentPet unit test stubs"""
+
+    def testPet(self):
+        cat = category.Category(name='hi', addprop={'a': 1})
+        inst = pet.Pet(photoUrls=[], name='Katsu', category=cat)
+        self.assertEqual(
+            inst,
+            {
+                'photoUrls': (),
+                'name': 'Katsu',
+                'category': {
+                    'name': 'hi',
+                    'addprop': {'a': decimal.Decimal('1')}
+                }
+            }
+        )
+
+
+if __name__ == '__main__':
+    unittest.main()
\ No newline at end of file
-- 
GitLab


From 2445fa2f94246735a549b45d54f2c696be043733 Mon Sep 17 00:00:00 2001
From: Justin Black <justin.a.black@gmail.com>
Date: Fri, 18 Nov 2022 14:35:56 -0800
Subject: [PATCH 3/4] Samples regenerated

---
 .../python/unit_test_api/schemas.py           | 45 ++++++++++++-------
 .../python/dynamic_servers/schemas.py         | 45 ++++++++++++-------
 .../petstore/python/petstore_api/schemas.py   | 45 ++++++++++++-------
 3 files changed, 87 insertions(+), 48 deletions(-)

diff --git a/samples/openapi3/client/3_0_3_unit_test/python/unit_test_api/schemas.py b/samples/openapi3/client/3_0_3_unit_test/python/unit_test_api/schemas.py
index d6c0284ab19..ce7d7eaf827 100644
--- a/samples/openapi3/client/3_0_3_unit_test/python/unit_test_api/schemas.py
+++ b/samples/openapi3/client/3_0_3_unit_test/python/unit_test_api/schemas.py
@@ -148,6 +148,19 @@ class ValidationMetadata(frozendict.frozendict):
         return self.get('validated_path_to_schemas')
 
 
+def add_deeper_validated_schemas(validation_metadata: ValidationMetadata, path_to_schemas: dict):
+    # this is called if validation_ran_earlier and current and deeper locations need to be added
+    current_path_to_item = validation_metadata.path_to_item
+    other_path_to_schemas = {}
+    for path_to_item, schemas in validation_metadata.validated_path_to_schemas.items():
+        if len(path_to_item) < len(current_path_to_item):
+            continue
+        path_begins_with_current_path = path_to_item[:len(current_path_to_item)] == current_path_to_item
+        if path_begins_with_current_path:
+            other_path_to_schemas[path_to_item] = schemas
+    update(path_to_schemas, other_path_to_schemas)
+
+
 class Singleton:
     """
     Enums and singletons are the same
@@ -392,9 +405,9 @@ class Schema:
             because value is of the correct type, and validation was run earlier when the instance was created
         """
         _path_to_schemas = {}
-        if validation_metadata.validated_path_to_schemas:
-            update(_path_to_schemas, validation_metadata.validated_path_to_schemas)
-        if not validation_metadata.validation_ran_earlier(cls):
+        if validation_metadata.validation_ran_earlier(cls):
+            add_deeper_validated_schemas(validation_metadata, _path_to_schemas)
+        else:
             other_path_to_schemas = cls._validate_oapg(arg, validation_metadata=validation_metadata)
             update(_path_to_schemas, other_path_to_schemas)
         # loop through it make a new class for each entry
@@ -1332,6 +1345,7 @@ class ListBase(ValidatorBase):
                 validated_path_to_schemas=validation_metadata.validated_path_to_schemas
             )
             if item_validation_metadata.validation_ran_earlier(item_cls):
+                add_deeper_validated_schemas(item_validation_metadata, path_to_schemas)
                 continue
             other_path_to_schemas = item_cls._validate_oapg(
                 value, validation_metadata=item_validation_metadata)
@@ -1595,6 +1609,7 @@ class DictBase(Discriminable, ValidatorBase):
                 validated_path_to_schemas=validation_metadata.validated_path_to_schemas
             )
             if arg_validation_metadata.validation_ran_earlier(schema):
+                add_deeper_validated_schemas(arg_validation_metadata, path_to_schemas)
                 continue
             other_path_to_schemas = schema._validate_oapg(value, validation_metadata=arg_validation_metadata)
             update(path_to_schemas, other_path_to_schemas)
@@ -1683,6 +1698,7 @@ class DictBase(Discriminable, ValidatorBase):
             validated_path_to_schemas=validation_metadata.validated_path_to_schemas
         )
         if updated_vm.validation_ran_earlier(discriminated_cls):
+            add_deeper_validated_schemas(updated_vm, _path_to_schemas)
             return _path_to_schemas
         other_path_to_schemas = discriminated_cls._validate_oapg(arg, validation_metadata=updated_vm)
         update(_path_to_schemas, other_path_to_schemas)
@@ -1781,18 +1797,11 @@ def cast_to_allowed_types(
     if isinstance(arg, Schema):
         # store the already run validations
         schema_classes = set()
-        source_schema_was_unset = len(arg.__class__.__bases__) == 2 and UnsetAnyTypeSchema in arg.__class__.__bases__
-        if not source_schema_was_unset:
-            """
-            Do not include UnsetAnyTypeSchema and its base class because
-            it did not exist in the original spec schema definition
-            It was added to ensure that all instances are of type Schema and the allowed base types
-            """
-            for cls in arg.__class__.__bases__:
-                if cls is Singleton:
-                    # Skip Singleton
-                    continue
-                schema_classes.add(cls)
+        for cls in arg.__class__.__bases__:
+            if cls is Singleton:
+                # Skip Singleton
+                continue
+            schema_classes.add(cls)
         validated_path_to_schemas[path_to_item] = schema_classes
 
     type_error = ApiTypeError(f"Invalid type. Required value type is str and passed type was {type(arg)} at {path_to_item}")
@@ -1845,6 +1854,7 @@ class ComposedBase(Discriminable):
         path_to_schemas = defaultdict(set)
         for allof_cls in cls.MetaOapg.all_of():
             if validation_metadata.validation_ran_earlier(allof_cls):
+                add_deeper_validated_schemas(validation_metadata, path_to_schemas)
                 continue
             other_path_to_schemas = allof_cls._validate_oapg(arg, validation_metadata=validation_metadata)
             update(path_to_schemas, other_path_to_schemas)
@@ -1865,6 +1875,7 @@ class ComposedBase(Discriminable):
                 continue
             if validation_metadata.validation_ran_earlier(oneof_cls):
                 oneof_classes.append(oneof_cls)
+                add_deeper_validated_schemas(validation_metadata, path_to_schemas)
                 continue
             try:
                 path_to_schemas = oneof_cls._validate_oapg(arg, validation_metadata=validation_metadata)
@@ -1898,6 +1909,7 @@ class ComposedBase(Discriminable):
         for anyof_cls in cls.MetaOapg.any_of():
             if validation_metadata.validation_ran_earlier(anyof_cls):
                 anyof_classes.append(anyof_cls)
+                add_deeper_validated_schemas(validation_metadata, path_to_schemas)
                 continue
 
             try:
@@ -2011,6 +2023,7 @@ class ComposedBase(Discriminable):
 
         if discriminated_cls is not None and not updated_vm.validation_ran_earlier(discriminated_cls):
             # TODO use an exception from this package here
+            add_deeper_validated_schemas(updated_vm, path_to_schemas)
             assert discriminated_cls in path_to_schemas[updated_vm.path_to_item]
         return path_to_schemas
 
@@ -2459,4 +2472,4 @@ LOG_CACHE_USAGE = False
 
 def log_cache_usage(cache_fn):
     if LOG_CACHE_USAGE:
-        print(cache_fn.__name__, cache_fn.cache_info())
+        print(cache_fn.__name__, cache_fn.cache_info())
\ No newline at end of file
diff --git a/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/schemas.py b/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/schemas.py
index 49f42952e20..966644f4d95 100644
--- a/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/schemas.py
+++ b/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/schemas.py
@@ -148,6 +148,19 @@ class ValidationMetadata(frozendict.frozendict):
         return self.get('validated_path_to_schemas')
 
 
+def add_deeper_validated_schemas(validation_metadata: ValidationMetadata, path_to_schemas: dict):
+    # this is called if validation_ran_earlier and current and deeper locations need to be added
+    current_path_to_item = validation_metadata.path_to_item
+    other_path_to_schemas = {}
+    for path_to_item, schemas in validation_metadata.validated_path_to_schemas.items():
+        if len(path_to_item) < len(current_path_to_item):
+            continue
+        path_begins_with_current_path = path_to_item[:len(current_path_to_item)] == current_path_to_item
+        if path_begins_with_current_path:
+            other_path_to_schemas[path_to_item] = schemas
+    update(path_to_schemas, other_path_to_schemas)
+
+
 class Singleton:
     """
     Enums and singletons are the same
@@ -392,9 +405,9 @@ class Schema:
             because value is of the correct type, and validation was run earlier when the instance was created
         """
         _path_to_schemas = {}
-        if validation_metadata.validated_path_to_schemas:
-            update(_path_to_schemas, validation_metadata.validated_path_to_schemas)
-        if not validation_metadata.validation_ran_earlier(cls):
+        if validation_metadata.validation_ran_earlier(cls):
+            add_deeper_validated_schemas(validation_metadata, _path_to_schemas)
+        else:
             other_path_to_schemas = cls._validate_oapg(arg, validation_metadata=validation_metadata)
             update(_path_to_schemas, other_path_to_schemas)
         # loop through it make a new class for each entry
@@ -1332,6 +1345,7 @@ class ListBase(ValidatorBase):
                 validated_path_to_schemas=validation_metadata.validated_path_to_schemas
             )
             if item_validation_metadata.validation_ran_earlier(item_cls):
+                add_deeper_validated_schemas(item_validation_metadata, path_to_schemas)
                 continue
             other_path_to_schemas = item_cls._validate_oapg(
                 value, validation_metadata=item_validation_metadata)
@@ -1595,6 +1609,7 @@ class DictBase(Discriminable, ValidatorBase):
                 validated_path_to_schemas=validation_metadata.validated_path_to_schemas
             )
             if arg_validation_metadata.validation_ran_earlier(schema):
+                add_deeper_validated_schemas(arg_validation_metadata, path_to_schemas)
                 continue
             other_path_to_schemas = schema._validate_oapg(value, validation_metadata=arg_validation_metadata)
             update(path_to_schemas, other_path_to_schemas)
@@ -1683,6 +1698,7 @@ class DictBase(Discriminable, ValidatorBase):
             validated_path_to_schemas=validation_metadata.validated_path_to_schemas
         )
         if updated_vm.validation_ran_earlier(discriminated_cls):
+            add_deeper_validated_schemas(updated_vm, _path_to_schemas)
             return _path_to_schemas
         other_path_to_schemas = discriminated_cls._validate_oapg(arg, validation_metadata=updated_vm)
         update(_path_to_schemas, other_path_to_schemas)
@@ -1781,18 +1797,11 @@ def cast_to_allowed_types(
     if isinstance(arg, Schema):
         # store the already run validations
         schema_classes = set()
-        source_schema_was_unset = len(arg.__class__.__bases__) == 2 and UnsetAnyTypeSchema in arg.__class__.__bases__
-        if not source_schema_was_unset:
-            """
-            Do not include UnsetAnyTypeSchema and its base class because
-            it did not exist in the original spec schema definition
-            It was added to ensure that all instances are of type Schema and the allowed base types
-            """
-            for cls in arg.__class__.__bases__:
-                if cls is Singleton:
-                    # Skip Singleton
-                    continue
-                schema_classes.add(cls)
+        for cls in arg.__class__.__bases__:
+            if cls is Singleton:
+                # Skip Singleton
+                continue
+            schema_classes.add(cls)
         validated_path_to_schemas[path_to_item] = schema_classes
 
     type_error = ApiTypeError(f"Invalid type. Required value type is str and passed type was {type(arg)} at {path_to_item}")
@@ -1845,6 +1854,7 @@ class ComposedBase(Discriminable):
         path_to_schemas = defaultdict(set)
         for allof_cls in cls.MetaOapg.all_of():
             if validation_metadata.validation_ran_earlier(allof_cls):
+                add_deeper_validated_schemas(validation_metadata, path_to_schemas)
                 continue
             other_path_to_schemas = allof_cls._validate_oapg(arg, validation_metadata=validation_metadata)
             update(path_to_schemas, other_path_to_schemas)
@@ -1865,6 +1875,7 @@ class ComposedBase(Discriminable):
                 continue
             if validation_metadata.validation_ran_earlier(oneof_cls):
                 oneof_classes.append(oneof_cls)
+                add_deeper_validated_schemas(validation_metadata, path_to_schemas)
                 continue
             try:
                 path_to_schemas = oneof_cls._validate_oapg(arg, validation_metadata=validation_metadata)
@@ -1898,6 +1909,7 @@ class ComposedBase(Discriminable):
         for anyof_cls in cls.MetaOapg.any_of():
             if validation_metadata.validation_ran_earlier(anyof_cls):
                 anyof_classes.append(anyof_cls)
+                add_deeper_validated_schemas(validation_metadata, path_to_schemas)
                 continue
 
             try:
@@ -2011,6 +2023,7 @@ class ComposedBase(Discriminable):
 
         if discriminated_cls is not None and not updated_vm.validation_ran_earlier(discriminated_cls):
             # TODO use an exception from this package here
+            add_deeper_validated_schemas(updated_vm, path_to_schemas)
             assert discriminated_cls in path_to_schemas[updated_vm.path_to_item]
         return path_to_schemas
 
@@ -2459,4 +2472,4 @@ LOG_CACHE_USAGE = False
 
 def log_cache_usage(cache_fn):
     if LOG_CACHE_USAGE:
-        print(cache_fn.__name__, cache_fn.cache_info())
+        print(cache_fn.__name__, cache_fn.cache_info())
\ No newline at end of file
diff --git a/samples/openapi3/client/petstore/python/petstore_api/schemas.py b/samples/openapi3/client/petstore/python/petstore_api/schemas.py
index e2c6c665dd8..b96bc1f1fda 100644
--- a/samples/openapi3/client/petstore/python/petstore_api/schemas.py
+++ b/samples/openapi3/client/petstore/python/petstore_api/schemas.py
@@ -148,6 +148,19 @@ class ValidationMetadata(frozendict.frozendict):
         return self.get('validated_path_to_schemas')
 
 
+def add_deeper_validated_schemas(validation_metadata: ValidationMetadata, path_to_schemas: dict):
+    # this is called if validation_ran_earlier and current and deeper locations need to be added
+    current_path_to_item = validation_metadata.path_to_item
+    other_path_to_schemas = {}
+    for path_to_item, schemas in validation_metadata.validated_path_to_schemas.items():
+        if len(path_to_item) < len(current_path_to_item):
+            continue
+        path_begins_with_current_path = path_to_item[:len(current_path_to_item)] == current_path_to_item
+        if path_begins_with_current_path:
+            other_path_to_schemas[path_to_item] = schemas
+    update(path_to_schemas, other_path_to_schemas)
+
+
 class Singleton:
     """
     Enums and singletons are the same
@@ -392,9 +405,9 @@ class Schema:
             because value is of the correct type, and validation was run earlier when the instance was created
         """
         _path_to_schemas = {}
-        if validation_metadata.validated_path_to_schemas:
-            update(_path_to_schemas, validation_metadata.validated_path_to_schemas)
-        if not validation_metadata.validation_ran_earlier(cls):
+        if validation_metadata.validation_ran_earlier(cls):
+            add_deeper_validated_schemas(validation_metadata, _path_to_schemas)
+        else:
             other_path_to_schemas = cls._validate_oapg(arg, validation_metadata=validation_metadata)
             update(_path_to_schemas, other_path_to_schemas)
         # loop through it make a new class for each entry
@@ -1332,6 +1345,7 @@ class ListBase(ValidatorBase):
                 validated_path_to_schemas=validation_metadata.validated_path_to_schemas
             )
             if item_validation_metadata.validation_ran_earlier(item_cls):
+                add_deeper_validated_schemas(item_validation_metadata, path_to_schemas)
                 continue
             other_path_to_schemas = item_cls._validate_oapg(
                 value, validation_metadata=item_validation_metadata)
@@ -1595,6 +1609,7 @@ class DictBase(Discriminable, ValidatorBase):
                 validated_path_to_schemas=validation_metadata.validated_path_to_schemas
             )
             if arg_validation_metadata.validation_ran_earlier(schema):
+                add_deeper_validated_schemas(arg_validation_metadata, path_to_schemas)
                 continue
             other_path_to_schemas = schema._validate_oapg(value, validation_metadata=arg_validation_metadata)
             update(path_to_schemas, other_path_to_schemas)
@@ -1683,6 +1698,7 @@ class DictBase(Discriminable, ValidatorBase):
             validated_path_to_schemas=validation_metadata.validated_path_to_schemas
         )
         if updated_vm.validation_ran_earlier(discriminated_cls):
+            add_deeper_validated_schemas(updated_vm, _path_to_schemas)
             return _path_to_schemas
         other_path_to_schemas = discriminated_cls._validate_oapg(arg, validation_metadata=updated_vm)
         update(_path_to_schemas, other_path_to_schemas)
@@ -1781,18 +1797,11 @@ def cast_to_allowed_types(
     if isinstance(arg, Schema):
         # store the already run validations
         schema_classes = set()
-        source_schema_was_unset = len(arg.__class__.__bases__) == 2 and UnsetAnyTypeSchema in arg.__class__.__bases__
-        if not source_schema_was_unset:
-            """
-            Do not include UnsetAnyTypeSchema and its base class because
-            it did not exist in the original spec schema definition
-            It was added to ensure that all instances are of type Schema and the allowed base types
-            """
-            for cls in arg.__class__.__bases__:
-                if cls is Singleton:
-                    # Skip Singleton
-                    continue
-                schema_classes.add(cls)
+        for cls in arg.__class__.__bases__:
+            if cls is Singleton:
+                # Skip Singleton
+                continue
+            schema_classes.add(cls)
         validated_path_to_schemas[path_to_item] = schema_classes
 
     type_error = ApiTypeError(f"Invalid type. Required value type is str and passed type was {type(arg)} at {path_to_item}")
@@ -1845,6 +1854,7 @@ class ComposedBase(Discriminable):
         path_to_schemas = defaultdict(set)
         for allof_cls in cls.MetaOapg.all_of():
             if validation_metadata.validation_ran_earlier(allof_cls):
+                add_deeper_validated_schemas(validation_metadata, path_to_schemas)
                 continue
             other_path_to_schemas = allof_cls._validate_oapg(arg, validation_metadata=validation_metadata)
             update(path_to_schemas, other_path_to_schemas)
@@ -1865,6 +1875,7 @@ class ComposedBase(Discriminable):
                 continue
             if validation_metadata.validation_ran_earlier(oneof_cls):
                 oneof_classes.append(oneof_cls)
+                add_deeper_validated_schemas(validation_metadata, path_to_schemas)
                 continue
             try:
                 path_to_schemas = oneof_cls._validate_oapg(arg, validation_metadata=validation_metadata)
@@ -1898,6 +1909,7 @@ class ComposedBase(Discriminable):
         for anyof_cls in cls.MetaOapg.any_of():
             if validation_metadata.validation_ran_earlier(anyof_cls):
                 anyof_classes.append(anyof_cls)
+                add_deeper_validated_schemas(validation_metadata, path_to_schemas)
                 continue
 
             try:
@@ -2011,6 +2023,7 @@ class ComposedBase(Discriminable):
 
         if discriminated_cls is not None and not updated_vm.validation_ran_earlier(discriminated_cls):
             # TODO use an exception from this package here
+            add_deeper_validated_schemas(updated_vm, path_to_schemas)
             assert discriminated_cls in path_to_schemas[updated_vm.path_to_item]
         return path_to_schemas
 
@@ -2459,4 +2472,4 @@ LOG_CACHE_USAGE = False
 
 def log_cache_usage(cache_fn):
     if LOG_CACHE_USAGE:
-        print(cache_fn.__name__, cache_fn.cache_info())
+        print(cache_fn.__name__, cache_fn.cache_info())
\ No newline at end of file
-- 
GitLab


From 2b0650383cff7b3837815b64054af3e480890c3c Mon Sep 17 00:00:00 2001
From: Justin Black <justin.a.black@gmail.com>
Date: Fri, 18 Nov 2022 14:41:24 -0800
Subject: [PATCH 4/4] Adds missing #

---
 .../openapi3/client/petstore/python/tests_manual/test_pet.py    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_pet.py b/samples/openapi3/client/petstore/python/tests_manual/test_pet.py
index e82f29ccaa3..be64bfa6e3c 100644
--- a/samples/openapi3/client/petstore/python/tests_manual/test_pet.py
+++ b/samples/openapi3/client/petstore/python/tests_manual/test_pet.py
@@ -1,4 +1,4 @@
- coding: utf-8
+# coding: utf-8
 
 """
     OpenAPI Petstore
-- 
GitLab