Skip to content

Commit

Permalink
feat: Add the apiVersion protected property to the generated resource…
Browse files Browse the repository at this point in the history
…s when applicable
  • Loading branch information
Hectorhammett committed Apr 22, 2024
1 parent a975dae commit 0fd4c10
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions generator/src/googleapis/codegen/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,13 @@ def __init__(self, api, name, def_dict, parent=None):
method_dict = self.values.get('methods') or {}
for name in sorted(method_dict):
method = Method(api, name, method_dict[name], parent=self)

# Support for the new API versioning on the discovery document
# the design states that all the methods should have the same version
# hence why we take it the first time and set it once
if not self.get('apiVersion') and 'apiVersion' in method_dict[name]:
self.SetTemplateValue('apiVersion', method_dict[name]['apiVersion'])

requestType = method.values.get('requestType')
if requestType and requestType.GetTemplateValue('className') and \
requestType.GetTemplateValue('className') not in self._method_classes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ namespace {{ api.ownerName }}\Service\{{ api.className }}\Resource;
* </code>
*/
class {{ resource.className }} extends \Google\Service\Resource
{{% indent %}{% for method in resource.methods %}
{{% indent %}{% if resource.apiVersion %}
protected $apiVersion = '{{ resource.apiVersion }}';
{% endif %}{% for method in resource.methods %}
{% call_template _method method=method %}{% endfor %}
{% endindent %}}

Expand Down

0 comments on commit 0fd4c10

Please sign in to comment.