Skip to content

Commit 0d9f636

Browse files
committed
fix(nestedtypes): recursion for nested types
Drive has recursive nested types, which were not handled preeviously.
1 parent 66f3ae1 commit 0d9f636

6 files changed

Lines changed: 77 additions & 42 deletions

File tree

gen/youtube3/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ let r = hub.resource().activity(...).doit()
5151
Or specifically ...
5252

5353
```ignore
54-
let r = hub.videos().rate(...).doit()
55-
let r = hub.videos().getRating(...).doit()
56-
let r = hub.videos().list(...).doit()
57-
let r = hub.videos().insert(...).doit()
58-
let r = hub.videos().update(...).doit()
59-
let r = hub.videos().delete(...).doit()
54+
let r = hub.live_broadcasts().control(...).doit()
55+
let r = hub.live_broadcasts().insert(...).doit()
56+
let r = hub.live_broadcasts().list(...).doit()
57+
let r = hub.live_broadcasts().transition(...).doit()
58+
let r = hub.live_broadcasts().update(...).doit()
59+
let r = hub.live_broadcasts().delete(...).doit()
60+
let r = hub.live_broadcasts().bind(...).doit()
6061
```
6162

6263
The `resource()` and `activity(...)` calls create [builders][builder-pattern]. The second one dealing with `Activities`

gen/youtube3/src/lib.rs

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@
4848
//! Or specifically ...
4949
//!
5050
//! ```ignore
51-
//! let r = hub.videos().rate(...).doit()
52-
//! let r = hub.videos().getRating(...).doit()
53-
//! let r = hub.videos().list(...).doit()
54-
//! let r = hub.videos().insert(...).doit()
55-
//! let r = hub.videos().update(...).doit()
56-
//! let r = hub.videos().delete(...).doit()
51+
//! let r = hub.live_broadcasts().control(...).doit()
52+
//! let r = hub.live_broadcasts().insert(...).doit()
53+
//! let r = hub.live_broadcasts().list(...).doit()
54+
//! let r = hub.live_broadcasts().transition(...).doit()
55+
//! let r = hub.live_broadcasts().update(...).doit()
56+
//! let r = hub.live_broadcasts().delete(...).doit()
57+
//! let r = hub.live_broadcasts().bind(...).doit()
5758
//! ```
5859
//!
5960
//! The `resource()` and `activity(...)` calls create [builders][builder-pattern]. The second one dealing with `Activities`
@@ -126,7 +127,7 @@ use std::marker::PhantomData;
126127
use std::borrow::BorrowMut;
127128
use std::cell::RefCell;
128129
use std::default::Default;
129-
use std::io::{Read, Seek}
130+
use std::io::{Read, Seek};
130131

131132
pub use cmn::{Hub, ResourceMethodsBuilder, MethodBuilder, Resource, Part, ResponseResult, RequestValue, NestedType};
132133

@@ -589,7 +590,9 @@ impl Part for ChannelAuditDetails {}
589590
/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
590591
/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
591592
///
593+
/// * delete (none)
592594
/// * update (request|response)
595+
/// * list (none)
593596
/// * insert (request|response)
594597
///
595598
///
@@ -1102,6 +1105,8 @@ impl Part for InvideoPromotion {}
11021105
///
11031106
/// * insert (request|response)
11041107
/// * update (request|response)
1108+
/// * list (none)
1109+
/// * delete (none)
11051110
///
11061111
///
11071112
#[derive(RustcEncodable, RustcDecodable, Default, Clone)]
@@ -1223,7 +1228,7 @@ impl Part for ChannelSectionSnippet {}
12231228
#[derive(RustcEncodable, RustcDecodable, Default, Clone)]
12241229
pub struct ChannelContentDetails {
12251230
/// no description provided
1226-
pub related_playlists: HashMap<String, ChannelContentDetailsRelatedplaylists>,
1231+
pub related_playlists: HashMap<String, ChannelContentDetailsRelatedPlaylists>,
12271232
/// The googlePlusUserId object identifies the Google+ profile ID associated with this channel.
12281233
pub google_plus_user_id: Option<String>,
12291234
}
@@ -1389,7 +1394,13 @@ impl Part for ActivityContentDetails {}
13891394

13901395
/// A i18nRegion resource identifies a region where YouTube is available.
13911396
///
1392-
/// This type is not used in any activity, and only used as *part* of another schema.
1397+
/// # Activities
1398+
///
1399+
/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
1400+
/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
1401+
///
1402+
/// * list (none)
1403+
///
13931404
///
13941405
#[derive(RustcEncodable, RustcDecodable, Default, Clone)]
13951406
pub struct I18nRegion {
@@ -1403,7 +1414,7 @@ pub struct I18nRegion {
14031414
pub id: Option<String>,
14041415
}
14051416

1406-
impl Part for I18nRegion {}
1417+
impl Resource for I18nRegion {}
14071418

14081419

14091420
/// The contentOwnerDetails object encapsulates channel data that is relevant for YouTube Partners linked with the channel.
@@ -2098,8 +2109,10 @@ impl Part for LocalizedProperty {}
20982109
///
20992110
/// * control (response)
21002111
/// * insert (request|response)
2101-
/// * update (request|response)
2112+
/// * list (none)
21022113
/// * transition (response)
2114+
/// * update (request|response)
2115+
/// * delete (none)
21032116
/// * bind (response)
21042117
///
21052118
///
@@ -2653,7 +2666,9 @@ impl ResponseResult for ChannelListResponse {}
26532666
/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
26542667
/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
26552668
///
2669+
/// * delete (none)
26562670
/// * update (request|response)
2671+
/// * list (none)
26572672
/// * insert (request|response)
26582673
///
26592674
///
@@ -3115,7 +3130,13 @@ impl Part for ActivityContentDetailsBulletin {}
31153130

31163131
/// An i18nLanguage resource identifies a UI language currently supported by YouTube.
31173132
///
3118-
/// This type is not used in any activity, and only used as *part* of another schema.
3133+
/// # Activities
3134+
///
3135+
/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
3136+
/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
3137+
///
3138+
/// * list (none)
3139+
///
31193140
///
31203141
#[derive(RustcEncodable, RustcDecodable, Default, Clone)]
31213142
pub struct I18nLanguage {
@@ -3129,7 +3150,7 @@ pub struct I18nLanguage {
31293150
pub id: Option<String>,
31303151
}
31313152

3132-
impl Part for I18nLanguage {}
3153+
impl Resource for I18nLanguage {}
31333154

31343155

31353156
/// There is no detailed description.
@@ -3426,7 +3447,7 @@ impl Part for PageInfo {}
34263447
/// This type is not used in any activity, and only used as *part* of another schema.
34273448
///
34283449
#[derive(RustcEncodable, RustcDecodable, Default, Clone)]
3429-
pub struct ChannelContentDetailsRelatedplaylists {
3450+
pub struct ChannelContentDetailsRelatedPlaylists {
34303451
/// The ID of the playlist that contains the channel"s uploaded videos. Use the videos.insert method to upload new videos and the videos.delete method to delete previously uploaded videos.
34313452
pub uploads: Option<String>,
34323453
/// The ID of the playlist that contains the channel"s watch history. Use the playlistItems.insert and playlistItems.delete to add or remove items from that list.
@@ -3439,8 +3460,8 @@ pub struct ChannelContentDetailsRelatedplaylists {
34393460
pub watch_later: Option<String>,
34403461
}
34413462

3442-
impl NestedType for ChannelContentDetailsRelatedplaylists {}
3443-
impl Part for ChannelContentDetailsRelatedplaylists {}
3463+
impl NestedType for ChannelContentDetailsRelatedPlaylists {}
3464+
impl Part for ChannelContentDetailsRelatedPlaylists {}
34443465

34453466

34463467

@@ -3941,8 +3962,8 @@ impl<'a, C, NC, A> VideoMethodsBuilder<'a, C, NC, A> {
39413962
/// Create a builder to help you perform the following task:
39423963
///
39433964
/// Retrieves the ratings that the authorized user gave to a list of specified videos.
3944-
pub fn get_rating(&self, id: &str) -> VideoGetratingMethodBuilder<'a, C, NC, A> {
3945-
VideoGetratingMethodBuilder {
3965+
pub fn get_rating(&self, id: &str) -> VideoGetRatingMethodBuilder<'a, C, NC, A> {
3966+
VideoGetRatingMethodBuilder {
39463967
hub: self.hub,
39473968
_id: id.to_string(),
39483969
_on_behalf_of_content_owner: Default::default(),
@@ -6511,7 +6532,7 @@ impl<'a, C, NC, A> VideoRateMethodBuilder<'a, C, NC, A> {
65116532
/// // TODO: show how to handle the result !
65126533
/// # }
65136534
/// ```
6514-
pub struct VideoGetratingMethodBuilder<'a, C, NC, A>
6535+
pub struct VideoGetRatingMethodBuilder<'a, C, NC, A>
65156536
where NC: 'a,
65166537
C: 'a,
65176538
A: 'a, {
@@ -6521,9 +6542,9 @@ pub struct VideoGetratingMethodBuilder<'a, C, NC, A>
65216542
_on_behalf_of_content_owner: Option<String>,
65226543
}
65236544

6524-
impl<'a, C, NC, A> MethodBuilder for VideoGetratingMethodBuilder<'a, C, NC, A> {}
6545+
impl<'a, C, NC, A> MethodBuilder for VideoGetRatingMethodBuilder<'a, C, NC, A> {}
65256546

6526-
impl<'a, C, NC, A> VideoGetratingMethodBuilder<'a, C, NC, A> {
6547+
impl<'a, C, NC, A> VideoGetRatingMethodBuilder<'a, C, NC, A> {
65276548

65286549

65296550
/// Perform the operation you have build so far.
@@ -6539,7 +6560,7 @@ impl<'a, C, NC, A> VideoGetratingMethodBuilder<'a, C, NC, A> {
65396560
/// we provide this method for API completeness.
65406561
///
65416562
/// The id parameter specifies a comma-separated list of the YouTube video ID(s) for the resource(s) for which you are retrieving rating data. In a video resource, the id property specifies the video's ID.
6542-
pub fn id(mut self, new_value: &str) -> VideoGetratingMethodBuilder<'a, C, NC, A> {
6563+
pub fn id(mut self, new_value: &str) -> VideoGetRatingMethodBuilder<'a, C, NC, A> {
65436564
self._id = new_value.to_string();
65446565
return self;
65456566
}
@@ -6549,7 +6570,7 @@ impl<'a, C, NC, A> VideoGetratingMethodBuilder<'a, C, NC, A> {
65496570
/// Note: This parameter is intended exclusively for YouTube content partners.
65506571
///
65516572
/// The onBehalfOfContentOwner parameter indicates that the request's authorization credentials identify a YouTube CMS user who is acting on behalf of the content owner specified in the parameter value. This parameter is intended for YouTube content partners that own and manage many different YouTube channels. It allows content owners to authenticate once and get access to all their video and channel data, without having to provide authentication credentials for each individual channel. The CMS account that the user authenticates with must be linked to the specified YouTube content owner.
6552-
pub fn on_behalf_of_content_owner(mut self, new_value: &str) -> VideoGetratingMethodBuilder<'a, C, NC, A> {
6573+
pub fn on_behalf_of_content_owner(mut self, new_value: &str) -> VideoGetRatingMethodBuilder<'a, C, NC, A> {
65536574
self._on_behalf_of_content_owner = Some(new_value.to_string());
65546575
return self;
65556576
}

src/mako/lib.rs.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use std::marker::PhantomData;
3232
use std::borrow::BorrowMut;
3333
use std::cell::RefCell;
3434
use std::default::Default;
35-
use std::io::{Read, Seek}
35+
use std::io::{Read, Seek};
3636

3737
pub use cmn::{Hub, ResourceMethodsBuilder, MethodBuilder, Resource, Part, ResponseResult, RequestValue, NestedType};
3838

src/mako/lib/lib.mako

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<%! from util import (activity_split, put_and, md_italic, split_camelcase_s, canonical_type_name,
22
rust_test_fn_invisible, rust_doc_test_norun, rust_doc_comment, markdown_rust_block,
3-
unindent_first_by) %>\
3+
unindent_first_by, mangle_ident) %>\
44
<%namespace name="util" file="util.mako"/>\
55
66
## If rust-doc is True, examples will be made to work for rust doc tests. Otherwise they are set
@@ -47,7 +47,7 @@ Or specifically ...
4747
```ignore
4848
% for an, a in c.sta_map[fr.id].iteritems():
4949
<% resource, activity = activity_split(an) %>\
50-
let r = hub.${resource}().${activity}(...).${api.terms.action}()
50+
let r = hub.${mangle_ident(resource)}().${activity}(...).${api.terms.action}()
5151
% endfor
5252
```
5353

src/mako/lib/schema.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
## 's' contains the schema structure from json to build
66
<%def name="new(s, c)">\
77
<%
8-
assert s.type == "object"
8+
## assert s.type == "object"
99
markers = schema_markers(s, c)
1010
%>\
1111
<%block filter="rust_doc_comment">\

src/mako/lib/util.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,20 @@
1616
'double' : 'f64',
1717
'float' : 'f32',
1818
'int32' : 'i32',
19+
'int64' : 'i64',
20+
'uint64' : 'u64',
1921
'array' : 'Vec',
2022
'string' : 'String',
2123
'object' : 'HashMap'}
2224

2325
_words = [w.strip(',') for w in "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.".split(' ')]
2426
RUST_TYPE_RND_MAP = {'bool': lambda: str(bool(randint(0, 1))).lower(),
2527
'u32' : lambda: randint(0, 100),
28+
'u64' : lambda: randint(0, 100),
2629
'f64' : lambda: random(),
30+
'f32' : lambda: random(),
2731
'i32' : lambda: randint(-101, -1),
32+
'i64' : lambda: randint(-101, -1),
2833
'String': lambda: '"%s"' % choice(_words),
2934
}
3035
TREF = '$ref'
@@ -218,7 +223,7 @@ def canonical_type_name(s):
218223
return s[:1].upper() + s[1:]
219224

220225
def nested_type_name(sn, pn):
221-
return sn + pn.capitalize()
226+
return sn + canonical_type_name(pn)
222227

223228
# Make properties which are reserved keywords usable
224229
def mangle_ident(n):
@@ -273,7 +278,7 @@ def nested_type(nt):
273278

274279
# return True if this property is actually a nested type
275280
def is_nested_type_property(t):
276-
return 'type' in t and t.type == 'object' and 'properties' in t
281+
return 'type' in t and t.type == 'object' and 'properties' in t or ('items' in t and 'properties' in t.items)
277282

278283
# Return True if the schema is nested
279284
def is_nested_type(s):
@@ -295,16 +300,24 @@ def is_pod_property(p):
295300

296301
# return an iterator yielding fake-schemas that identify a nested type
297302
def iter_nested_types(schemas):
298-
for s in schemas.values():
299-
if 'properties' not in s:
300-
continue
301-
for pn, p in s.properties.iteritems():
303+
def iter_nested_properties(prefix, properties):
304+
for pn, p in properties.iteritems():
302305
if is_nested_type_property(p):
303306
ns = p.copy()
304-
ns.id = nested_type_name(s.id, pn)
307+
ns.id = nested_type_name(prefix, pn)
305308
ns[NESTED_TYPE_MARKER] = True
309+
if 'items' in p:
310+
ns.update(p.items.iteritems())
306311
yield ns
312+
for np in iter_nested_properties(prefix + canonical_type_name(pn), ns.properties):
313+
yield np
314+
# can be recursive ...
307315
# end for ach property
316+
for s in schemas.values():
317+
if 'properties' not in s:
318+
continue
319+
for np in iter_nested_properties(s.id, s.properties):
320+
yield np
308321
# end for aech schma
309322

310323
# Return sorted type names of all markers applicable to the given schema
@@ -353,7 +366,7 @@ def to_fqan(name, resource, method):
353366

354367
# videos -> Video
355368
def activity_name_to_type_name(an):
356-
return an.capitalize()[:-1]
369+
return canonical_type_name(an)[:-1]
357370

358371
# yields (resource, activity, activity_data)
359372
def iter_acitivities(c):
@@ -552,7 +565,7 @@ def mb_type_params_s(m):
552565

553566
# return type name for a method on the given resource
554567
def mb_type(r, m):
555-
return "%s%sMethodBuilder" % (singular(canonical_type_name(r)), m.capitalize())
568+
return "%s%sMethodBuilder" % (singular(canonical_type_name(r)), canonical_type_name(m))
556569

557570
def hub_type(canonicalName):
558571
return canonical_type_name(canonicalName)

0 commit comments

Comments
 (0)