@@ -117,13 +117,23 @@ def classname(s):
117117 return capwords (s )
118118
119119
120- def get_auth_types_set (namespace ):
120+ def get_auth_types_set (namespace , noauth_as_user = False ):
121+ if isinstance (namespace , NamespaceWrapper ):
122+ namespace = namespace .as_babel
123+
121124 routes = namespace .routes
122125 if not routes :
123126 return set ()
124127
128+ def auth_replace_noauth (route ):
129+ auth_type = route .attrs .get ('auth' , 'user' )
130+ if noauth_as_user and auth_type == 'noauth' :
131+ return 'user'
132+ else :
133+ return auth_type
134+
125135 return {
126- route . attrs . get ( 'auth' , 'user' )
136+ auth_replace_noauth ( route )
127137 for route in routes
128138 }
129139
@@ -743,9 +753,8 @@ def routes(self):
743753 for route in self .as_babel .routes
744754 )
745755
746- @property
747- def java_class (self ):
748- return self ._as_java_class (classname ('dbx_' + self .babel_name ))
756+ def java_class (self , auth ):
757+ return self ._as_java_class (classname ('dbx_' + auth + '_' + self .babel_name + '_requests' ))
749758
750759 @property
751760 def java_getter (self ):
@@ -766,7 +775,8 @@ def __init__(self, ctx, namespace, route):
766775
767776 @property
768777 def java_class (self ):
769- return self .namespace .java_class
778+ auth = self .auth_style if self .auth_style != 'noauth' else 'user'
779+ return self .namespace .java_class (auth )
770780
771781 @property
772782 def arg (self ):
@@ -1637,7 +1647,6 @@ def emit_attrs(tag, attrs):
16371647 out ('/**' )
16381648
16391649 if doc :
1640- doc = sanitize_javadoc (doc )
16411650 first_paragraph = True
16421651 for paragraph in split_paragraphs (doc .strip ()):
16431652 if not first_paragraph :
@@ -1706,7 +1715,7 @@ def javadoc_deprecated(self, deprecated):
17061715
17071716 if isinstance (deprecated , RouteWrapper ):
17081717 return 'use %s instead.' % self .javadoc_ref (deprecated )
1709- elif deprecated is True :
1718+ elif isinstance ( deprecated , bool ) and deprecated :
17101719 return ''
17111720 else :
17121721 return None
@@ -1964,7 +1973,7 @@ def generate_imports(self):
19641973 for import_ in sorted (imports ):
19651974 out ('import %s;' % import_ )
19661975
1967- def add_imports_for_namespace (self , namespace ):
1976+ def add_imports_for_namespace (self , namespace , auth ):
19681977 assert isinstance (namespace , NamespaceWrapper ), repr (namespace )
19691978
19701979 self ._ctx .add_imports (
@@ -1979,7 +1988,9 @@ def add_imports_for_namespace(self, namespace):
19791988 'java.util.Map' ,
19801989 )
19811990 for route in namespace .routes :
1982- self .add_imports_for_route (route )
1991+ route_auth = route .auth_style if route .auth_style != 'noauth' else 'user'
1992+ if route_auth == auth :
1993+ self .add_imports_for_route (route )
19831994
19841995 def add_imports_for_route (self , route ):
19851996 self ._add_imports_for_data_type (route .arg )
@@ -2000,8 +2011,9 @@ def add_imports_for_route(self, route):
20002011 self ._ctx .add_imports ('com.dropbox.core.v2.DbxDownloadStyleBuilder' )
20012012
20022013 def add_imports_for_route_builder (self , route ):
2014+ route_auth = route .auth_style if route .auth_style != 'noauth' else 'user'
20032015 self ._ctx .add_imports (
2004- route .namespace .java_class ,
2016+ route .namespace .java_class ( route_auth ) ,
20052017 route .arg .java_builder_class ,
20062018 'com.dropbox.core.DbxException' ,
20072019 )
@@ -2228,7 +2240,7 @@ def generate_dbx_clients(self):
22282240
22292241 user_client_class_name = 'DbxClientV2'
22302242 with self .dbx_client (
2231- self .ctx .base_package , user_client_class_name , ( 'user' , 'noauth' ) ,
2243+ self .ctx .base_package , user_client_class_name , 'user' ,
22322244
22332245 """
22342246 Use this class to make remote calls to the Dropbox API user endpoints. User endpoints
@@ -2240,7 +2252,7 @@ def generate_dbx_clients(self):
22402252 pass
22412253
22422254 with self .dbx_client (
2243- self .ctx .base_package , 'DbxTeamClientV2' , ( 'team' ,) ,
2255+ self .ctx .base_package , 'DbxTeamClientV2' , 'team' ,
22442256 """
22452257 Use this class to make remote calls to the Dropbox API team endpoints. Team endpoints
22462258 expose actions you can perform on or for a Dropbox team. You'll need a team access
@@ -2288,14 +2300,19 @@ def generate_dbx_clients(self):
22882300
22892301
22902302 @contextmanager
2291- def dbx_client (self , package_name , class_name , auth_types , class_doc ):
2303+ def dbx_client (self , package_name , class_name , auth , class_doc ):
22922304 assert class_doc
22932305
22942306 out = self .g .emit
22952307
2308+ if auth == 'user' :
2309+ auth_types_filter = (auth , 'noauth' )
2310+ else :
2311+ auth_types_filter = (auth ,)
2312+
22962313 namespaces = [
22972314 NamespaceWrapper (self .ctx , ns )
2298- for ns in get_namespaces_by_auth_types (self .ctx .api , auth_types )
2315+ for ns in get_namespaces_by_auth_types (self .ctx .api , auth_types_filter )
22992316 ]
23002317
23012318 package_relpath = self .create_package_path (package_name )
@@ -2309,7 +2326,7 @@ def dbx_client(self, package_name, class_name, auth_types, class_doc):
23092326 out ('import com.dropbox.core.http.HttpRequestor;' )
23102327
23112328 for namespace in namespaces :
2312- out ('import %s;' % namespace .java_class )
2329+ out ('import %s;' % namespace .java_class ( auth ) )
23132330
23142331 out ('' )
23152332 self .doc .generate_javadoc (
@@ -2323,7 +2340,7 @@ def dbx_client(self, package_name, class_name, auth_types, class_doc):
23232340 with self .g .block ('public final class %s' % class_name ):
23242341 out ('private final DbxRawClientV2 _client;' )
23252342 for namespace in namespaces :
2326- out ('private final %s %s;' % (namespace .java_class , namespace .java_field ))
2343+ out ('private final %s %s;' % (namespace .java_class ( auth ) , namespace .java_field ))
23272344 out ('' )
23282345
23292346 param_docs = OrderedDict ((
@@ -2373,7 +2390,7 @@ def dbx_client(self, package_name, class_name, auth_types, class_doc):
23732390 out ('this._client = _client;' )
23742391 for namespace in namespaces :
23752392 out ('this.%s = new %s(_client);' % (
2376- namespace .java_field , namespace .java_class
2393+ namespace .java_field , namespace .java_class ( auth )
23772394 ))
23782395
23792396 for namespace in namespaces :
@@ -2384,7 +2401,7 @@ def dbx_client(self, package_name, class_name, auth_types, class_doc):
23842401 """ % namespace .babel_name ,
23852402 returns = "Dropbox %s client" % namespace .babel_name
23862403 )
2387- with self .g .block ("public %s %s()" % (namespace .java_class , namespace .java_getter )):
2404+ with self .g .block ("public %s %s()" % (namespace .java_class ( auth ) , namespace .java_getter )):
23882405 out ('return %s;' % namespace .java_field )
23892406
23902407 out ('' )
@@ -2393,9 +2410,6 @@ def dbx_client(self, package_name, class_name, auth_types, class_doc):
23932410
23942411
23952412 def generate_namespace (self , namespace ):
2396- out = self .g .emit
2397- javadoc = self .doc .generate_javadoc
2398-
23992413 # create class files for all namespace data types in this package
24002414 for data_type in namespace .data_types :
24012415 self .generate_data_type (data_type )
@@ -2413,22 +2427,33 @@ def generate_namespace(self, namespace):
24132427 # add documentation to our packages
24142428 self .generate_package_javadoc (namespace )
24152429
2416- with self .new_file (namespace ):
2417- self .importer .add_imports_for_namespace (namespace )
2430+ for auth in get_auth_types_set (namespace , noauth_as_user = True ):
2431+ self .generate_namespace_for_auth (namespace , auth )
2432+
2433+ def generate_namespace_for_auth (self , namespace , auth ):
2434+ out = self .g .emit
2435+ javadoc = self .doc .generate_javadoc
2436+
2437+ with self .new_file (namespace , class_name = namespace .java_class (auth ).fq ):
2438+ self .importer .add_imports_for_namespace (namespace , auth )
24182439 self .importer .generate_imports ()
24192440
24202441 out ('' )
2421- javadoc ('Routes in namespace "%s".' % namespace .babel_name )
2422- with self .g .block ('public final class %s' % namespace .java_class ):
2442+ javadoc ('Routes in namespace "%s" that support %s auth .' % ( namespace .babel_name , auth ) )
2443+ with self .g .block ('public final class %s' % namespace .java_class ( auth ) ):
24232444 out ('// namespace %s' % namespace .babel_name )
24242445 out ('' )
24252446 out ('private final DbxRawClientV2 client;' )
24262447
24272448 out ('' )
2428- with self .g .block ('public %s(DbxRawClientV2 client)' % namespace .java_class ):
2449+ with self .g .block ('public %s(DbxRawClientV2 client)' % namespace .java_class ( auth ) ):
24292450 out ('this.client = client;' )
24302451
24312452 for route in namespace .routes :
2453+ route_auth = route .auth_style if route .auth_style != 'noauth' else 'user'
2454+ if route_auth != auth :
2455+ continue
2456+
24322457 out ('' )
24332458 out ('//' )
24342459 out ('// route %s/%s' % (route .namespace .babel_name , route .babel_name ))
@@ -2442,12 +2467,16 @@ def generate_namespace(self, namespace):
24422467 self .generate_route_builder (route )
24432468
24442469 def generate_package_javadoc (self , namespace ):
2470+ classes = oxford_comma_list (tuple (
2471+ "{@link %s}" % namespace .java_class (auth )
2472+ for auth in get_auth_types_set (namespace , noauth_as_user = True )
2473+ ), conjunction = 'and' )
24452474 package_doc = (
24462475 """
24472476 %s
24482477
2449- See {@link %s} for a list of possible requests for this namespace.
2450- """ % (namespace .babel_doc , namespace . java_class )
2478+ See %s for a list of possible requests for this namespace.
2479+ """ % (namespace .babel_doc , classes )
24512480 )
24522481
24532482 with self .new_file (namespace , 'package-info' , package_doc = package_doc ):
@@ -3597,6 +3626,7 @@ def generate_builder_type(self, route):
35973626 builder_arg_class = arg_type .java_builder_class
35983627 builder_arg_name = arg_type .java_builder_field
35993628 client_name = route .namespace .java_field
3629+ route_auth = route .auth_style if route .auth_style != 'noauth' else 'user'
36003630
36013631 out ('' )
36023632 javadoc (
@@ -3607,15 +3637,15 @@ def generate_builder_type(self, route):
36073637 """ % self .doc .javadoc_ref (route , builder = True )
36083638 )
36093639 with self .g .block ('public class %s' % route .java_builder_class_with_inheritance ):
3610- out ('private final %s %s;' % (route .namespace .java_class , client_name ))
3640+ out ('private final %s %s;' % (route .namespace .java_class ( route_auth ) , client_name ))
36113641 out ('private final %s %s;' % (builder_arg_class , builder_arg_name ))
36123642
36133643 #
36143644 # CONSTRUCTOR
36153645 #
36163646
36173647 args = ', ' .join ('%s %s' % pair for pair in (
3618- (route .namespace .java_class , client_name ),
3648+ (route .namespace .java_class ( route_auth ) , client_name ),
36193649 (builder_arg_class , builder_arg_name ),
36203650 ))
36213651
0 commit comments