Skip to content

Commit 32145e6

Browse files
committed
fix(names): nested type names are consistent now
At least so it appears. The implementation doesn't look totally clean to me, as it seems similar concerns are in different portions of the code, which was merely tuned to work together. It could break appart if someone - me - wants to change it sometime
1 parent 538120f commit 32145e6

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/mako/lib/schema.mako

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<%! from util import (schema_markers, rust_doc_comment, mangle_ident, to_rust_type, put_and,
2-
IO_TYPES, activity_split, enclose_in, REQUEST_MARKER_TRAIT, mb_type, indent_all_but_first_by)
2+
IO_TYPES, activity_split, enclose_in, REQUEST_MARKER_TRAIT, mb_type, indent_all_but_first_by,
3+
NESTED_TYPE_SUFFIX)
34
%>\
45
## Build a schema which must be an object
56
###################################################################################################################
@@ -32,12 +33,14 @@ ${doc(s, c)}\
3233
#[derive(RustcEncodable, RustcDecodable, Default, Clone)]
3334
% if s.type == 'object':
3435
${_new_object(s, s.get('properties'), c)}\
35-
% else: ## assume it's an array
36+
% elif s.type == 'array':
3637
% if s.items.get('type') != 'object':
37-
pub struct ${s.id}(${to_rust_type(s.id, 'item', s)});
38+
pub struct ${s.id}(${to_rust_type(s.id, NESTED_TYPE_SUFFIX, s)});
3839
% else:
3940
${_new_object(s, s.items.get('properties'), c)}\
4041
% endif ## array item != 'object'
42+
% else: ## probably any ... just represent it with NewType ... whatever that is
43+
pub struct ${s.id};
4144
% endif ## type == 'object'
4245
4346
% for marker_trait in markers:

src/mako/lib/util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
NESTED_TYPE_MARKER = 'is_nested'
5353
SPACES_PER_TAB = 4
5454

55+
NESTED_TYPE_SUFFIX = 'item'
5556
DELEGATE_TYPE = 'Delegate'
5657
REQUEST_PRIORITY = 100
5758
REQUEST_MARKER_TRAIT = 'RequestValue'
@@ -339,6 +340,7 @@ def is_pod_property(p):
339340
# return an iterator yielding fake-schemas that identify a nested type
340341
# NOTE: In case you don't understand how this algorithm really works ... me neither - THE AUTHOR
341342
def iter_nested_types(schemas):
343+
# 'type' in t and t.type == 'object' and 'properties' in t or ('items' in t and 'properties' in t.items)
342344
def iter_nested_properties(prefix, properties):
343345
for pn, p in properties.iteritems():
344346
if is_nested_type_property(p):
@@ -356,8 +358,12 @@ def iter_nested_properties(prefix, properties):
356358
yield np
357359
elif _is_map_prop(p):
358360
# it's a hash, check its type
361+
# TODO: does this code run ? Why is there a plain prefix
359362
for np in iter_nested_properties(prefix, {pn: p.additionalProperties}):
360363
yield np
364+
elif 'items' in p:
365+
for np in iter_nested_properties(prefix, {pn: p.items}):
366+
yield np
361367
# end handle prop itself
362368
# end for ach property
363369
for s in schemas.values():

0 commit comments

Comments
 (0)