From 614539a925c5e64508fa28506b1c6db3ccd96882 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 11 Mar 2015 15:30:11 +0100 Subject: [PATCH] fix(type-clashes): protect from nested-type-clash It was possible for a nested type to be generated with a name that in fact CLASHED with an existing schema type. What are the odds ! The clash-check added will just verify against clashes with schema types, which seems to be doing it for now. --- gen/youtube3/src/lib.rs | 90 ++++++++++++++++++++-------------------- src/mako/README.md.mako | 2 +- src/mako/lib.rs.mako | 2 +- src/mako/lib/mbuild.mako | 8 ++-- src/mako/lib/rbuild.mako | 6 +-- src/mako/lib/schema.mako | 8 ++-- src/mako/lib/util.py | 25 +++++++---- 7 files changed, 74 insertions(+), 67 deletions(-) diff --git a/gen/youtube3/src/lib.rs b/gen/youtube3/src/lib.rs index 1a2d05fad05..81c82792024 100644 --- a/gen/youtube3/src/lib.rs +++ b/gen/youtube3/src/lib.rs @@ -5199,7 +5199,7 @@ impl<'a, C, NC, A> I18nLanguageListMethodBuilder<'a, C, NC, A> where NC: hyper:: /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> I18nLanguageListMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> I18nLanguageListMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -5391,7 +5391,7 @@ impl<'a, C, NC, A> ChannelBannerInsertMethodBuilder<'a, C, NC, A> where NC: hype /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> ChannelBannerInsertMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> ChannelBannerInsertMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -5606,7 +5606,7 @@ impl<'a, C, NC, A> ChannelSectionListMethodBuilder<'a, C, NC, A> where NC: hyper /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> ChannelSectionListMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> ChannelSectionListMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -5825,7 +5825,7 @@ impl<'a, C, NC, A> ChannelSectionInsertMethodBuilder<'a, C, NC, A> where NC: hyp /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> ChannelSectionInsertMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> ChannelSectionInsertMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -5979,7 +5979,7 @@ impl<'a, C, NC, A> ChannelSectionDeleteMethodBuilder<'a, C, NC, A> where NC: hyp /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> ChannelSectionDeleteMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> ChannelSectionDeleteMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -6181,7 +6181,7 @@ impl<'a, C, NC, A> ChannelSectionUpdateMethodBuilder<'a, C, NC, A> where NC: hyp /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> ChannelSectionUpdateMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> ChannelSectionUpdateMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -6379,7 +6379,7 @@ impl<'a, C, NC, A> GuideCategoryListMethodBuilder<'a, C, NC, A> where NC: hyper: /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> GuideCategoryListMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> GuideCategoryListMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -6598,7 +6598,7 @@ impl<'a, C, NC, A> PlaylistInsertMethodBuilder<'a, C, NC, A> where NC: hyper::ne /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> PlaylistInsertMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> PlaylistInsertMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -6858,7 +6858,7 @@ impl<'a, C, NC, A> PlaylistListMethodBuilder<'a, C, NC, A> where NC: hyper::net: /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> PlaylistListMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> PlaylistListMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -7012,7 +7012,7 @@ impl<'a, C, NC, A> PlaylistDeleteMethodBuilder<'a, C, NC, A> where NC: hyper::ne /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> PlaylistDeleteMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> PlaylistDeleteMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -7216,7 +7216,7 @@ impl<'a, C, NC, A> PlaylistUpdateMethodBuilder<'a, C, NC, A> where NC: hyper::ne /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> PlaylistUpdateMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> PlaylistUpdateMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -7398,7 +7398,7 @@ impl<'a, C, NC, A> ThumbnailSetMethodBuilder<'a, C, NC, A> where NC: hyper::net: /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> ThumbnailSetMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> ThumbnailSetMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -7715,7 +7715,7 @@ impl<'a, C, NC, A> VideoListMethodBuilder<'a, C, NC, A> where NC: hyper::net::Ne /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> VideoListMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> VideoListMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -7881,7 +7881,7 @@ impl<'a, C, NC, A> VideoRateMethodBuilder<'a, C, NC, A> where NC: hyper::net::Ne /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> VideoRateMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> VideoRateMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -8035,7 +8035,7 @@ impl<'a, C, NC, A> VideoGetRatingMethodBuilder<'a, C, NC, A> where NC: hyper::ne /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> VideoGetRatingMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> VideoGetRatingMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -8189,7 +8189,7 @@ impl<'a, C, NC, A> VideoDeleteMethodBuilder<'a, C, NC, A> where NC: hyper::net:: /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> VideoDeleteMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> VideoDeleteMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -8435,7 +8435,7 @@ impl<'a, C, NC, A> VideoUpdateMethodBuilder<'a, C, NC, A> where NC: hyper::net:: /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> VideoUpdateMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> VideoUpdateMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -8764,7 +8764,7 @@ impl<'a, C, NC, A> VideoInsertMethodBuilder<'a, C, NC, A> where NC: hyper::net:: /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> VideoInsertMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> VideoInsertMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -8951,7 +8951,7 @@ impl<'a, C, NC, A> SubscriptionInsertMethodBuilder<'a, C, NC, A> where NC: hyper /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> SubscriptionInsertMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> SubscriptionInsertMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -9248,7 +9248,7 @@ impl<'a, C, NC, A> SubscriptionListMethodBuilder<'a, C, NC, A> where NC: hyper:: /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> SubscriptionListMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> SubscriptionListMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -9387,7 +9387,7 @@ impl<'a, C, NC, A> SubscriptionDeleteMethodBuilder<'a, C, NC, A> where NC: hyper /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> SubscriptionDeleteMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> SubscriptionDeleteMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -9927,7 +9927,7 @@ impl<'a, C, NC, A> SearchListMethodBuilder<'a, C, NC, A> where NC: hyper::net::N /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> SearchListMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> SearchListMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -10097,7 +10097,7 @@ impl<'a, C, NC, A> I18nRegionListMethodBuilder<'a, C, NC, A> where NC: hyper::ne /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> I18nRegionListMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> I18nRegionListMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -10323,7 +10323,7 @@ impl<'a, C, NC, A> LiveStreamUpdateMethodBuilder<'a, C, NC, A> where NC: hyper:: /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> LiveStreamUpdateMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> LiveStreamUpdateMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -10494,7 +10494,7 @@ impl<'a, C, NC, A> LiveStreamDeleteMethodBuilder<'a, C, NC, A> where NC: hyper:: /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> LiveStreamDeleteMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> LiveStreamDeleteMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -10738,7 +10738,7 @@ impl<'a, C, NC, A> LiveStreamListMethodBuilder<'a, C, NC, A> where NC: hyper::ne /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> LiveStreamListMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> LiveStreamListMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -10962,7 +10962,7 @@ impl<'a, C, NC, A> LiveStreamInsertMethodBuilder<'a, C, NC, A> where NC: hyper:: /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> LiveStreamInsertMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> LiveStreamInsertMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -11164,7 +11164,7 @@ impl<'a, C, NC, A> ChannelUpdateMethodBuilder<'a, C, NC, A> where NC: hyper::net /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> ChannelUpdateMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> ChannelUpdateMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -11449,7 +11449,7 @@ impl<'a, C, NC, A> ChannelListMethodBuilder<'a, C, NC, A> where NC: hyper::net:: /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> ChannelListMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> ChannelListMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -11588,7 +11588,7 @@ impl<'a, C, NC, A> PlaylistItemDeleteMethodBuilder<'a, C, NC, A> where NC: hyper /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> PlaylistItemDeleteMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> PlaylistItemDeleteMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -11831,7 +11831,7 @@ impl<'a, C, NC, A> PlaylistItemListMethodBuilder<'a, C, NC, A> where NC: hyper:: /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> PlaylistItemListMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> PlaylistItemListMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -12037,7 +12037,7 @@ impl<'a, C, NC, A> PlaylistItemInsertMethodBuilder<'a, C, NC, A> where NC: hyper /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> PlaylistItemInsertMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> PlaylistItemInsertMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -12230,7 +12230,7 @@ impl<'a, C, NC, A> PlaylistItemUpdateMethodBuilder<'a, C, NC, A> where NC: hyper /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> PlaylistItemUpdateMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> PlaylistItemUpdateMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -12428,7 +12428,7 @@ impl<'a, C, NC, A> WatermarkSetMethodBuilder<'a, C, NC, A> where NC: hyper::net: /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> WatermarkSetMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> WatermarkSetMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -12580,7 +12580,7 @@ impl<'a, C, NC, A> WatermarkUnsetMethodBuilder<'a, C, NC, A> where NC: hyper::ne /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> WatermarkUnsetMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> WatermarkUnsetMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -12824,7 +12824,7 @@ impl<'a, C, NC, A> LiveBroadcastControlMethodBuilder<'a, C, NC, A> where NC: hyp /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> LiveBroadcastControlMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> LiveBroadcastControlMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -13050,7 +13050,7 @@ impl<'a, C, NC, A> LiveBroadcastUpdateMethodBuilder<'a, C, NC, A> where NC: hype /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> LiveBroadcastUpdateMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> LiveBroadcastUpdateMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -13274,7 +13274,7 @@ impl<'a, C, NC, A> LiveBroadcastInsertMethodBuilder<'a, C, NC, A> where NC: hype /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> LiveBroadcastInsertMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> LiveBroadcastInsertMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -13488,7 +13488,7 @@ impl<'a, C, NC, A> LiveBroadcastBindMethodBuilder<'a, C, NC, A> where NC: hyper: /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> LiveBroadcastBindMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> LiveBroadcastBindMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -13745,7 +13745,7 @@ impl<'a, C, NC, A> LiveBroadcastListMethodBuilder<'a, C, NC, A> where NC: hyper: /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> LiveBroadcastListMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> LiveBroadcastListMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -13916,7 +13916,7 @@ impl<'a, C, NC, A> LiveBroadcastDeleteMethodBuilder<'a, C, NC, A> where NC: hype /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> LiveBroadcastDeleteMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> LiveBroadcastDeleteMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -14129,7 +14129,7 @@ impl<'a, C, NC, A> LiveBroadcastTransitionMethodBuilder<'a, C, NC, A> where NC: /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> LiveBroadcastTransitionMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> LiveBroadcastTransitionMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -14325,7 +14325,7 @@ impl<'a, C, NC, A> VideoCategoryListMethodBuilder<'a, C, NC, A> where NC: hyper: /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> VideoCategoryListMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> VideoCategoryListMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -14589,7 +14589,7 @@ impl<'a, C, NC, A> ActivityListMethodBuilder<'a, C, NC, A> where NC: hyper::net: /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> ActivityListMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> ActivityListMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self @@ -14775,7 +14775,7 @@ impl<'a, C, NC, A> ActivityInsertMethodBuilder<'a, C, NC, A> where NC: hyper::ne /// Usually there is more than one suitable scope to authorize an operation, some of which may /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be /// sufficient, a read-write scope will do as well. - pub fn scope(mut self, scope: T) -> ActivityInsertMethodBuilder<'a, C, NC, A> + pub fn add_scope(mut self, scope: T) -> ActivityInsertMethodBuilder<'a, C, NC, A> where T: Str { self._scopes.insert(scope.as_slice().to_string(), ()); self diff --git a/src/mako/README.md.mako b/src/mako/README.md.mako index 44e17c64b07..73eae4a4a54 100644 --- a/src/mako/README.md.mako +++ b/src/mako/README.md.mako @@ -1,6 +1,6 @@ <% from util import (markdown_comment, new_context) - c = new_context(resources) + c = new_context(schemas, resources) %>\ <%namespace name="lib" file="lib/lib.mako"/>\ <%namespace name="util" file="lib/util.mako"/>\ diff --git a/src/mako/lib.rs.mako b/src/mako/lib.rs.mako index 690e01b4757..3f61671e831 100644 --- a/src/mako/lib.rs.mako +++ b/src/mako/lib.rs.mako @@ -11,7 +11,7 @@ nested_schemas = list() if schemas: nested_schemas = list(iter_nested_types(schemas)) - c = new_context(resources) + c = new_context(schemas, resources) hub_type = hub_type(schemas, util.canonical_name()) ht_params = hub_type_params_s() %>\ diff --git a/src/mako/lib/mbuild.mako b/src/mako/lib/mbuild.mako index caec9166bd6..97e80386a97 100644 --- a/src/mako/lib/mbuild.mako +++ b/src/mako/lib/mbuild.mako @@ -90,9 +90,9 @@ pub struct ${ThisType} % for p in params: ${property(p.name)}:\ % if is_required_property(p): - ${activity_rust_type(p, allow_optionals=False)}, + ${activity_rust_type(schemas, p, allow_optionals=False)}, % else: - ${activity_rust_type(p)}, + ${activity_rust_type(schemas, p)}, % endif % endfor ## A generic map for additinal parameters. Sometimes you can set some that are documented online only @@ -161,7 +161,7 @@ ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\ ############################################################################################### <%def name="_setter_fn(resource, method, m, p, part_prop, ThisType, c)">\ <% - InType = activity_input_type(p) + InType = activity_input_type(schemas, p) def show_part_info(m, p): if p.name != 'part': @@ -217,7 +217,7 @@ ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\ is_string_value = lambda v: v.endswith('"') # to rust value - trv = lambda spn, sp, sn=None: to_rust_type(sn, spn, sp, allow_optionals=False) + trv = lambda spn, sp, sn=None: to_rust_type(schemas, sn, spn, sp, allow_optionals=False) # rvfrt = random value for rust type rvfrt = lambda spn, sp, sn=None: rnd_arg_val_for_type(trv(spn, sp, sn)) diff --git a/src/mako/lib/rbuild.mako b/src/mako/lib/rbuild.mako index 6bbca0af514..0d5f024aff4 100644 --- a/src/mako/lib/rbuild.mako +++ b/src/mako/lib/rbuild.mako @@ -61,13 +61,13 @@ impl${rb_params} ${ThisType} { method_args = '' if required_props: - method_args = ', ' + ', '.join('%s: %s' % (mangle_ident(p.name), activity_input_type(p)) for p in required_props) + method_args = ', ' + ', '.join('%s: %s' % (mangle_ident(p.name), activity_input_type(schemas, p)) for p in required_props) mb_tparams = mb_type_params_s(m) # we would could have information about data requirements for each property in it's dict. # for now, we just hardcode it, and treat the entries as way to easily change param names assert len(api.properties) == 2, "Hardcoded for now, thanks to scope requirements" - + type_params = '' if mb_additional_type_params(m): type_params = '<%s>' % ', '.join(mb_additional_type_params(m)) @@ -82,7 +82,7 @@ impl${rb_params} ${ThisType} { ${RType} { hub: self.hub, % for p in required_props: - ${property(p.name)}: ${rust_copy_value_s(mangle_ident(p.name), activity_input_type(p), p)}, + ${property(p.name)}: ${rust_copy_value_s(mangle_ident(p.name), activity_input_type(schemas, p), p)}, % endfor ## auto-generate parts from request resources % if part_prop and request_value: diff --git a/src/mako/lib/schema.mako b/src/mako/lib/schema.mako index fa329a1d1c6..ca6033f87e2 100644 --- a/src/mako/lib/schema.mako +++ b/src/mako/lib/schema.mako @@ -11,7 +11,7 @@ pub struct ${s.id}\ { % for pn, p in properties.iteritems(): ${p.get('description', 'no description provided') | rust_doc_comment, indent_all_but_first_by(1)} - pub ${mangle_ident(pn)}: ${to_rust_type(s.id, pn, p)}, + pub ${mangle_ident(pn)}: ${to_rust_type(schemas, s.id, pn, p)}, % endfor } % else: ## it's an empty struct, i.e. struct Foo; @@ -35,7 +35,7 @@ ${doc(s, c)}\ ${_new_object(s, s.get('properties'), c)}\ % elif s.type == 'array': % if s.items.get('type') != 'object': -pub struct ${s.id}(${to_rust_type(s.id, NESTED_TYPE_SUFFIX, s)}); +pub struct ${s.id}(${to_rust_type(schemas, s.id, NESTED_TYPE_SUFFIX, s)}); % else: ${_new_object(s, s.items.get('properties'), c)}\ % endif ## array item != 'object' @@ -57,7 +57,7 @@ impl ${s.id} { % for pn, p in s.properties.iteritems(): <% mn = 'self.' + mangle_ident(pn) - rt = to_rust_type(s.id, pn, p) + rt = to_rust_type(schemas, s.id, pn, p) check = 'is_some()' if rt.startswith('Vec') or rt.startswith('HashMap'): check = 'len() > 0' @@ -92,6 +92,6 @@ This type is not used in any activity, and only used as *part* of another schema % if s.type != 'object': ## for some reason, it's not shown in rustdoc ... -The contained type is `${to_rust_type(s.id, s.id, s)}`. +The contained type is `${to_rust_type(schemas, s.id, s.id, s)}`. %endif \ No newline at end of file diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index 302c436b520..48353370563 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -263,12 +263,18 @@ def mangle_ident(n): def _is_map_prop(p): return 'additionalProperties' in p +def _assure_unique_type_name(schemas, tn): + if tn in schemas: + tn += 'Internal' + assert tn not in schemas + return tn + # 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 to_rust_type(schemas, sn, pn, t, allow_optionals=True): def nested_type(nt): if 'items' in nt: nt = nt.items @@ -277,8 +283,8 @@ def nested_type(nt): else: assert(is_nested_type_property(nt)) # It's a nested type - we take it literally like $ref, but generate a name for the type ourselves - return nested_type_name(sn, pn) - return to_rust_type(sn, pn, nt, allow_optionals=False) + return _assure_unique_type_name(schemas, nested_type_name(sn, pn)) + return to_rust_type(schemas, sn, pn, nt, allow_optionals=False) def wrap_type(tn): if allow_optionals: @@ -323,10 +329,10 @@ def is_nested_type(s): # convert a rust-type to something that would be taken as input of a function # even though our storage type is different -def activity_input_type(p): +def activity_input_type(schemas, p): if 'input_type' in p: return p.input_type - n = activity_rust_type(p, allow_optionals=False) + n = activity_rust_type(schemas, p, allow_optionals=False) if n == 'String': n = 'str' # pods are copied anyway @@ -370,6 +376,7 @@ def iter_nested_properties(prefix, properties): if 'properties' not in s: continue for np in iter_nested_properties(s.id, s.properties): + np.id = _assure_unique_type_name(schemas, np.id) yield np # end for aech schma @@ -409,8 +416,8 @@ def activity_split(fqan): return t[0], t[1], '.'.join(t[2:]) # Shorthand to get a type from parameters of activities -def activity_rust_type(p, allow_optionals=True): - return to_rust_type(None, p.name, p, allow_optionals=allow_optionals) +def activity_rust_type(schemas, p, allow_optionals=True): + return to_rust_type(schemas, None, p.name, p, allow_optionals=allow_optionals) # the inverse of activity-split, but needs to know the 'name' of the API def to_fqan(name, resource, method): @@ -563,7 +570,7 @@ def build_all_params(schemas, c, m, n, npn): Context = collections.namedtuple('Context', ['sta_map', 'fqan_map', 'rta_map', 'rtc_map']) # return a newly build context from the given data -def new_context(resources): +def new_context(schemas, resources): if not resources: return Context(dict(), dict(), dict(), dict()) # Returns (A, B) where @@ -587,7 +594,7 @@ def build_activity_mappings(activities, res = None, fqan = None): t = m.get(in_out_type_name, None) if t is None: continue - tn = to_rust_type(None, None, t, allow_optionals=False) + tn = to_rust_type(schemas, None, None, t, allow_optionals=False) info = res.setdefault(tn, dict()) io_info = info.setdefault(m.id, []) io_info.append(in_out_type_name)