From 583aa24152fbb093a0590d317f234c0482ec7af5 Mon Sep 17 00:00:00 2001 From: Sebastien Rosset Date: Sun, 24 May 2020 17:21:00 -0700 Subject: [PATCH] [Python-experimental] Fix type error if oneof/anyof child schema is null type (#6387) * Mustache template should use invokerPackage tag to generate import * Fix runtime exception when composed schema has 'null' type * Fix runtime exception when composed schema has 'null' type --- .../resources/python/python-experimental/model_utils.mustache | 2 +- .../petstore/python-experimental/petstore_api/model_utils.py | 2 +- .../petstore/python-experimental/petstore_api/model_utils.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache index a0d2dd2e5b3..c9a527ab6fe 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache @@ -779,7 +779,7 @@ def get_discriminator_class(model_class, model_class._composed_schemas.get('allOf', ()) for cls in composed_children: # Check if the schema has inherited discriminators. - if cls.discriminator is not None: + if hasattr(cls, 'discriminator') and cls.discriminator is not None: used_model_class = get_discriminator_class( cls, discr_name, discr_value, cls_visited) if used_model_class is not None: diff --git a/samples/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/client/petstore/python-experimental/petstore_api/model_utils.py index fdf1feccf19..91225e19fcb 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/client/petstore/python-experimental/petstore_api/model_utils.py @@ -1046,7 +1046,7 @@ def get_discriminator_class(model_class, model_class._composed_schemas.get('allOf', ()) for cls in composed_children: # Check if the schema has inherited discriminators. - if cls.discriminator is not None: + if hasattr(cls, 'discriminator') and cls.discriminator is not None: used_model_class = get_discriminator_class( cls, discr_name, discr_value, cls_visited) if used_model_class is not None: diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py index fdf1feccf19..91225e19fcb 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py @@ -1046,7 +1046,7 @@ def get_discriminator_class(model_class, model_class._composed_schemas.get('allOf', ()) for cls in composed_children: # Check if the schema has inherited discriminators. - if cls.discriminator is not None: + if hasattr(cls, 'discriminator') and cls.discriminator is not None: used_model_class = get_discriminator_class( cls, discr_name, discr_value, cls_visited) if used_model_class is not None: