Skip to content

Commit

Permalink
fix(names): nested type names are consistent now
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Byron committed Mar 11, 2015
1 parent 538120f commit 32145e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/mako/lib/schema.mako
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<%! from util import (schema_markers, rust_doc_comment, mangle_ident, to_rust_type, put_and,
IO_TYPES, activity_split, enclose_in, REQUEST_MARKER_TRAIT, mb_type, indent_all_but_first_by)
IO_TYPES, activity_split, enclose_in, REQUEST_MARKER_TRAIT, mb_type, indent_all_but_first_by,
NESTED_TYPE_SUFFIX)
%>\
## Build a schema which must be an object
###################################################################################################################
Expand Down Expand Up @@ -32,12 +33,14 @@ ${doc(s, c)}\
#[derive(RustcEncodable, RustcDecodable, Default, Clone)]
% if s.type == 'object':
${_new_object(s, s.get('properties'), c)}\
% else: ## assume it's an array
% elif s.type == 'array':
% if s.items.get('type') != 'object':
pub struct ${s.id}(${to_rust_type(s.id, 'item', s)});
pub struct ${s.id}(${to_rust_type(s.id, NESTED_TYPE_SUFFIX, s)});
% else:
${_new_object(s, s.items.get('properties'), c)}\
% endif ## array item != 'object'
% else: ## probably any ... just represent it with NewType ... whatever that is
pub struct ${s.id};
% endif ## type == 'object'
% for marker_trait in markers:
Expand Down
6 changes: 6 additions & 0 deletions src/mako/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
NESTED_TYPE_MARKER = 'is_nested'
SPACES_PER_TAB = 4

NESTED_TYPE_SUFFIX = 'item'
DELEGATE_TYPE = 'Delegate'
REQUEST_PRIORITY = 100
REQUEST_MARKER_TRAIT = 'RequestValue'
Expand Down Expand Up @@ -339,6 +340,7 @@ def is_pod_property(p):
# return an iterator yielding fake-schemas that identify a nested type
# NOTE: In case you don't understand how this algorithm really works ... me neither - THE AUTHOR
def iter_nested_types(schemas):
# 'type' in t and t.type == 'object' and 'properties' in t or ('items' in t and 'properties' in t.items)
def iter_nested_properties(prefix, properties):
for pn, p in properties.iteritems():
if is_nested_type_property(p):
Expand All @@ -356,8 +358,12 @@ def iter_nested_properties(prefix, properties):
yield np
elif _is_map_prop(p):
# it's a hash, check its type
# TODO: does this code run ? Why is there a plain prefix
for np in iter_nested_properties(prefix, {pn: p.additionalProperties}):
yield np
elif 'items' in p:
for np in iter_nested_properties(prefix, {pn: p.items}):
yield np
# end handle prop itself
# end for ach property
for s in schemas.values():
Expand Down

0 comments on commit 32145e6

Please sign in to comment.