Skip to content

Commit

Permalink
Add support for specifying version identifier in generated files.
Browse files Browse the repository at this point in the history
  • Loading branch information
cglouch committed Sep 16, 2024
1 parent 484c671 commit 2c88ab5
Show file tree
Hide file tree
Showing 4 changed files with 754 additions and 3 deletions.
8 changes: 7 additions & 1 deletion apitools/gen/gen_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _GetCodegenFromFlags(args):

client_info = util.ClientInfo.Create(
discovery_doc, args.scope, client_id, client_secret,
args.user_agent, names, args.api_key)
args.user_agent, names, args.api_key, args.version_identifier)
outdir = os.path.expanduser(args.outdir) or client_info.default_directory
if os.path.exists(outdir) and not args.overwrite:
raise exceptions.ConfigurationValueError(
Expand Down Expand Up @@ -225,6 +225,12 @@ def main(argv=None):
help=('Base package path of protorpc '
'(defaults to apitools.base.protorpclite'))

parser.add_argument(
'--version-identifier',
help=('Version identifier to use for the generated client (defaults to '
'"version" value in discovery doc). This must be a valid '
'identifier when used in a Python module name.'))

parser.add_argument(
'--outdir',
default='',
Expand Down
26 changes: 26 additions & 0 deletions apitools/gen/gen_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,32 @@ def testGenClient_SimpleDocWithV5(self):
set(['dns_v1_client.py', 'dns_v1_messages.py', '__init__.py']),
set(os.listdir(tmp_dir_path)))

def testGenClient_ApiVersioning(self):
with test_utils.TempDir() as tmp_dir_path:
gen_client.main([
gen_client.__file__,
'--infile', GetTestDataPath(
'dns', 'dns_2015-08-07-preview.json'),
'--outdir', tmp_dir_path,
'--overwrite',
'--version-identifier', 'v2015_08_07_preview',
'--root_package', 'google.apis',
'client'
])
self.assertEquals(
set([
'dns_v2015_08_07_preview_client.py',
'dns_v2015_08_07_preview_messages.py',
'__init__.py']),
set(os.listdir(tmp_dir_path)))
client_file = _GetContent(
os.path.join(tmp_dir_path, 'dns_v2015_08_07_preview_client.py'))
# Check that "apiVersion" system parameter values from discovery doc
# appear in generated client.
self.assertIn('2015-01-01-preview', client_file)
self.assertIn('2015-02-02-preview', client_file)
self.assertIn('2015-03-03-preview', client_file)

def testGenPipPackage_SimpleDoc(self):
with test_utils.TempDir() as tmp_dir_path:
gen_client.main([
Expand Down
Loading

0 comments on commit 2c88ab5

Please sign in to comment.