diff --git a/ChangeLog.md b/ChangeLog.md index 7e42e43ca6a..a5eb8958998 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -8,6 +8,7 @@ Modelerfour version: 4.15.421 **Bug Fixes** - Honor default value for properties if `x-ms-client-default` value is passed #798 +- Can now generate services with no operations #801 ### 2020-10-19 - 5.4.0 Autorest core version: 3.0.6318 diff --git a/autorest/codegen/__init__.py b/autorest/codegen/__init__.py index e7e6a6da03c..7b42b872376 100644 --- a/autorest/codegen/__init__.py +++ b/autorest/codegen/__init__.py @@ -80,17 +80,19 @@ def _create_code_model(self, yaml_data: Dict[str, Any], options: Dict[str, Union # We don't want to support multi-api customurl YET (will see if that goes well....) # So far now, let's get the first one in the first operation # UGLY as hell..... - first_req_of_first_op_of_first_grp = yaml_data["operationGroups"][0]["operations"][0]["requests"][0] - code_model.custom_base_url = first_req_of_first_op_of_first_grp["protocol"]["http"]["uri"] + if yaml_data.get("operationGroups"): + first_req_of_first_op_of_first_grp = yaml_data["operationGroups"][0]["operations"][0]["requests"][0] + code_model.custom_base_url = first_req_of_first_op_of_first_grp["protocol"]["http"]["uri"] else: dollar_host_parameter = dollar_host[0] code_model.global_parameters.remove(dollar_host_parameter) code_model.base_url = dollar_host_parameter.yaml_data["clientDefaultValue"] # Create operations - code_model.operation_groups = [ - OperationGroup.from_yaml(code_model, op_group) for op_group in yaml_data["operationGroups"] - ] + if yaml_data.get("operationGroups"): + code_model.operation_groups = [ + OperationGroup.from_yaml(code_model, op_group) for op_group in yaml_data["operationGroups"] + ] # Get my namespace namespace = self._autorestapi.get_value("namespace") diff --git a/autorest/codegen/serializers/__init__.py b/autorest/codegen/serializers/__init__.py index 5b295b79874..9b36715a32b 100644 --- a/autorest/codegen/serializers/__init__.py +++ b/autorest/codegen/serializers/__init__.py @@ -52,19 +52,20 @@ def serialize(self, code_model: CodeModel) -> None: if code_model.schemas or code_model.enums: self._serialize_and_write_models_folder(code_model=code_model, env=env, namespace_path=namespace_path) - self._serialize_and_write_operations_folder(code_model=code_model, env=env, namespace_path=namespace_path) - self._serialize_and_write_top_level_folder(code_model=code_model, env=env, namespace_path=namespace_path) - if not code_model.options["no_async"]: - self._serialize_and_write_aio_folder( - code_model=code_model, env=env, namespace_path=namespace_path, - ) + if code_model.operation_groups: + self._serialize_and_write_operations_folder(code_model=code_model, env=env, namespace_path=namespace_path) - if code_model.options["multiapi"]: - self._serialize_and_write_metadata( - code_model, env=env, namespace_path=namespace_path - ) + if not code_model.options["no_async"]: + self._serialize_and_write_aio_folder( + code_model=code_model, env=env, namespace_path=namespace_path, + ) + + if code_model.options["multiapi"]: + self._serialize_and_write_metadata( + code_model, env=env, namespace_path=namespace_path + ) def _serialize_and_write_models_folder(self, code_model: CodeModel, env: Environment, namespace_path: Path) -> None: # Write the models folder @@ -155,7 +156,14 @@ def _serialize_and_write_top_level_folder( ) -> None: general_serializer = GeneralSerializer(code_model=code_model, env=env, async_mode=False) - self._autorestapi.write_file(namespace_path / Path("__init__.py"), general_serializer.serialize_init_file()) + if code_model.operation_groups: + self._autorestapi.write_file( + namespace_path / Path("__init__.py"), general_serializer.serialize_init_file() + ) + else: + self._autorestapi.write_file( + namespace_path / Path("__init__.py"), general_serializer.serialize_pkgutil_init_file() + ) p = namespace_path.parent while p != Path("."): # write pkgutil init file @@ -165,9 +173,11 @@ def _serialize_and_write_top_level_folder( p = p.parent # Write the service client - self._autorestapi.write_file( - namespace_path / Path(f"_{code_model.module_name}.py"), general_serializer.serialize_service_client_file() - ) + if code_model.operation_groups: + self._autorestapi.write_file( + namespace_path / Path(f"_{code_model.module_name}.py"), + general_serializer.serialize_service_client_file() + ) self._serialize_and_write_version_file(code_model, namespace_path, general_serializer) @@ -175,9 +185,10 @@ def _serialize_and_write_top_level_folder( self._autorestapi.write_file(namespace_path / Path("py.typed"), "# Marker file for PEP 561.") # Write the config file - self._autorestapi.write_file( - namespace_path / Path("_configuration.py"), general_serializer.serialize_config_file() - ) + if code_model.operation_groups: + self._autorestapi.write_file( + namespace_path / Path("_configuration.py"), general_serializer.serialize_config_file() + ) # Write the setup file if code_model.options["basic_setup_py"]: