From 32145e645ea29ff43c451530906356564e12f817 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 11 Mar 2015 14:58:02 +0100 Subject: [PATCH] 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 --- src/mako/lib/schema.mako | 9 ++++++--- src/mako/lib/util.py | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/mako/lib/schema.mako b/src/mako/lib/schema.mako index 7912b79e30..fa329a1d1c 100644 --- a/src/mako/lib/schema.mako +++ b/src/mako/lib/schema.mako @@ -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 ################################################################################################################### @@ -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: diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index 4055aa3a5f..302c436b52 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -52,6 +52,7 @@ DEL_METHOD = 'delete' NESTED_TYPE_MARKER = 'is_nested' SPACES_PER_TAB = 4 +NESTED_TYPE_SUFFIX = 'item' DELEGATE_TYPE = 'Delegate' REQUEST_PRIORITY = 100 REQUEST_MARKER_TRAIT = 'RequestValue' @@ -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): @@ -356,8 +358,12 @@ def iter_nested_types(schemas): 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():