mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-02-23 15:49:49 +01:00
restructure templates to use modules, so it's not just one big file
This commit is contained in:
@@ -20,7 +20,17 @@ make:
|
||||
- source: ../Cargo.toml
|
||||
- source: lib.rs
|
||||
output_dir: src
|
||||
- source: api.rs
|
||||
- source: api/mod.rs
|
||||
output_dir: src
|
||||
- source: api/utilities.rs
|
||||
output_dir: src
|
||||
- source: api/hub.rs
|
||||
output_dir: src
|
||||
- source: api/method_builders.rs
|
||||
output_dir: src
|
||||
- source: api/schemas.rs
|
||||
output_dir: src
|
||||
- source: api/call_builders.rs
|
||||
output_dir: src
|
||||
cargo:
|
||||
keywords: [protocol, web, api]
|
||||
|
||||
24
src/generator/templates/api/api/call_builders.rs.mako
Normal file
24
src/generator/templates/api/api/call_builders.rs.mako
Normal file
@@ -0,0 +1,24 @@
|
||||
<%namespace name="lib" file="../lib/lib.mako"/>\
|
||||
<%namespace name="util" file="../../../lib/util.mako"/>\
|
||||
<%namespace name="rbuild" file="../lib/rbuild.mako"/>\
|
||||
<%namespace name="mbuild" file="../lib/mbuild.mako"/>\
|
||||
<%namespace name="schema" file="../lib/schema.mako"/>\
|
||||
<%
|
||||
from generator.lib.util import (new_context, rust_comment, rust_doc_comment, rust_module_doc_comment,
|
||||
rb_type, hub_type, mangle_ident, hub_type_params_s,
|
||||
rb_type_params_s, find_fattest_resource, HUB_TYPE_PARAMETERS, METHODS_RESOURCE,
|
||||
UNUSED_TYPE_MARKER, schema_markers)
|
||||
|
||||
c = new_context(schemas, resources)
|
||||
hub_type = hub_type(c.schemas, util.canonical_name())
|
||||
ht_params = hub_type_params_s()
|
||||
|
||||
default_user_agent = "google-api-rust-client/" + cargo.build_version
|
||||
%>\
|
||||
use super::*;
|
||||
% for resource, methods in c.rta_map.items():
|
||||
% for method in methods:
|
||||
${mbuild.new(resource, method, c)}
|
||||
|
||||
% endfor ## method in methods
|
||||
% endfor ## resource, methods
|
||||
@@ -1,8 +1,8 @@
|
||||
<%namespace name="lib" file="lib/lib.mako"/>\
|
||||
<%namespace name="util" file="../../lib/util.mako"/>\
|
||||
<%namespace name="rbuild" file="lib/rbuild.mako"/>\
|
||||
<%namespace name="mbuild" file="lib/mbuild.mako"/>\
|
||||
<%namespace name="schema" file="lib/schema.mako"/>\
|
||||
<%namespace name="lib" file="../lib/lib.mako"/>\
|
||||
<%namespace name="util" file="../../../lib/util.mako"/>\
|
||||
<%namespace name="rbuild" file="../lib/rbuild.mako"/>\
|
||||
<%namespace name="mbuild" file="../lib/mbuild.mako"/>\
|
||||
<%namespace name="schema" file="../lib/schema.mako"/>\
|
||||
<%
|
||||
from generator.lib.util import (new_context, rust_comment, rust_doc_comment, rust_module_doc_comment,
|
||||
rb_type, hub_type, mangle_ident, hub_type_params_s,
|
||||
@@ -15,34 +15,7 @@
|
||||
|
||||
default_user_agent = "google-api-rust-client/" + cargo.build_version
|
||||
%>\
|
||||
use std::collections::HashMap;
|
||||
use std::cell::RefCell;
|
||||
use std::default::Default;
|
||||
use std::collections::BTreeSet;
|
||||
use std::error::Error as StdError;
|
||||
use serde_json as json;
|
||||
use std::io;
|
||||
use std::fs;
|
||||
use std::mem;
|
||||
|
||||
use hyper::client::connect;
|
||||
use tokio::io::{AsyncRead, AsyncWrite};
|
||||
use tokio::time::sleep;
|
||||
use tower_service;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use crate::{client, client::GetToken, client::serde_with};
|
||||
|
||||
// ##############
|
||||
// UTILITIES ###
|
||||
// ############
|
||||
|
||||
${lib.scope_enum()}
|
||||
|
||||
|
||||
// ########
|
||||
// HUB ###
|
||||
// ######
|
||||
use super::*;
|
||||
|
||||
/// Central instance to access all ${hub_type} related resource activities
|
||||
///
|
||||
@@ -57,9 +30,9 @@ ${lib.hub_usage_example(c)}\
|
||||
pub struct ${hub_type}${ht_params} {
|
||||
pub client: hyper::Client<S, hyper::body::Body>,
|
||||
pub auth: Box<dyn client::GetToken>,
|
||||
_user_agent: String,
|
||||
_base_url: String,
|
||||
_root_url: String,
|
||||
pub(super) _user_agent: String,
|
||||
pub(super) _base_url: String,
|
||||
pub(super) _root_url: String,
|
||||
}
|
||||
|
||||
impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> client::Hub for ${hub_type}${ht_params} {}
|
||||
@@ -106,37 +79,3 @@ impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> ${hub_type}${ht_params} {
|
||||
mem::replace(&mut self._root_url, new_root_url)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
% if c.schemas:
|
||||
// ############
|
||||
// SCHEMAS ###
|
||||
// ##########
|
||||
% for s in c.schemas.values():
|
||||
% if UNUSED_TYPE_MARKER not in schema_markers(s, c, transitive=True):
|
||||
${schema.new(s, c)}
|
||||
% endif
|
||||
% endfor
|
||||
% endif
|
||||
|
||||
// ###################
|
||||
// MethodBuilders ###
|
||||
// #################
|
||||
|
||||
% for resource in c.rta_map:
|
||||
${rbuild.new(resource, c)}
|
||||
|
||||
|
||||
% endfor
|
||||
|
||||
|
||||
// ###################
|
||||
// CallBuilders ###
|
||||
// #################
|
||||
|
||||
% for resource, methods in c.rta_map.items():
|
||||
% for method in methods:
|
||||
${mbuild.new(resource, method, c)}
|
||||
|
||||
% endfor ## method in methods
|
||||
% endfor ## resource, methods
|
||||
23
src/generator/templates/api/api/method_builders.rs.mako
Normal file
23
src/generator/templates/api/api/method_builders.rs.mako
Normal file
@@ -0,0 +1,23 @@
|
||||
<%namespace name="lib" file="../lib/lib.mako"/>\
|
||||
<%namespace name="util" file="../../../lib/util.mako"/>\
|
||||
<%namespace name="rbuild" file="../lib/rbuild.mako"/>\
|
||||
<%namespace name="mbuild" file="../lib/mbuild.mako"/>\
|
||||
<%namespace name="schema" file="../lib/schema.mako"/>\
|
||||
<%
|
||||
from generator.lib.util import (new_context, rust_comment, rust_doc_comment, rust_module_doc_comment,
|
||||
rb_type, hub_type, mangle_ident, hub_type_params_s,
|
||||
rb_type_params_s, find_fattest_resource, HUB_TYPE_PARAMETERS, METHODS_RESOURCE,
|
||||
UNUSED_TYPE_MARKER, schema_markers)
|
||||
|
||||
c = new_context(schemas, resources)
|
||||
hub_type = hub_type(c.schemas, util.canonical_name())
|
||||
ht_params = hub_type_params_s()
|
||||
|
||||
default_user_agent = "google-api-rust-client/" + cargo.build_version
|
||||
%>\
|
||||
use super::*;
|
||||
% for resource in c.rta_map:
|
||||
${rbuild.new(resource, c)}
|
||||
|
||||
|
||||
% endfor
|
||||
51
src/generator/templates/api/api/mod.rs.mako
Normal file
51
src/generator/templates/api/api/mod.rs.mako
Normal file
@@ -0,0 +1,51 @@
|
||||
<%namespace name="lib" file="../lib/lib.mako"/>\
|
||||
<%namespace name="util" file="../../../lib/util.mako"/>\
|
||||
<%namespace name="rbuild" file="../lib/rbuild.mako"/>\
|
||||
<%namespace name="mbuild" file="../lib/mbuild.mako"/>\
|
||||
<%namespace name="schema" file="../lib/schema.mako"/>\
|
||||
<%
|
||||
from generator.lib.util import (new_context, rust_comment, rust_doc_comment, rust_module_doc_comment,
|
||||
rb_type, hub_type, mangle_ident, hub_type_params_s,
|
||||
rb_type_params_s, find_fattest_resource, HUB_TYPE_PARAMETERS, METHODS_RESOURCE,
|
||||
UNUSED_TYPE_MARKER, schema_markers)
|
||||
|
||||
c = new_context(schemas, resources)
|
||||
hub_type = hub_type(c.schemas, util.canonical_name())
|
||||
ht_params = hub_type_params_s()
|
||||
|
||||
default_user_agent = "google-api-rust-client/" + cargo.build_version
|
||||
%>\
|
||||
use std::collections::HashMap;
|
||||
use std::cell::RefCell;
|
||||
use std::default::Default;
|
||||
use std::collections::BTreeSet;
|
||||
use std::error::Error as StdError;
|
||||
use serde_json as json;
|
||||
use std::io;
|
||||
use std::fs;
|
||||
use std::mem;
|
||||
|
||||
use hyper::client::connect;
|
||||
use tokio::io::{AsyncRead, AsyncWrite};
|
||||
use tokio::time::sleep;
|
||||
use tower_service;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use crate::{client, client::GetToken, client::serde_with};
|
||||
|
||||
mod utilities;
|
||||
pub use utilities::*;
|
||||
|
||||
mod hub;
|
||||
pub use hub::*;
|
||||
|
||||
% if c.schemas:
|
||||
mod schemas;
|
||||
pub use schemas::*;
|
||||
% endif
|
||||
|
||||
mod method_builders;
|
||||
pub use method_builders::*;
|
||||
|
||||
mod call_builders;
|
||||
pub use call_builders::*;
|
||||
23
src/generator/templates/api/api/schemas.rs.mako
Normal file
23
src/generator/templates/api/api/schemas.rs.mako
Normal file
@@ -0,0 +1,23 @@
|
||||
<%namespace name="lib" file="../lib/lib.mako"/>\
|
||||
<%namespace name="util" file="../../../lib/util.mako"/>\
|
||||
<%namespace name="rbuild" file="../lib/rbuild.mako"/>\
|
||||
<%namespace name="mbuild" file="../lib/mbuild.mako"/>\
|
||||
<%namespace name="schema" file="../lib/schema.mako"/>\
|
||||
<%
|
||||
from generator.lib.util import (new_context, rust_comment, rust_doc_comment, rust_module_doc_comment,
|
||||
rb_type, hub_type, mangle_ident, hub_type_params_s,
|
||||
rb_type_params_s, find_fattest_resource, HUB_TYPE_PARAMETERS, METHODS_RESOURCE,
|
||||
UNUSED_TYPE_MARKER, schema_markers)
|
||||
|
||||
c = new_context(schemas, resources)
|
||||
hub_type = hub_type(c.schemas, util.canonical_name())
|
||||
ht_params = hub_type_params_s()
|
||||
|
||||
default_user_agent = "google-api-rust-client/" + cargo.build_version
|
||||
%>\
|
||||
use super::*;
|
||||
% for s in c.schemas.values():
|
||||
% if UNUSED_TYPE_MARKER not in schema_markers(s, c, transitive=True):
|
||||
${schema.new(s, c)}
|
||||
% endif
|
||||
% endfor
|
||||
19
src/generator/templates/api/api/utilities.rs.mako
Normal file
19
src/generator/templates/api/api/utilities.rs.mako
Normal file
@@ -0,0 +1,19 @@
|
||||
<%namespace name="lib" file="../lib/lib.mako"/>\
|
||||
<%namespace name="util" file="../../../lib/util.mako"/>\
|
||||
<%namespace name="rbuild" file="../lib/rbuild.mako"/>\
|
||||
<%namespace name="mbuild" file="../lib/mbuild.mako"/>\
|
||||
<%namespace name="schema" file="../lib/schema.mako"/>\
|
||||
<%
|
||||
from generator.lib.util import (new_context, rust_comment, rust_doc_comment, rust_module_doc_comment,
|
||||
rb_type, hub_type, mangle_ident, hub_type_params_s,
|
||||
rb_type_params_s, find_fattest_resource, HUB_TYPE_PARAMETERS, METHODS_RESOURCE,
|
||||
UNUSED_TYPE_MARKER, schema_markers)
|
||||
|
||||
c = new_context(schemas, resources)
|
||||
hub_type = hub_type(c.schemas, util.canonical_name())
|
||||
ht_params = hub_type_params_s()
|
||||
|
||||
default_user_agent = "google-api-rust-client/" + cargo.build_version
|
||||
%>\
|
||||
use super::*;
|
||||
${lib.scope_enum()}
|
||||
@@ -120,10 +120,10 @@ ${self.usage(resource, method, m, params, request_value, parts)}\
|
||||
pub struct ${ThisType}
|
||||
where ${struct_type_bounds_s()} {
|
||||
|
||||
hub: &'a ${hub_type_name}${hub_type_params_s()},
|
||||
pub(super) hub: &'a ${hub_type_name}${hub_type_params_s()},
|
||||
## PROPERTIES ###############
|
||||
% for p in params:
|
||||
${property(p.name)}:\
|
||||
pub(super) ${property(p.name)}:\
|
||||
% if is_required_property(p):
|
||||
${activity_rust_type(schemas, p, allow_optionals=False)},
|
||||
% else:
|
||||
@@ -131,10 +131,10 @@ pub struct ${ThisType}
|
||||
% endif
|
||||
% endfor
|
||||
## A generic map for additinal parameters. Sometimes you can set some that are documented online only
|
||||
${api.properties.params}: HashMap<String, String>,
|
||||
pub(super) ${api.properties.params}: HashMap<String, String>,
|
||||
% if method_default_scope(m):
|
||||
## We need the scopes sorted, to not unnecessarily query new tokens
|
||||
${api.properties.scopes}: BTreeSet<String>
|
||||
pub(super) ${api.properties.scopes}: BTreeSet<String>
|
||||
% endif
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ let rb = hub.${mangle_ident(resource)}();
|
||||
pub struct ${ThisType}
|
||||
where ${struct_type_bounds_s()} {
|
||||
|
||||
hub: &'a ${hub_type_name}${hub_type_params_s()},
|
||||
pub(super) hub: &'a ${hub_type_name}${hub_type_params_s()},
|
||||
}
|
||||
|
||||
impl${rb_params} ${METHODS_BUILDER_MARKER_TRAIT} for ${ThisType} {}
|
||||
|
||||
Reference in New Issue
Block a user