Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add gapic metadata file #781

Merged
merged 21 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"schema": "1.0",
software-dov marked this conversation as resolved.
Show resolved Hide resolved
"comment": "This file maps proto services/RPCs to the corresponding library clients/methods",
"language": "python",
"protoPackage": "{{ api.naming.proto_package }}",
"libraryPackage": "{{ '.'.join(api.naming.module_namespace+(api.naming.versioned_module_name,)) }}",
"services": {
{% for service in api.services.values()|sort(attribute='name') -%}
"{{ service.name }}":{
{% if 'grpc' in opts.transport -%}
"grpc": {
"libraryClient": "{{ service.client_name }}",
"rpcs": {
{% for method in service.methods.values() -%}
"{{ method.name }}": ["{{ method.name|snake_case }}"]{{ "," if not loop.last else "" }}
{% endfor -%}{# method -#}
}
}{{ "," if 'rest' in opts.transport else "" -}}
{% endif -%}
{% if 'rest' in opts.transport -%}
"rest": {
"libraryClient": "{{ service.client_name }}",
"rpcs": {
{% for method in service.methods.values() -%}
"{{ method.name }}": ["{{ method.name|snake_case }}"]{{ "," if not loop.last else "" }}
{% endfor -%}{# method -#}
}
}
{% endif -%}{# opts.transport #}
}{{ "," if not loop.last else "" }}
{% endfor -%}{# service -#}
}
}
9 changes: 5 additions & 4 deletions gapic/cli/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ def generate(
# This generator uses a slightly different mechanism for determining
# which files to generate; it tracks at package level rather than file
# level.
package = os.path.commonprefix([i.package for i in filter(
lambda p: p.name in req.file_to_generate,
req.proto_file,
)]).rstrip('.')
package = os.path.commonprefix([
p.package
for p in req.proto_file
if p.name in req.file_to_generate
]).rstrip('.')

# Build the API model object.
# This object is a frozen representation of the whole API, and is sent
Expand Down
41 changes: 41 additions & 0 deletions gapic/templates/%namespace/%name_%version/gapic_metadata.json.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"schema": "1.0",
"comment": "This file maps proto services/RPCs to the corresponding library clients/methods",
"language": "python",
"protoPackage": "{{ api.naming.proto_package }}",
"libraryPackage": "{{ '.'.join(api.naming.module_namespace+(api.naming.versioned_module_name,)) }}",
"services": {
{% for service in api.services.values()|sort(attribute='name') -%}
"{{ service.name }}":{
{% if 'grpc' in opts.transport -%}
"grpc": {
"libraryClient": "{{ service.client_name }}",
"rpcs": {
{% for method in service.methods.values() -%}
"{{ method.name }}": ["{{ method.name|snake_case }}"]{{ "," if not loop.last else "" }}
{% endfor -%}{# method -#}
}
},
"grpcAsync": {
"libraryClient": "{{ service.async_client_name }}",
"rpcs": {
{% for method in service.methods.values() -%}
"{{ method.name }}": ["{{ method.name|snake_case }}"]{{ "," if not loop.last else "" }}
{% endfor -%}{# method -#}
}
}{{ "," if 'rest' in opts.transport else "" -}}
{% endif -%}
{% if 'rest' in opts.transport -%}
"rest": {
"libraryClient": "{{ service.client_name }}",
"rpcs": {
{% for method in service.methods.values() -%}
"{{ method.name }}": ["{{ method.name|snake_case }}"]{{ "," if not loop.last else "" }}
{% endfor -%}{# method -#}
}
}
{% endif -%}{# opts.transport #}
}{{ "," if not loop.last else "" }}
{% endfor -%}{# service -#}
}
}