mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-02-23 15:49:49 +01:00
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:
@@ -54,13 +54,13 @@ let r = hub.resource().activity(...).doit()
|
|||||||
Or specifically ...
|
Or specifically ...
|
||||||
|
|
||||||
```ignore
|
```ignore
|
||||||
let r = hub.live_broadcast().control(...).doit()
|
let r = hub.live_broadcasts().control(...).doit()
|
||||||
let r = hub.live_broadcast().insert(...).doit()
|
let r = hub.live_broadcasts().insert(...).doit()
|
||||||
let r = hub.live_broadcast().list(...).doit()
|
let r = hub.live_broadcasts().list(...).doit()
|
||||||
let r = hub.live_broadcast().transition(...).doit()
|
let r = hub.live_broadcasts().transition(...).doit()
|
||||||
let r = hub.live_broadcast().update(...).doit()
|
let r = hub.live_broadcasts().update(...).doit()
|
||||||
let r = hub.live_broadcast().delete(...).doit()
|
let r = hub.live_broadcasts().delete(...).doit()
|
||||||
let r = hub.live_broadcast().bind(...).doit()
|
let r = hub.live_broadcasts().bind(...).doit()
|
||||||
```
|
```
|
||||||
|
|
||||||
The `resource()` and `activity(...)` calls create [builders][builder-pattern]. The second one dealing with `Activities`
|
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
@@ -27,8 +27,8 @@ ${lib.docs(c)}
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
// We don't warn about this, as depending on the API, some data structures or facilities are never used.
|
// 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
|
// Instead of pre-determining this, we just disable the lint. It's manually tuned to not have any
|
||||||
// unused imports in fully featured APIs
|
// unused imports in fully featured APIs. Same with unused_mut ... .
|
||||||
#![allow(unused_imports)]
|
#![allow(unused_imports, unused_mut)]
|
||||||
|
|
||||||
|
|
||||||
extern crate hyper;
|
extern crate hyper;
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ ${'.' + action_name | indent_by(13)}(${action_args});
|
|||||||
add_args = ', ' + stripped(add_args)
|
add_args = ', ' + stripped(add_args)
|
||||||
# end handle media params
|
# 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)]
|
field_params = [p for p in params if p.get('is_query_param', True)]
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
###################################################################################################################
|
###################################################################################################################
|
||||||
<%def name="new(s, c)">\
|
<%def name="new(s, c)">\
|
||||||
<%
|
<%
|
||||||
|
assert s.type == "object"
|
||||||
markers = schema_markers(s, c)
|
markers = schema_markers(s, c)
|
||||||
%>\
|
%>\
|
||||||
<%block filter="rust_doc_comment">\
|
<%block filter="rust_doc_comment">\
|
||||||
|
|||||||
@@ -254,18 +254,22 @@ def nested_type_name(sn, pn):
|
|||||||
|
|
||||||
# Make properties which are reserved keywords usable
|
# Make properties which are reserved keywords usable
|
||||||
def mangle_ident(n):
|
def mangle_ident(n):
|
||||||
n = camel_to_under(n).replace('-', '.').replace('.', '')
|
n = camel_to_under(n).replace('-', '.').replace('.', '').replace('$', '')
|
||||||
if n in RESERVED_WORDS:
|
if n in RESERVED_WORDS:
|
||||||
return n + '_'
|
return n + '_'
|
||||||
return n
|
return n
|
||||||
|
|
||||||
|
def _is_map_prop(p):
|
||||||
|
return 'additionalProperties' in p
|
||||||
|
|
||||||
# map a json type to an rust type
|
# map a json type to an rust type
|
||||||
# sn = schema name
|
# sn = schema name
|
||||||
# pn = property name
|
# pn = property name
|
||||||
# t = type dict
|
# 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 to_rust_type(sn, pn, t, allow_optionals=True):
|
||||||
def nested_type(nt):
|
def nested_type(nt):
|
||||||
if nt.get('items', None) is not None:
|
if 'items' in nt:
|
||||||
nt = nt.items
|
nt = nt.items
|
||||||
elif nt.get('additionalProperties'):
|
elif nt.get('additionalProperties'):
|
||||||
nt = nt.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))
|
rust_type = "%s<%s>" % (rust_type, nested_type(t))
|
||||||
is_pod = False
|
is_pod = False
|
||||||
elif t.type == 'object':
|
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
|
is_pod = False
|
||||||
elif t.type == 'string' and 'Count' in pn:
|
elif t.type == 'string' and 'Count' in pn:
|
||||||
rust_type = 'i64'
|
rust_type = 'i64'
|
||||||
@@ -327,6 +334,7 @@ def is_pod_property(p):
|
|||||||
return 'format' in p or p.get('type','') == 'boolean'
|
return 'format' in p or p.get('type','') == 'boolean'
|
||||||
|
|
||||||
# return an iterator yielding fake-schemas that identify a nested type
|
# 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_types(schemas):
|
||||||
def iter_nested_properties(prefix, properties):
|
def iter_nested_properties(prefix, properties):
|
||||||
for pn, p in properties.iteritems():
|
for pn, p in properties.iteritems():
|
||||||
@@ -339,7 +347,11 @@ def iter_nested_types(schemas):
|
|||||||
yield ns
|
yield ns
|
||||||
for np in iter_nested_properties(prefix + canonical_type_name(pn), ns.properties):
|
for np in iter_nested_properties(prefix + canonical_type_name(pn), ns.properties):
|
||||||
yield np
|
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
|
# end for ach property
|
||||||
for s in schemas.values():
|
for s in schemas.values():
|
||||||
if 'properties' not in s:
|
if 'properties' not in s:
|
||||||
|
|||||||
Reference in New Issue
Block a user