mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-01-06 11:34:34 +01:00
refactor(rbuild): methods useful for mbuild as too
It's vital to be able to traverse parameters easily and consistently :)
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
rb_type, mb_type, singular, hub_type, to_fqan, indent_all_but_first_by,
|
||||
method_params, activity_rust_type, mangle_ident, activity_input_type, get_word,
|
||||
split_camelcase_s, property, is_pod_property, TREF, method_io, IO_REQUEST,
|
||||
schema_to_required_property, rust_copy_value_s, is_required_property)
|
||||
schema_to_required_property, rust_copy_value_s, is_required_property,
|
||||
hash_comment, build_all_params, REQUEST_VALUE_PROPERTY_NAME)
|
||||
%>\
|
||||
<%namespace name="util" file="util.mako"/>\
|
||||
<%namespace name="lib" file="lib.mako"/>\
|
||||
@@ -18,10 +19,7 @@
|
||||
# an identifier for a property. We prefix them to prevent clashes with the setters
|
||||
ThisType = mb_type(resource, method) + "<'a, C, NC, A>"
|
||||
|
||||
request_resource = method_io(schemas, c, m, IO_REQUEST)
|
||||
params = method_params(m)
|
||||
if request_resource:
|
||||
params.insert(0, schema_to_required_property(request_resource, 'request'))
|
||||
params, request_value = build_all_params(schemas, c, m, IO_REQUEST, REQUEST_VALUE_PROPERTY_NAME)
|
||||
%>\
|
||||
% if 'description' in m:
|
||||
${m.description | rust_doc_comment}
|
||||
@@ -35,14 +33,14 @@ ${m.description | rust_doc_comment}
|
||||
/// Instantiate a resource method builder
|
||||
///
|
||||
<%block filter="rust_doc_test_norun, rust_doc_comment">\
|
||||
${util.test_prelude()}\
|
||||
${capture(util.test_prelude) | hash_comment}\
|
||||
|
||||
<%block filter="rust_test_fn_invisible">\
|
||||
${lib.test_hub(hub_type_name, comments=False)}\
|
||||
${capture(lib.test_hub, hub_type_name, comments=False) | hash_comment}\
|
||||
|
||||
// Usually you wouldn't bind this to a variable, but keep calling methods
|
||||
// to setup your call.
|
||||
// TODO: figoure out actual arguments ...
|
||||
## % for p
|
||||
// let mb = hub.${resource}().${mangle_ident(method)}(...);
|
||||
|
||||
// Finally, execute your call and process the result
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
rb_type, singular, hub_type, mangle_ident, mb_type, method_params, property,
|
||||
to_fqan, indent_all_but_first_by, schema_markers,
|
||||
activity_input_type, TREF, method_io, IO_REQUEST, schema_to_required_property,
|
||||
rust_copy_value_s, is_required_property)
|
||||
rust_copy_value_s, is_required_property, organize_params, REQUEST_VALUE_PROPERTY_NAME,
|
||||
build_all_params)
|
||||
%>\
|
||||
<%namespace name="util" file="util.mako"/>\
|
||||
<%namespace name="lib" file="lib.mako"/>\
|
||||
@@ -54,26 +55,8 @@ impl<'a, C, NC, A> ${ThisType} {
|
||||
|
||||
# skip part if we have a request resource. Only resources can have parts
|
||||
# that we can easily deduce
|
||||
request_resource = method_io(schemas, c, m, IO_REQUEST)
|
||||
params = method_params(m)
|
||||
REQUEST_RESOURCE_PROPERTY_NAME = 'request'
|
||||
if request_resource:
|
||||
# resource into property
|
||||
resprop = schema_to_required_property(request_resource, REQUEST_RESOURCE_PROPERTY_NAME)
|
||||
params.insert(0, resprop)
|
||||
|
||||
part_prop = None
|
||||
optional_props = list()
|
||||
required_props = list()
|
||||
for p in params:
|
||||
if is_required_property(p):
|
||||
if request_resource and p.name == 'part':
|
||||
part_prop = p
|
||||
else:
|
||||
required_props.append(p)
|
||||
else:
|
||||
optional_props.append(p)
|
||||
# end for each property
|
||||
params, request_value = build_all_params(schemas, c, m, IO_REQUEST, REQUEST_VALUE_PROPERTY_NAME)
|
||||
required_props, optional_props, part_prop = organize_params(params, request_value)
|
||||
|
||||
method_args = ''
|
||||
if required_props:
|
||||
@@ -92,8 +75,8 @@ impl<'a, C, NC, A> ${ThisType} {
|
||||
${property(p.name)}: ${rust_copy_value_s(mangle_ident(p.name), activity_input_type(p), p)},
|
||||
% endfor
|
||||
## auto-generate parts from request resources
|
||||
% if part_prop and request_resource:
|
||||
${property(part_prop.name)}: ${mangle_ident(REQUEST_RESOURCE_PROPERTY_NAME)}.to_parts(),
|
||||
% if part_prop and request_value:
|
||||
${property(part_prop.name)}: ${mangle_ident(REQUEST_VALUE_PROPERTY_NAME)}.to_parts(),
|
||||
% endif
|
||||
% for p in optional_props:
|
||||
${property(p.name)}: Default::default(),
|
||||
|
||||
@@ -26,6 +26,7 @@ SPACES_PER_TAB = 4
|
||||
|
||||
REQUEST_PRIORITY = 100
|
||||
REQUEST_MARKER = 'RequestValue'
|
||||
REQUEST_VALUE_PROPERTY_NAME = 'request'
|
||||
|
||||
# ==============================================================================
|
||||
## @name Filters
|
||||
@@ -349,6 +350,32 @@ def schema_to_required_property(s, n):
|
||||
def is_required_property(p):
|
||||
return p.get('required', False) or p.get('priority', 0) > 0
|
||||
|
||||
# method_params(...), request_value|None -> (required_properties, optional_properties, part_prop|None)
|
||||
def organize_params(params, request_value):
|
||||
part_prop = None
|
||||
optional_props = list()
|
||||
required_props = list()
|
||||
for p in params:
|
||||
if is_required_property(p):
|
||||
if request_value and p.name == 'part':
|
||||
assert part_prop is None
|
||||
part_prop = p
|
||||
else:
|
||||
required_props.append(p)
|
||||
else:
|
||||
optional_props.append(p)
|
||||
# end for each property
|
||||
return required_props, optional_props, part_prop
|
||||
|
||||
# schemas, context, method(dict), 'request'|'response', request_prop_name -> (params, request_value|None)
|
||||
def build_all_params(schemas, c, m, n, npn):
|
||||
request_value = method_io(schemas, c, m, n)
|
||||
params = method_params(m)
|
||||
if request_value:
|
||||
params.insert(0, schema_to_required_property(request_value, npn))
|
||||
return params, request_value
|
||||
|
||||
|
||||
## -- End Activity Utilities -- @}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user