@@ -387,7 +387,8 @@ def schema_markers(s, c):
387387 else :
388388 # it should have at least one activity that matches it's type to qualify for the Resource trait
389389 for fqan , iot in activities .iteritems ():
390- if activity_name_to_type_name (activity_split (fqan )[1 ]).lower () == sid .lower ():
390+ _ , resource , _ = activity_split (fqan )
391+ if resource and activity_name_to_type_name (resource ).lower () == sid .lower ():
391392 res .add ('cmn::%s' % RESOURCE_MARKER_TRAIT )
392393 if IO_RESPONSE in iot :
393394 res .add (RESPONSE_MARKER_TRAIT )
@@ -408,10 +409,16 @@ def schema_markers(s, c):
408409# -------------------------
409410## @name Activity Utilities
410411# @{
411- # return (category, name, method)
412+ # return (category, name|None , method)
412413def activity_split (fqan ):
413414 t = fqan .split ('.' )
414- return t [0 ], t [1 ], '.' .join (t [2 :])
415+ mt = t [2 :]
416+ if not mt :
417+ # make this the method, with not resource
418+ mt = [t [1 ]]
419+ t [1 ] = None
420+ # end
421+ return t [0 ], t [1 ], '.' .join (mt )
415422
416423# Shorthand to get a type from parameters of activities
417424def activity_rust_type (schemas , p , allow_optionals = True ):
@@ -569,7 +576,7 @@ def build_all_params(c, m):
569576Context = collections .namedtuple ('Context' , ['sta_map' , 'fqan_map' , 'rta_map' , 'rtc_map' , 'schemas' ])
570577
571578# return a newly build context from the given data
572- def new_context (schemas , resources ):
579+ def new_context (schemas , resources , methods ):
573580 # Returns (A, B) where
574581 # A: { SchemaTypeName -> { fqan -> ['request'|'response', ...]}
575582 # B: { fqan -> activity_method_data }
@@ -579,14 +586,18 @@ def build_activity_mappings(activities, res = None, fqan = None):
579586 res = dict ()
580587 if fqan is None :
581588 fqan = dict ()
582- for an , a in activities .iteritems ():
589+ for a in activities .values ():
583590 if 'resources' in a :
584591 build_activity_mappings (a .resources , res , fqan )
585592 if 'methods' not in a :
586593 continue
587594 for mn , m in a .methods .iteritems ():
588595 assert m .id not in fqan
589596 fqan [m .id ] = m
597+ category , resource , method = activity_split (m .id )
598+ # Put the same method under different names to make access easier
599+ if resource is None :
600+ fqan [to_fqan (category , category , method )] = m
590601 for in_out_type_name in IO_TYPES :
591602 t = m .get (in_out_type_name , None )
592603 if t is None :
@@ -601,12 +612,12 @@ def build_activity_mappings(activities, res = None, fqan = None):
601612 # delete: has no response or request
602613 # getrating: response is a 'SomethingResult', which is still related to activities name
603614 # the latter is used to deduce the resource name
604- _ , an , _ = activity_split ( m . id )
605- tn = activity_name_to_type_name (an )
606- info = res .setdefault (tn , dict ())
607- if m .id not in info :
608- info .setdefault (m .id , [])
609- # end handle other cases
615+ if resource :
616+ tn = activity_name_to_type_name (resource )
617+ info = res .setdefault (tn , dict ())
618+ if m .id not in info :
619+ info .setdefault (m .id , [])
620+ # end handle other cases
610621 # end for each method
611622 # end for each activity
612623 return res , fqan
@@ -676,17 +687,31 @@ def recurse_properties(prefix, rs, s, parent_ids):
676687 # end utility
677688
678689 all_schemas = schemas and build_schema_map () or dict ()
679- if not resources :
690+ if not ( resources or methods ) :
680691 return Context (dict (), dict (), dict (), dict (), all_schemas )
681692
682- sta_map , fqan_map = build_activity_mappings (resources )
683- rta_map = dict ()
684- rtc_map = dict ()
685- for an in fqan_map :
686- category , resource , activity = activity_split (an )
687- rta_map .setdefault (resource , list ()).append (activity )
688- assert rtc_map .setdefault (resource , category ) == category
689- # DEBUG
693+ rta_map , rtc_map , sta_map , fqan_map = dict (), dict (), dict (), dict ()
694+
695+ sources = list ()
696+ if bool (resources ):
697+ sources .append (resources )
698+ if bool (methods ):
699+ sources .append ({None : type (methods )({'methods' : methods })})
700+
701+ for data_source in sources :
702+ _sta_map , _fqan_map = build_activity_mappings (data_source )
703+ for an in _fqan_map :
704+ category , resource , activity = activity_split (an )
705+ resource = resource or category
706+ rta_map .setdefault (resource , list ()).append (activity )
707+ assert rtc_map .setdefault (resource , category ) == category
708+ # end for each fqan
709+ # TODO: DEBUG: Remove this when it was run on all APIs
710+ assert len (set (sta_map .keys ()) & set (_sta_map .keys ())) == 0
711+ assert len (set (fqan_map .keys ()) & set (_fqan_map .keys ())) == 0 , set (fqan_map .keys ()) & set (_fqan_map .keys ())
712+ sta_map .update (_sta_map )
713+ fqan_map .update (_fqan_map )
714+ # end for each data source
690715 return Context (sta_map , fqan_map , rta_map , rtc_map , all_schemas )
691716
692717# Expects v to be 'v\d+', throws otherwise
0 commit comments