@@ -263,12 +263,18 @@ def mangle_ident(n):
263263def _is_map_prop (p ):
264264 return 'additionalProperties' in p
265265
266+ def _assure_unique_type_name (schemas , tn ):
267+ if tn in schemas :
268+ tn += 'Internal'
269+ assert tn not in schemas
270+ return tn
271+
266272# map a json type to an rust type
267273# sn = schema name
268274# pn = property name
269275# t = type dict
270276# NOTE: In case you don't understand how this algorithm really works ... me neither - THE AUTHOR
271- def to_rust_type (sn , pn , t , allow_optionals = True ):
277+ def to_rust_type (schemas , sn , pn , t , allow_optionals = True ):
272278 def nested_type (nt ):
273279 if 'items' in nt :
274280 nt = nt .items
@@ -277,8 +283,8 @@ def nested_type(nt):
277283 else :
278284 assert (is_nested_type_property (nt ))
279285 # It's a nested type - we take it literally like $ref, but generate a name for the type ourselves
280- return nested_type_name (sn , pn )
281- return to_rust_type (sn , pn , nt , allow_optionals = False )
286+ return _assure_unique_type_name ( schemas , nested_type_name (sn , pn ) )
287+ return to_rust_type (schemas , sn , pn , nt , allow_optionals = False )
282288
283289 def wrap_type (tn ):
284290 if allow_optionals :
@@ -323,10 +329,10 @@ def is_nested_type(s):
323329
324330# convert a rust-type to something that would be taken as input of a function
325331# even though our storage type is different
326- def activity_input_type (p ):
332+ def activity_input_type (schemas , p ):
327333 if 'input_type' in p :
328334 return p .input_type
329- n = activity_rust_type (p , allow_optionals = False )
335+ n = activity_rust_type (schemas , p , allow_optionals = False )
330336 if n == 'String' :
331337 n = 'str'
332338 # pods are copied anyway
@@ -370,6 +376,7 @@ def iter_nested_properties(prefix, properties):
370376 if 'properties' not in s :
371377 continue
372378 for np in iter_nested_properties (s .id , s .properties ):
379+ np .id = _assure_unique_type_name (schemas , np .id )
373380 yield np
374381 # end for aech schma
375382
@@ -409,8 +416,8 @@ def activity_split(fqan):
409416 return t [0 ], t [1 ], '.' .join (t [2 :])
410417
411418# Shorthand to get a type from parameters of activities
412- def activity_rust_type (p , allow_optionals = True ):
413- return to_rust_type (None , p .name , p , allow_optionals = allow_optionals )
419+ def activity_rust_type (schemas , p , allow_optionals = True ):
420+ return to_rust_type (schemas , None , p .name , p , allow_optionals = allow_optionals )
414421
415422# the inverse of activity-split, but needs to know the 'name' of the API
416423def to_fqan (name , resource , method ):
@@ -563,7 +570,7 @@ def build_all_params(schemas, c, m, n, npn):
563570Context = collections .namedtuple ('Context' , ['sta_map' , 'fqan_map' , 'rta_map' , 'rtc_map' ])
564571
565572# return a newly build context from the given data
566- def new_context (resources ):
573+ def new_context (schemas , resources ):
567574 if not resources :
568575 return Context (dict (), dict (), dict (), dict ())
569576 # Returns (A, B) where
@@ -587,7 +594,7 @@ def build_activity_mappings(activities, res = None, fqan = None):
587594 t = m .get (in_out_type_name , None )
588595 if t is None :
589596 continue
590- tn = to_rust_type (None , None , t , allow_optionals = False )
597+ tn = to_rust_type (schemas , None , None , t , allow_optionals = False )
591598 info = res .setdefault (tn , dict ())
592599 io_info = info .setdefault (m .id , [])
593600 io_info .append (in_out_type_name )
0 commit comments