2019-10-19 14:39:53 -07:00
|
|
|
{{
|
|
|
|
const spec = require('./.spec.json');
|
|
|
|
const dotUtils = require('./dotUtils.js');
|
2019-10-23 00:49:02 -07:00
|
|
|
}}{{= dotUtils.preamble() }}
|
2019-10-19 14:39:53 -07:00
|
|
|
|
|
|
|
// http://www.mingweisamuel.com/riotapi-schema/tool/
|
|
|
|
// Version {{= spec.info.version }}
|
|
|
|
|
2019-11-03 10:48:45 -08:00
|
|
|
//! Automatically generated endpoint handles.
|
2019-10-23 00:39:40 -07:00
|
|
|
|
2019-11-03 10:48:45 -08:00
|
|
|
use crate::models::*;
|
2019-10-22 14:28:23 -07:00
|
|
|
|
2019-10-21 21:45:38 -07:00
|
|
|
use std::future::Future;
|
2019-10-19 14:39:53 -07:00
|
|
|
use std::vec::Vec;
|
|
|
|
|
|
|
|
use url::form_urlencoded::Serializer;
|
|
|
|
|
2019-10-22 19:33:15 -07:00
|
|
|
use crate::Result;
|
2019-10-19 14:39:53 -07:00
|
|
|
use crate::consts::Region;
|
|
|
|
use crate::riot_api::RiotApi;
|
|
|
|
|
|
|
|
{{
|
|
|
|
const endpointGroups = {};
|
|
|
|
for (let path of Object.entries(spec.paths)) {
|
|
|
|
let ep = path[1]['x-endpoint'];
|
|
|
|
endpointGroups[ep] = endpointGroups[ep] || [];
|
|
|
|
endpointGroups[ep].push(path);
|
|
|
|
}
|
2019-10-21 22:43:06 -07:00
|
|
|
}}
|
|
|
|
impl RiotApi {
|
|
|
|
{{
|
|
|
|
for (const endpointName of Object.keys(endpointGroups)) {
|
|
|
|
const method = dotUtils.changeCase.snakeCase(endpointName);
|
|
|
|
const type = dotUtils.changeCase.pascalCase(endpointName);
|
|
|
|
}}
|
2019-10-22 00:01:11 -07:00
|
|
|
/// Handle for {{= type }} endpoints. This method is automatically generated.
|
2019-10-27 12:15:22 -07:00
|
|
|
///
|
|
|
|
/// <a href="https://developer.riotgames.com/api-methods/#{{= endpointName }}">Official API Reference</a>
|
2019-10-22 00:01:11 -07:00
|
|
|
#[inline]
|
2019-10-21 22:43:06 -07:00
|
|
|
pub fn {{= method }}(&self) -> {{= type }} {
|
|
|
|
{{= type }} { base: self }
|
|
|
|
}
|
|
|
|
{{
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
{{
|
2019-10-19 14:39:53 -07:00
|
|
|
for (let [ endpointName, endpointMethods ] of Object.entries(endpointGroups)) {
|
|
|
|
let endpoint = dotUtils.changeCase.pascalCase(endpointName);
|
|
|
|
}}
|
|
|
|
|
2019-10-22 00:01:11 -07:00
|
|
|
/// {{= endpoint }} endpoints. This struct is automatically generated.
|
2019-10-27 12:15:22 -07:00
|
|
|
///
|
|
|
|
/// <a href="https://developer.riotgames.com/api-methods/#{{= endpointName }}">Official API Reference</a>
|
2019-10-21 22:43:06 -07:00
|
|
|
pub struct {{= endpoint }}<'a> {
|
|
|
|
base: &'a RiotApi,
|
|
|
|
}
|
|
|
|
impl<'a> {{= endpoint }}<'a> {
|
2019-10-19 14:39:53 -07:00
|
|
|
{{
|
|
|
|
for (let [ route, path ] of endpointMethods)
|
|
|
|
{
|
|
|
|
let get = path.get;
|
|
|
|
if (!get)
|
|
|
|
continue;
|
|
|
|
let operationId = get.operationId;
|
|
|
|
let method = dotUtils.changeCase.snakeCase(operationId.slice(operationId.indexOf('.') + 1));
|
|
|
|
|
|
|
|
let jsonInfo = get.responses['200'].content['application/json'];
|
2019-10-31 01:09:20 -07:00
|
|
|
let returnType = dotUtils.stringifyType(jsonInfo.schema, { endpoint, fullpath: false });
|
2019-10-19 14:39:53 -07:00
|
|
|
|
|
|
|
/* Cases if not rate limited. */
|
|
|
|
let rateLimitExcluded = get['x-app-rate-limit-excluded'] ? true : false;
|
|
|
|
|
|
|
|
/* Description processing. */
|
|
|
|
let desc = get.description;
|
|
|
|
let descArr = desc
|
|
|
|
.replace(/(#+)\s*([^\\]+)\\n(.*?)([\\n$])/g,
|
|
|
|
(m, g1, g2, g3, g4) => `<h${g1.length}>${g2}</h${g1.length}>\\n${g3}${g4}`)
|
|
|
|
.split('\n');
|
|
|
|
|
|
|
|
/* Build argument comment & string. */
|
|
|
|
let argBuilder = [];
|
|
|
|
let makeParamCode = '';
|
|
|
|
let allParams = get.parameters;
|
|
|
|
let queryParams = [];
|
|
|
|
let routeArgument = dotUtils.formatRouteArgument(route);
|
|
|
|
if (allParams && allParams.length)
|
|
|
|
{
|
|
|
|
let pathParams = allParams.filter(p => 'path' === p.in)
|
2019-10-31 01:09:20 -07:00
|
|
|
.sortBy(({ name }) => route.indexOf(name));
|
2019-10-19 14:39:53 -07:00
|
|
|
let reqParams = allParams.filter(p => 'path' !== p.in && p.required);
|
|
|
|
let optParams = allParams.filter(p => 'path' !== p.in && !p.required)
|
2019-10-31 01:09:20 -07:00
|
|
|
.sortBy(({ name }) => {
|
|
|
|
let match = /(^[a-z]+|[A-Z]+(?![a-z])|[A-Z][a-z]+)/.exec(name);
|
2019-10-19 14:39:53 -07:00
|
|
|
return match.slice(1).reverse().join('');
|
|
|
|
});
|
|
|
|
queryParams = reqParams.concat(optParams);
|
|
|
|
|
|
|
|
for (let paramList of [ pathParams, reqParams, optParams ])
|
|
|
|
{
|
|
|
|
let required = paramList === pathParams;
|
|
|
|
for (let param of paramList)
|
|
|
|
{
|
|
|
|
argBuilder.push(', ', dotUtils.changeCase.snakeCase(param.name), ': ',
|
2019-10-31 01:09:20 -07:00
|
|
|
dotUtils.stringifyType(param.schema, { endpoint, optional: !required, owned: false }));
|
2019-10-19 14:39:53 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
routeArgument = dotUtils.formatRouteArgument(route, pathParams);
|
|
|
|
}
|
|
|
|
for (var descLine of descArr)
|
|
|
|
{
|
|
|
|
}}
|
2019-10-29 15:25:53 -07:00
|
|
|
///{{= descLine ? ' ' + descLine : '' }}
|
2019-10-19 14:39:53 -07:00
|
|
|
{{
|
|
|
|
}
|
|
|
|
}}
|
2019-10-29 15:25:53 -07:00
|
|
|
///
|
|
|
|
/// <a href="{{= get.externalDocs.url }}">{{= get.externalDocs.description }}</a>
|
|
|
|
/// # Parameters
|
|
|
|
/// * `region` - Region to query.
|
2019-10-19 14:39:53 -07:00
|
|
|
{{
|
|
|
|
if (allParams)
|
|
|
|
{
|
|
|
|
for (let param of allParams)
|
|
|
|
{
|
|
|
|
}}
|
2019-10-29 15:25:53 -07:00
|
|
|
/// * `{{= param.name }}`{{= param.required ? '' : ' (optional)' }}{{= param.description ? ' - ' + param.description : ''}}
|
2019-10-19 14:39:53 -07:00
|
|
|
{{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}}
|
2019-10-29 15:25:53 -07:00
|
|
|
pub fn {{= method }}(&self, region: Region{{= argBuilder.join('') }})
|
|
|
|
-> impl Future<Output = Result<Option<{{= returnType }}>>> + 'a
|
|
|
|
{
|
2019-10-19 14:39:53 -07:00
|
|
|
{{? queryParams.length }}
|
2019-10-29 15:38:46 -07:00
|
|
|
let mut query_params = Serializer::new(String::new());
|
2019-10-19 14:39:53 -07:00
|
|
|
{{
|
|
|
|
for (let queryParam of queryParams)
|
|
|
|
{
|
|
|
|
}}
|
2019-10-29 15:25:53 -07:00
|
|
|
{{= dotUtils.formatAddQueryParam(queryParam) }};
|
2019-10-19 14:39:53 -07:00
|
|
|
{{
|
|
|
|
}
|
|
|
|
}}
|
2019-10-29 15:25:53 -07:00
|
|
|
let query_string = query_params.finish();
|
2019-10-19 14:39:53 -07:00
|
|
|
{{?}}
|
2019-10-29 15:25:53 -07:00
|
|
|
let path_string = {{= routeArgument }};
|
|
|
|
self.base.get::<{{= returnType }}>("{{= operationId }}", region, path_string, {{= queryParams.length ? 'Some(query_string)' : 'None' }})
|
|
|
|
}
|
2019-10-19 14:39:53 -07:00
|
|
|
|
|
|
|
{{
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
{{
|
|
|
|
}
|
|
|
|
}}
|