mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2025-12-26 17:02:24 +01:00
move scope_enum to own mako file
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<%namespace name="lib" file="../lib/lib.mako"/>\
|
||||
<%namespace name="enum" file="../lib/enum.mako"/>\
|
||||
<%namespace name="util" file="../../../lib/util.mako"/>\
|
||||
<%namespace name="rbuild" file="../lib/rbuild.mako"/>\
|
||||
<%namespace name="mbuild" file="../lib/mbuild.mako"/>\
|
||||
@@ -13,4 +14,4 @@
|
||||
default_user_agent = "google-api-rust-client/" + cargo.build_version
|
||||
%>\
|
||||
use super::*;
|
||||
${lib.scope_enum()}
|
||||
${enum.scope_enum()}
|
||||
|
||||
67
src/generator/templates/api/lib/enum.mako
Normal file
67
src/generator/templates/api/lib/enum.mako
Normal file
@@ -0,0 +1,67 @@
|
||||
<%!
|
||||
from generator.lib.util import (activity_split, put_and, md_italic, split_camelcase_s, canonical_type_name, hub_type,
|
||||
rust_test_fn_invisible, rust_doc_test_norun, rust_doc_comment, markdown_rust_block,
|
||||
unindent_first_by, mangle_ident, mb_type, singular, scope_url_to_variant,
|
||||
PART_MARKER_TRAIT, RESOURCE_MARKER_TRAIT, CALL_BUILDER_MARKERT_TRAIT,
|
||||
find_fattest_resource, build_all_params, pass_through, parts_from_params,
|
||||
REQUEST_MARKER_TRAIT, RESPONSE_MARKER_TRAIT, supports_scopes, to_api_version,
|
||||
to_fqan, METHODS_RESOURCE, ADD_PARAM_MEDIA_EXAMPLE, PROTOCOL_TYPE_INFO, enclose_in,
|
||||
upload_action_fn, METHODS_BUILDER_MARKER_TRAIT, DELEGATE_TYPE,
|
||||
to_extern_crate_name, rust_doc_sanitize)
|
||||
|
||||
def pretty_name(name):
|
||||
return ' '.join(split_camelcase_s(name).split('.'))
|
||||
%>\
|
||||
<%namespace name="util" file="../../../lib/util.mako"/>\
|
||||
<%namespace name="mbuild" file="mbuild.mako"/>\
|
||||
|
||||
|
||||
## Builds the scope-enum for the API
|
||||
## It's possible there is no scope enum if there is no auth information
|
||||
###############################################################################################
|
||||
###############################################################################################
|
||||
<%def name="scope_enum()">\
|
||||
% if not supports_scopes(auth):
|
||||
<% return '' %>\
|
||||
% endif
|
||||
/// Identifies the an OAuth2 authorization scope.
|
||||
/// A scope is needed when requesting an
|
||||
/// [authorization token](https://developers.google.com/youtube/v3/guides/authentication).
|
||||
#[derive(PartialEq, Eq, Hash, Debug, Clone)]
|
||||
pub enum Scope {
|
||||
% for url, scope in auth.oauth2.scopes.items():
|
||||
${scope.description | rust_doc_sanitize(documentationLink), rust_doc_comment}
|
||||
${scope_url_to_variant(name, url, fully_qualified=False)},
|
||||
% if not loop.last:
|
||||
|
||||
% endif
|
||||
% endfor
|
||||
}
|
||||
|
||||
impl AsRef<str> for Scope {
|
||||
fn as_ref(&self) -> &str {
|
||||
match *self {
|
||||
% for url in auth.oauth2.scopes.keys():
|
||||
${scope_url_to_variant(name, url)} => "${url}",
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Scope {
|
||||
fn default() -> Scope {
|
||||
<%
|
||||
default_url = None
|
||||
shortest_url = None
|
||||
for url in auth.oauth2.scopes.keys():
|
||||
if not default_url and 'readonly' in url:
|
||||
default_url = url
|
||||
if not shortest_url or len(shortest_url) > len(url):
|
||||
shortest_url = url
|
||||
# end for each url
|
||||
default_url = default_url or shortest_url
|
||||
%>\
|
||||
${scope_url_to_variant(name, default_url)}
|
||||
}
|
||||
}
|
||||
</%def>
|
||||
@@ -319,53 +319,3 @@ You can read the full text at the repository's [license file][repo-license].
|
||||
[repo-license]: ${cargo.repo_base_url + 'blob/main/LICENSE.md'}
|
||||
</%def>
|
||||
|
||||
|
||||
## Builds the scope-enum for the API
|
||||
## It's possible there is no scope enum if there is no auth information
|
||||
###############################################################################################
|
||||
###############################################################################################
|
||||
<%def name="scope_enum()">\
|
||||
% if not supports_scopes(auth):
|
||||
<% return '' %>\
|
||||
% endif
|
||||
/// Identifies the an OAuth2 authorization scope.
|
||||
/// A scope is needed when requesting an
|
||||
/// [authorization token](https://developers.google.com/youtube/v3/guides/authentication).
|
||||
#[derive(PartialEq, Eq, Ord, PartialOrd, Hash, Debug, Clone, Copy)]
|
||||
pub enum Scope {
|
||||
% for url, scope in auth.oauth2.scopes.items():
|
||||
${scope.description | rust_doc_sanitize(documentationLink), rust_doc_comment}
|
||||
${scope_url_to_variant(name, url, fully_qualified=False)},
|
||||
% if not loop.last:
|
||||
|
||||
% endif
|
||||
% endfor
|
||||
}
|
||||
|
||||
impl AsRef<str> for Scope {
|
||||
fn as_ref(&self) -> &str {
|
||||
match *self {
|
||||
% for url in auth.oauth2.scopes.keys():
|
||||
${scope_url_to_variant(name, url)} => "${url}",
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Scope {
|
||||
fn default() -> Scope {
|
||||
<%
|
||||
default_url = None
|
||||
shortest_url = None
|
||||
for url in auth.oauth2.scopes.keys():
|
||||
if not default_url and 'readonly' in url:
|
||||
default_url = url
|
||||
if not shortest_url or len(shortest_url) > len(url):
|
||||
shortest_url = url
|
||||
# end for each url
|
||||
default_url = default_url or shortest_url
|
||||
%>\
|
||||
${scope_url_to_variant(name, default_url)}
|
||||
}
|
||||
}
|
||||
</%def>
|
||||
|
||||
Reference in New Issue
Block a user