mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-02-23 15:49:49 +01:00
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
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user