From 21bccb8cebe7aa0cf59d70a112ac36570d8c8131 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 10 Mar 2020 17:30:31 -0400 Subject: [PATCH] making criterion to initialize models same as importing models in operation groups --- autorest/codegen/serializers/operation_group_serializer.py | 6 ++++++ autorest/codegen/templates/operations_container.py.jinja2 | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/autorest/codegen/serializers/operation_group_serializer.py b/autorest/codegen/serializers/operation_group_serializer.py index bb8422de242..2c8b94a5b1b 100644 --- a/autorest/codegen/serializers/operation_group_serializer.py +++ b/autorest/codegen/serializers/operation_group_serializer.py @@ -36,4 +36,10 @@ def _is_paging(operation): async_mode=self.async_mode, is_lro=_is_lro, is_paging=_is_paging, + import_models=any( + [ + operation for operation in self.operation_group.operations + if operation.parameters.has_body or operation.has_response_body or operation.exceptions + ] + ) ) diff --git a/autorest/codegen/templates/operations_container.py.jinja2 b/autorest/codegen/templates/operations_container.py.jinja2 index eed3819e264..3d01c0718aa 100644 --- a/autorest/codegen/templates/operations_container.py.jinja2 +++ b/autorest/codegen/templates/operations_container.py.jinja2 @@ -14,7 +14,7 @@ class {{ operation_group.class_name }}{{ object_base_class }}: You should not instantiate this class directly. Instead, you should create a Client instance that instantiates it for you and attaches it as an attribute. -{% if code_model.schemas %} +{% if import_models %} :ivar models: Alias to model classes used in this operation group. :type models: ~{{ code_model.namespace }}.models {% endif %} @@ -24,7 +24,7 @@ class {{ operation_group.class_name }}{{ object_base_class }}: :param deserializer: An object model deserializer. """ -{% if code_model.schemas %} +{% if import_models %} models = models {% endif %}