fix(hash): nested type resolution and hashes

It seems we do it better than the actual Go implementation, which fails
to detect that scopes are actually having a string member.

However, there still is an issue, as it's as hashmap for us, but just
a member for go ... lets see ...
https://developers.google.com/discovery/v1/reference/apis#resource
shows that we implement it correctly :) !!
This commit is contained in:
Sebastian Thiel
2015-03-11 10:15:00 +01:00
parent 559cb8fe45
commit 5d563c88a8
6 changed files with 1327 additions and 1308 deletions

View File

@@ -54,13 +54,13 @@ let r = hub.resource().activity(...).doit()
Or specifically ...
```ignore
let r = hub.live_broadcast().control(...).doit()
let r = hub.live_broadcast().insert(...).doit()
let r = hub.live_broadcast().list(...).doit()
let r = hub.live_broadcast().transition(...).doit()
let r = hub.live_broadcast().update(...).doit()
let r = hub.live_broadcast().delete(...).doit()
let r = hub.live_broadcast().bind(...).doit()
let r = hub.live_broadcasts().control(...).doit()
let r = hub.live_broadcasts().insert(...).doit()
let r = hub.live_broadcasts().list(...).doit()
let r = hub.live_broadcasts().transition(...).doit()
let r = hub.live_broadcasts().update(...).doit()
let r = hub.live_broadcasts().delete(...).doit()
let r = hub.live_broadcasts().bind(...).doit()
```
The `resource()` and `activity(...)` calls create [builders][builder-pattern]. The second one dealing with `Activities`

File diff suppressed because it is too large Load Diff

View File

@@ -27,8 +27,8 @@ ${lib.docs(c)}
#![allow(dead_code)]
// We don't warn about this, as depending on the API, some data structures or facilities are never used.
// Instead of pre-determining this, we just disable the lint. It's manually tuned to not have any
// unused imports in fully featured APIs
#![allow(unused_imports)]
// unused imports in fully featured APIs. Same with unused_mut ... .
#![allow(unused_imports, unused_mut)]
extern crate hyper;

View File

@@ -341,7 +341,7 @@ ${'.' + action_name | indent_by(13)}(${action_args});
add_args = ', ' + stripped(add_args)
# end handle media params
action_fn = qualifier + 'fn ' + api.terms.action + type_params + ('(self%s)' % add_args) + ' -> ' + rtype + where
action_fn = qualifier + 'fn ' + api.terms.action + type_params + ('(mut self%s)' % add_args) + ' -> ' + rtype + where
field_params = [p for p in params if p.get('is_query_param', True)]

View File

@@ -7,6 +7,7 @@
###################################################################################################################
<%def name="new(s, c)">\
<%
assert s.type == "object"
markers = schema_markers(s, c)
%>\
<%block filter="rust_doc_comment">\

View File

@@ -254,18 +254,22 @@ def nested_type_name(sn, pn):
# Make properties which are reserved keywords usable
def mangle_ident(n):
n = camel_to_under(n).replace('-', '.').replace('.', '')
n = camel_to_under(n).replace('-', '.').replace('.', '').replace('$', '')
if n in RESERVED_WORDS:
return n + '_'
return n
def _is_map_prop(p):
return 'additionalProperties' in p
# map a json type to an rust type
# sn = schema name
# pn = property name
# t = type dict
# NOTE: In case you don't understand how this algorithm really works ... me neither - THE AUTHOR
def to_rust_type(sn, pn, t, allow_optionals=True):
def nested_type(nt):
if nt.get('items', None) is not None:
if 'items' in nt:
nt = nt.items
elif nt.get('additionalProperties'):
nt = nt.additionalProperties
@@ -288,7 +292,10 @@ def to_rust_type(sn, pn, t, allow_optionals=True):
rust_type = "%s<%s>" % (rust_type, nested_type(t))
is_pod = False
elif t.type == 'object':
rust_type = "%s<String, %s>" % (rust_type, nested_type(t))
if _is_map_prop(t):
rust_type = "%s<String, %s>" % (rust_type, nested_type(t))
else:
rust_type = nested_type(t)
is_pod = False
elif t.type == 'string' and 'Count' in pn:
rust_type = 'i64'
@@ -327,6 +334,7 @@ def is_pod_property(p):
return 'format' in p or p.get('type','') == 'boolean'
# 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):
def iter_nested_properties(prefix, properties):
for pn, p in properties.iteritems():
@@ -339,7 +347,11 @@ def iter_nested_types(schemas):
yield ns
for np in iter_nested_properties(prefix + canonical_type_name(pn), ns.properties):
yield np
# can be recursive ...
elif _is_map_prop(p):
# it's a hash, check its type
for np in iter_nested_properties(prefix, {pn: p.additionalProperties}):
yield np
# end handle prop itself
# end for ach property
for s in schemas.values():
if 'properties' not in s: