forked from mirror/Riven
1
0
Fork 0
Riven/srcgen/endpoints/dto.rs.dt

56 lines
1.6 KiB
Plaintext
Raw Normal View History

2019-10-19 09:25:09 +00:00
{{
const spec = require('./.spec.json');
const dotUtils = require('./dotUtils.js');
2019-10-23 07:49:02 +00:00
}}{{= dotUtils.preamble() }}
2019-10-19 09:25:09 +00:00
// http://www.mingweisamuel.com/riotapi-schema/tool/
// Version {{= spec.info.version }}
{{
let schemas = spec.components.schemas;
let schemaKeyByEndpoint = Object.keys(schemas)
.filter(schemaKey => 'Error' != schemaKey)
.groupBy(schemaKey => schemaKey.split('.')[0]);
for (let [endpoint, schemaKeyGroup] of schemaKeyByEndpoint) {
}}
// {{= endpoint }}
#[allow(dead_code)]
2019-10-19 21:39:53 +00:00
pub mod {{= dotUtils.changeCase.snakeCase(endpoint) }} {
2019-10-19 09:25:09 +00:00
{{
for (let schemaKey of schemaKeyGroup) {
let [endpoint, rawSchemaName] = schemaKey.split('.');
let schemaName = dotUtils.normalizeSchemaName(rawSchemaName);
let schema = schemas[schemaKey];
let props = schema.properties;
}}
2019-10-22 07:01:11 +00:00
/// {{= schemaName }} data object. This struct is automatically generated.
2019-10-19 09:25:09 +00:00
{{? schema.description }}
/// # Description
/// {{= schema.description }}
{{?}}
2019-10-19 21:39:53 +00:00
#[derive(Debug)]
#[derive(serde::Serialize, serde::Deserialize)]
2019-10-19 09:25:09 +00:00
pub struct {{= schemaName }} {
2019-10-19 21:39:53 +00:00
{{
for (let [ propKey, prop ] of Object.entries(props))
{
let name = dotUtils.normalizePropName(propKey, schemaName, prop);
}}
{{? prop.description }}
/// {{= prop.description.split('\n').map(x => x.trim()).join(' \r\n /// ') }}
{{?}}
{{= dotUtils.formatJsonProperty(propKey) }}
pub {{= name }}: {{= dotUtils.stringifyType(prop) }},
{{
}
}}
2019-10-19 09:25:09 +00:00
}
{{
}
}}
}
{{
}
}}