Skip to content

Commit

Permalink
allow services with no operations to generate (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
iscai-msft authored Nov 3, 2020
1 parent cd22943 commit d4a275f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions autorest/codegen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
45 changes: 28 additions & 17 deletions autorest/codegen/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -165,19 +173,22 @@ 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)

# write the empty py.typed file
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"]:
Expand Down

0 comments on commit d4a275f

Please sign in to comment.