Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 45e98c8

Browse files
committed
feat: Add support for reading ClientLibrarySettings from service configuration YAML
1 parent f773c8a commit 45e98c8

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

gapic/schema/api.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,26 @@ def enforce_valid_method_settings(
670670
if all_errors:
671671
raise MethodSettingsError(yaml.dump(all_errors))
672672

673+
@cached_property
674+
def all_library_settings(
675+
self,
676+
) -> Mapping[str, Sequence[client_pb2.ClientLibrarySettings]]:
677+
"""Return a map of all `google.api.client.ClientLibrarySettings` to be used
678+
when generating client libraries.
679+
https://github.com/googleapis/googleapis/blob/master/google/api/client.proto#L130
680+
681+
Return:
682+
Mapping[str, Sequence[client_pb2.ClientLibrarySettings]]: A mapping of all library
683+
settings read from the service YAML.
684+
"""
685+
return {
686+
library_setting.version: client_pb2.ClientLibrarySettings(
687+
version=library_setting.version,
688+
python_settings=library_setting.python_settings,
689+
)
690+
for library_setting in self.service_yaml_config.publishing.library_settings
691+
}
692+
673693
@cached_property
674694
def all_method_settings(self) -> Mapping[str, Sequence[client_pb2.MethodSettings]]:
675695
"""Return a map of all `google.api.client.MethodSettings` to be used

tests/unit/schema/test_api.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,6 +2695,33 @@ def test_api_all_methods():
26952695
]
26962696

26972697

2698+
def test_read_python_settings_from_service_yaml():
2699+
service_yaml_config = {
2700+
"apis": [
2701+
{"name": "google.example.v1beta1.ServiceOne.Example1"},
2702+
],
2703+
"publishing": {
2704+
"library_settings": [
2705+
{
2706+
"version": "google.example.v1beta1",
2707+
"python_settings": {
2708+
"optional_features": ["rest_aio"],
2709+
},
2710+
}
2711+
]
2712+
},
2713+
}
2714+
cli_options = Options(service_yaml_config=service_yaml_config)
2715+
fd = get_file_descriptor_proto_for_method_settings_tests(fields=[])
2716+
api_schema = api.API.build(fd, "google.example.v1beta1", opts=cli_options)
2717+
assert api_schema.all_library_settings == {
2718+
"google.example.v1beta1": client_pb2.ClientLibrarySettings(
2719+
version="google.example.v1beta1",
2720+
python_settings=client_pb2.PythonSettings(optional_features=["rest_aio"]),
2721+
)
2722+
}
2723+
2724+
26982725
def test_read_method_settings_from_service_yaml():
26992726
"""
27002727
Tests the `gapic.schema.api.all_method_settings` method which reads

0 commit comments

Comments
 (0)