Skip to content

Commit d99ba9c

Browse files
committed
fix(mako): fix name clashes
Scopes could be invalid, previosly, and the hub type could clash with other types provided as Schema. Also, we used reserved identifiers
1 parent df9f029 commit d99ba9c

5 files changed

Lines changed: 31 additions & 21 deletions

File tree

gen/youtube3/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ use std::marker::PhantomData;
133133
use std::borrow::BorrowMut;
134134
use std::cell::RefCell;
135135
use std::default::Default;
136-
use std::io::{Read, Seek};
136+
use std::io;
137137
use std::fs;
138138
use std::collections::BTreeMap;
139139

@@ -5264,7 +5264,7 @@ impl<'a, C, NC, A> ChannelBannerInsertMethodBuilder<'a, C, NC, A> where NC: hype
52645264

52655265

52665266
/// Perform the operation you have build so far.
5267-
fn doit<R, RS>(mut self, stream: Option<(R, u64, mime::Mime)>, resumeable_stream: Option<(RS, u64, mime::Mime)>) -> Result<ChannelBannerResource> where R: Read, RS: ReadSeek {
5267+
fn doit<R, RS>(mut self, stream: Option<(R, u64, mime::Mime)>, resumeable_stream: Option<(RS, u64, mime::Mime)>) -> Result<ChannelBannerResource> where R: io::Read, RS: ReadSeek {
52685268
let mut params: Vec<(&str, String)> = Vec::with_capacity(3 + self._additional_params.len());
52695269
if self._on_behalf_of_content_owner.is_some() {
52705270
params.push(("onBehalfOfContentOwner", self._on_behalf_of_content_owner.unwrap().to_string()));
@@ -5304,7 +5304,7 @@ impl<'a, C, NC, A> ChannelBannerInsertMethodBuilder<'a, C, NC, A> where NC: hype
53045304
/// * *multipart*: yes
53055305
/// * *valid mime types*: 'application/octet-stream', 'image/jpeg' and 'image/png'
53065306
pub fn upload<R>(mut self, stream: R, size: u64, mime_type: mime::Mime) -> Result<ChannelBannerResource>
5307-
where R: Read {
5307+
where R: io::Read {
53085308
self.doit(Some((stream, size, mime_type)), None::<(fs::File, u64, mime::Mime)>, )
53095309
}
53105310
/// Upload media in a resumeable fashion.
@@ -7271,7 +7271,7 @@ impl<'a, C, NC, A> ThumbnailSetMethodBuilder<'a, C, NC, A> where NC: hyper::net:
72717271

72727272

72737273
/// Perform the operation you have build so far.
7274-
fn doit<R, RS>(mut self, stream: Option<(R, u64, mime::Mime)>, resumeable_stream: Option<(RS, u64, mime::Mime)>) -> Result<ThumbnailSetResponse> where R: Read, RS: ReadSeek {
7274+
fn doit<R, RS>(mut self, stream: Option<(R, u64, mime::Mime)>, resumeable_stream: Option<(RS, u64, mime::Mime)>) -> Result<ThumbnailSetResponse> where R: io::Read, RS: ReadSeek {
72757275
let mut params: Vec<(&str, String)> = Vec::with_capacity(3 + self._additional_params.len());
72767276
params.push(("videoId", self._video_id.to_string()));
72777277
if self._on_behalf_of_content_owner.is_some() {
@@ -7312,7 +7312,7 @@ impl<'a, C, NC, A> ThumbnailSetMethodBuilder<'a, C, NC, A> where NC: hyper::net:
73127312
/// * *multipart*: yes
73137313
/// * *valid mime types*: 'application/octet-stream', 'image/jpeg' and 'image/png'
73147314
pub fn upload<R>(mut self, stream: R, size: u64, mime_type: mime::Mime) -> Result<ThumbnailSetResponse>
7315-
where R: Read {
7315+
where R: io::Read {
73167316
self.doit(Some((stream, size, mime_type)), None::<(fs::File, u64, mime::Mime)>, )
73177317
}
73187318
/// Upload media in a resumeable fashion.
@@ -8540,7 +8540,7 @@ impl<'a, C, NC, A> VideoInsertMethodBuilder<'a, C, NC, A> where NC: hyper::net::
85408540

85418541

85428542
/// Perform the operation you have build so far.
8543-
fn doit<R, RS>(mut self, stream: Option<(R, u64, mime::Mime)>, resumeable_stream: Option<(RS, u64, mime::Mime)>) -> Result<Video> where R: Read, RS: ReadSeek {
8543+
fn doit<R, RS>(mut self, stream: Option<(R, u64, mime::Mime)>, resumeable_stream: Option<(RS, u64, mime::Mime)>) -> Result<Video> where R: io::Read, RS: ReadSeek {
85448544
let mut params: Vec<(&str, String)> = Vec::with_capacity(8 + self._additional_params.len());
85458545
if self._part.len() == 0 {
85468546
self._part = self._request.to_parts();
@@ -8596,7 +8596,7 @@ impl<'a, C, NC, A> VideoInsertMethodBuilder<'a, C, NC, A> where NC: hyper::net::
85968596
/// * *multipart*: yes
85978597
/// * *valid mime types*: 'application/octet-stream' and 'video/*'
85988598
pub fn upload<R>(mut self, stream: R, size: u64, mime_type: mime::Mime) -> Result<Video>
8599-
where R: Read {
8599+
where R: io::Read {
86008600
self.doit(Some((stream, size, mime_type)), None::<(fs::File, u64, mime::Mime)>, )
86018601
}
86028602
/// Upload media in a resumeable fashion.
@@ -12292,7 +12292,7 @@ impl<'a, C, NC, A> WatermarkSetMethodBuilder<'a, C, NC, A> where NC: hyper::net:
1229212292

1229312293

1229412294
/// Perform the operation you have build so far.
12295-
fn doit<R, RS>(mut self, stream: Option<(R, u64, mime::Mime)>, resumeable_stream: Option<(RS, u64, mime::Mime)>) -> Result<()> where R: Read, RS: ReadSeek {
12295+
fn doit<R, RS>(mut self, stream: Option<(R, u64, mime::Mime)>, resumeable_stream: Option<(RS, u64, mime::Mime)>) -> Result<()> where R: io::Read, RS: ReadSeek {
1229612296
let mut params: Vec<(&str, String)> = Vec::with_capacity(4 + self._additional_params.len());
1229712297
params.push(("channelId", self._channel_id.to_string()));
1229812298
if self._on_behalf_of_content_owner.is_some() {
@@ -12333,7 +12333,7 @@ impl<'a, C, NC, A> WatermarkSetMethodBuilder<'a, C, NC, A> where NC: hyper::net:
1233312333
/// * *multipart*: yes
1233412334
/// * *valid mime types*: 'application/octet-stream', 'image/jpeg' and 'image/png'
1233512335
pub fn upload<R>(mut self, stream: R, size: u64, mime_type: mime::Mime) -> Result<()>
12336-
where R: Read {
12336+
where R: io::Read {
1233712337
self.doit(Some((stream, size, mime_type)), None::<(fs::File, u64, mime::Mime)>, )
1233812338
}
1233912339
/// Upload media in a resumeable fashion.

src/mako/lib.rs.mako

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
if schemas:
1313
nested_schemas = list(iter_nested_types(schemas))
1414
c = new_context(resources)
15-
hub_type = hub_type(util.canonical_name())
15+
hub_type = hub_type(schemas, util.canonical_name())
1616
ht_params = hub_type_params_s()
1717
%>\
1818
<%block filter="rust_comment">\
@@ -37,7 +37,7 @@ use std::marker::PhantomData;
3737
use std::borrow::BorrowMut;
3838
use std::cell::RefCell;
3939
use std::default::Default;
40-
use std::io::{Read, Seek};
40+
use std::io;
4141
use std::fs;
4242
use std::collections::BTreeMap;
4343

src/mako/lib/mbuild.mako

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
###############################################################################################
3232
<%def name="new(resource, method, c)">\
3333
<%
34-
hub_type_name = hub_type(util.canonical_name())
34+
hub_type_name = hub_type(schemas,util.canonical_name())
3535
m = c.fqan_map[to_fqan(c.rtc_map[resource], resource, method)]
3636
# an identifier for a property. We prefix them to prevent clashes with the setters
3737
mb_tparams = mb_type_params_s(m)
@@ -212,7 +212,7 @@ ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\
212212
###############################################################################################
213213
<%def name="usage(resource, method, m, params, request_value, parts)">\
214214
<%
215-
hub_type_name = hub_type(util.canonical_name())
215+
hub_type_name = hub_type(schemas, util.canonical_name())
216216
required_props, optional_props, part_prop = organize_params(params, request_value)
217217
is_string_value = lambda v: v.endswith('"')
218218

src/mako/lib/rbuild.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
###############################################################################################
1515
<%def name="new(resource, c)">\
1616
<%
17-
hub_type_name = hub_type(util.canonical_name())
17+
hub_type_name = hub_type(schemas, util.canonical_name())
1818
rb_params = rb_type_params_s(resource, c)
1919
ThisType = rb_type(resource) + rb_params
2020
%>\

src/mako/lib/util.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
'description': """Upload media all at once.
5959
If the upload fails for whichever reason, all progress is lost.""",
6060
'default': 'fs::File',
61-
'where': 'Read',
61+
'where': 'io::Read',
6262
'suffix': '',
6363
'example_value': 'fs::File::open("file.ext").unwrap(), 148, "application/octet-stream".parse().unwrap()'
6464
},
@@ -238,6 +238,7 @@ def extract_parts(desc):
238238
# Return transformed string that could make a good type name
239239
def canonical_type_name(s):
240240
# can't use s.capitalize() as it will lower-case the remainder of the string
241+
s = s.replace(' ', '')
241242
return s[:1].upper() + s[1:]
242243

243244
def nested_type_name(sn, pn):
@@ -246,7 +247,7 @@ def nested_type_name(sn, pn):
246247
# Make properties which are reserved keywords usable
247248
def mangle_ident(n):
248249
n = '_'.join(singular(w) for w in camel_to_under(n).split('.'))
249-
if n == 'type':
250+
if n in ('type', 'where', 'override', 'move'):
250251
return n + '_'
251252
return n
252253

@@ -635,8 +636,11 @@ def mb_additional_type_params(m):
635636
def mb_type(r, m):
636637
return "%s%sMethodBuilder" % (singular(canonical_type_name(r)), dot_sep_to_canonical_type_name(m))
637638

638-
def hub_type(canonicalName):
639-
return canonical_type_name(canonicalName)
639+
def hub_type(schemas, canonicalName):
640+
name = canonical_type_name(canonicalName)
641+
if schemas and name in schemas:
642+
name += 'Hub'
643+
return name
640644

641645
# return e + d[n] + e + ' ' or ''
642646
def get_word(d, n, e = ''):
@@ -661,16 +665,22 @@ def dot_sep_to_canonical_type_name(n):
661665
def scope_url_to_variant(name, url, fully_qualified=True):
662666
FULL = 'Full'
663667
fqvn = lambda n: fully_qualified and 'Scope::%s' % n or n
668+
repl = lambda n: n.replace('-', '.').replace('_', '.')
669+
670+
if url.endswith('/'):
671+
url = name[:-1]
664672
base = os.path.basename(url)
673+
674+
assert base, name
665675
# special case, which works for now ... https://mail.gmail.com
676+
# NO can do ! Must play safe here ...
666677
if not base.startswith(name):
667-
return fqvn(FULL)
678+
return fqvn(dot_sep_to_canonical_type_name(repl(base)))
668679
base = base[len(name):]
669680
base = base.strip('-').strip('.')
670681
if len(base) == 0:
671682
return fqvn(FULL)
672-
base = base.replace('-', '.')
673-
return fqvn(dot_sep_to_canonical_type_name(base))
683+
return fqvn(dot_sep_to_canonical_type_name(repl(base)))
674684

675685

676686
# given a rust type-name (no optional, as from to_rust_type), you will get a suitable random default value

0 commit comments

Comments
 (0)