forked from mirror/Riven
60 lines
No EOL
1.9 KiB
Text
60 lines
No EOL
1.9 KiB
Text
{{
|
|
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 data transfer structs.
|
|
|
|
{{
|
|
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) {
|
|
}}
|
|
/// {{= dotUtils.changeCase.pascalCase(endpoint) }} data objects. This module is automatically generated.
|
|
#[allow(dead_code)]
|
|
pub mod {{= dotUtils.changeCase.snakeCase(endpoint) }} {
|
|
{{
|
|
for (let schemaKey of schemaKeyGroup) {
|
|
const [, rawSchemaName] = schemaKey.split('.');
|
|
const schemaName = dotUtils.normalizeSchemaName(rawSchemaName);
|
|
const schema = schemas[schemaKey];
|
|
const props = schema.properties;
|
|
const requiredSet = new Set(schema.required);
|
|
}}
|
|
/// {{= schemaName }} data object. This struct is automatically generated.
|
|
{{? schema.description }}
|
|
/// # Description
|
|
/// {{= schema.description }}
|
|
{{?}}
|
|
#[derive(Debug)]
|
|
#[derive(serde::Serialize, serde::Deserialize)]
|
|
pub struct {{= schemaName }} {
|
|
{{
|
|
for (let [ propKey, prop ] of Object.entries(props))
|
|
{
|
|
const name = dotUtils.normalizePropName(propKey);
|
|
const required = requiredSet.has(propKey);
|
|
}}
|
|
{{? prop.description }}
|
|
/// {{= prop.description.split('\n').map(x => x.trim()).join('<br>\r\n /// ') }}
|
|
{{?}}
|
|
{{= dotUtils.formatJsonProperty(propKey) }}
|
|
pub {{= name }}: {{= dotUtils.stringifyType(prop, { optional: !required }) }},
|
|
{{
|
|
}
|
|
}}
|
|
}
|
|
{{
|
|
}
|
|
}}
|
|
}
|
|
|
|
{{
|
|
}
|
|
}} |