{{ const spec = require('./.spec.json'); const dotUtils = require('./dotUtils.js'); }}{{= dotUtils.preamble() }} // http://www.mingweisamuel.com/riotapi-schema/tool/ // Version {{= spec.info.version }} //! Automatically generated endpoint handles. use crate::models::*; use std::future::Future; use std::vec::Vec; use reqwest::Method; use crate::Result; 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); } }} impl RiotApi { {{ for (const endpointName of Object.keys(endpointGroups)) { const method = dotUtils.changeCase.snakeCase(endpointName); const type = dotUtils.changeCase.pascalCase(endpointName); }} /// Returns a handle for accessing [{{= type }}](crate::endpoints::{{= type }}) endpoints. /// # Riot Developer API Reference /// `{{= endpointName }}` /// /// Note: this method is automatically generated. #[inline] pub fn {{= method }}(&self) -> {{= type }} { {{= type }} { base: self } } {{ } }} } {{ for (let [ endpointName, endpointMethods ] of Object.entries(endpointGroups)) { let endpoint = dotUtils.changeCase.pascalCase(endpointName); const endpoint_snake_case = dotUtils.changeCase.snakeCase(endpointName); }} /// {{= endpoint }} endpoints handle, accessed by calling [`{{= endpoint_snake_case }}()`](crate::RiotApi::{{= endpoint_snake_case }}) on a [`RiotApi`](crate::RiotApi) instance. /// # Riot Developer API Reference /// `{{= endpointName }}` /// /// Note: this struct is automatically generated. #[repr(transparent)] pub struct {{= endpoint }}<'a> { base: &'a RiotApi, } impl<'a> {{= endpoint }}<'a> { {{ for (let [ route, path ] of endpointMethods) { let get = path.get; if (!get) /* Only support GET parameters. */ continue; if ((get.parameters || []).some(p => 'header' === p.in)) /* Do not support header parameter methods. */ continue; let operationId = get.operationId; let method = dotUtils.changeCase.snakeCase(operationId.slice(operationId.indexOf('.') + 1)); let jsonInfo = get.responses['200'].content['application/json']; let returnOptional = !!get['x-nullable-404']; let parseType = dotUtils.stringifyType(jsonInfo.schema, { endpoint, fullpath: false }); let returnType = returnOptional ? `Option<${parseType}>` : parseType; /* Cases if not rate limited. */ let rateLimitExcluded = get['x-app-rate-limit-excluded'] ? true : false; /* Description processing. */ let descArr = get.description.split('\n'); /* Build argument comment & string. */ let argBuilder = []; let makeParamCode = ''; let allParams = get.parameters; let queryParams = []; let routeArgument; if (allParams && allParams.length) { let pathParams = allParams.filter(p => 'path' === p.in) .sortBy(({ name }) => route.indexOf(name)); let reqParams = allParams.filter(p => 'path' !== p.in && p.required); let optParams = allParams.filter(p => 'path' !== p.in && !p.required) .sortBy(({ name }) => { let match = /(^[a-z]+|[A-Z]+(?![a-z])|[A-Z][a-z]+)/.exec(name); 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), ': ', dotUtils.stringifyType(param.schema, { endpoint, optional: !required, owned: false })); } } routeArgument = dotUtils.formatRouteArgument(route, pathParams); } else { routeArgument = dotUtils.formatRouteArgument(route); } for (var descLine of descArr) { }} ///{{= descLine ? ' ' + descLine : '' }} {{ } }} /// # Parameters /// * `region` - Region to query. {{ if (allParams) { for (let param of allParams) { }} /// * `{{= param.name }}`{{= param.required ? '' : ' (optional)' }}{{= param.description ? ' - ' + param.description : ''}} {{ } } }} /// # Riot Developer API Reference /// `{{= operationId }}` /// /// Note: this method is automatically generated. pub fn {{= method }}(&self, region: Region{{= argBuilder.join('') }}) -> impl Future> + 'a { #[allow(unused_mut)] let mut request = self.base.request(Method::GET, region.into(), {{= routeArgument }}); {{ for (let queryParam of queryParams) { }} {{= dotUtils.formatAddQueryParam(queryParam) }}; {{ } }} self.base.execute{{= returnOptional ? '_optional' : '' }}::<{{= parseType }}>("{{= operationId }}", region.into(), request) } {{ } }} } {{ } }}