Skip to content

Commit 5751983

Browse files
andrewhaighjiuyangzhao
authored andcommitted
Add prefix to distinguish multiple auth variants of builders (#265)
* Use prefix in builder and fix tests * CR
1 parent 5f8487d commit 5751983

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

generator/java.stoneg.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,6 @@ def add_imports_for_route_builder(self, route):
768768
self._add_imports_for_data_type_exception(route.error_data_type)
769769

770770
namespace = j.route_namespace(route)
771-
route_auth = j.auth_style(route) if j.auth_style(route) != 'noauth' else 'user'
772771
self.add_imports(
773772
j.java_class(namespace),
774773
'com.dropbox.core.DbxException',
@@ -2011,8 +2010,15 @@ def builder_class(self, stone_elem):
20112010

20122011
if isinstance(stone_elem, ApiRoute):
20132012
route = stone_elem
2013+
2014+
if ',' in self.auth_style(route):
2015+
# Use prefix here because multiple builders may be generated
2016+
# if the endpoint has multiple auth types
2017+
prefix = (self._args.requests_classname_prefix or self._args.client_class) + "_"
2018+
else:
2019+
prefix = ""
20142020
package = self.java_class(route).package
2015-
return JavaClass(package + '.' + classname(format_func_name(route) + '_builder'))
2021+
return JavaClass(package + '.' + classname('%s%s_builder' % (prefix, format_func_name(route))))
20162022
else:
20172023
data_type = stone_elem
20182024
assert is_user_defined_type(data_type), repr(data_type)

src/test/java/com/dropbox/core/stone/test/RouteVersionTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,19 @@ public void testUploadRoutes() throws Exception {
2929
Method v1 = c.getDeclaredMethod("testUpload", UninitializedReason.class, String.class);
3030
Method v2NoBuilder = c.getDeclaredMethod("testUploadV2", String.class, String.class);
3131
Method v2Builder = c.getDeclaredMethod("testUploadV2Builder", String.class, String.class);
32+
Method v3Builder = c.getDeclaredMethod("testUploadV3Builder", String.class, String.class);
3233

3334
// Test return value
3435
assertEquals(v1.getReturnType(), TestUploadUploader.class);
3536
assertEquals(v2NoBuilder.getReturnType(), TestUploadV2Uploader.class);
3637
assertEquals(v2Builder.getReturnType(), TestUploadV2Builder.class);
38+
assertEquals(v3Builder.getReturnType(), DbxTestTestUploadV3Builder.class);
3739

3840
// Test builder
3941
TestUploadV2Builder.class.getDeclaredMethod("withBorn", Date.class);
4042
TestUploadV2Builder.class.getDeclaredMethod("withSize", DogSize.class);
41-
Method start = TestUploadV2Builder.class.getDeclaredMethod("start");
42-
assertTrue(Arrays.asList(start.getExceptionTypes()).contains(ParentUnionException.class));
43+
Method start2 = TestUploadV2Builder.class.getDeclaredMethod("start");
44+
assertTrue(Arrays.asList(start2.getExceptionTypes()).contains(ParentUnionException.class));
4345

4446
// Test return value of uploader from generic type
4547
ParameterizedType genericV1 = (ParameterizedType)TestUploadUploader.class.getGenericSuperclass();
@@ -50,6 +52,12 @@ public void testUploadRoutes() throws Exception {
5052
// Test exception from generic type
5153
assertEquals(genericV1.getActualTypeArguments()[1], Void.class);
5254
assertEquals(genericV2.getActualTypeArguments()[1], ParentUnion.class);
55+
56+
// Test builder with multiple auth types has prefix
57+
DbxTestTestUploadV3Builder.class.getDeclaredMethod("withBorn", Date.class);
58+
DbxTestTestUploadV3Builder.class.getDeclaredMethod("withSize", DogSize.class);
59+
Method start3 = DbxTestTestUploadV3Builder.class.getDeclaredMethod("start");
60+
assertTrue(Arrays.asList(start3.getExceptionTypes()).contains(ParentUnionException.class));
5361
}
5462

5563
@Test

src/test/stone/stone_cfg.stone

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ struct Route
77
style String = "rpc"
88
"The RPC format to use for the request. Valid values: rpc, download,
99
and upload."
10+
auth String = "auth"
11+
"Auth mode for the route."

src/test/stone/test.stone

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ route test_upload:2 (Dog, Void, ParentUnion)
8686
attrs
8787
style = "upload"
8888

89+
route test_upload:3 (Dog, Void, ParentUnion)
90+
attrs
91+
style = "upload"
92+
auth = "app, user"
93+
8994
route test_download(Dog, Fish, Void)
9095
attrs
9196
host = "content"

0 commit comments

Comments
 (0)