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

70 lines
2.2 KiB
Plaintext
Raw Permalink Normal View History

2021-01-16 22:16:56 +00:00
{{
const spec = require('./.spec.json');
const dotUtils = require('./dotUtils.js');
}}{{= dotUtils.preamble() }}
// http://www.mingweisamuel.com/riotapi-schema/tool/
// Version {{= spec.info.version }}
//! Data transfer structs.
//!
//! Separated into separate modules for each endpoint.
//! Several modules contain structs with the same name, so be sure to use the right ones.
//!
//! Note: these modules are automatically generated.
{{
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) {
const endpoint_pascal_case = dotUtils.changeCase.pascalCase(endpoint);
}}
/// Data structs used by [`{{= endpoint_pascal_case }}`](crate::endpoints::{{= endpoint_pascal_case }}).
///
/// Note: 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.
{{? schema.description }}
/// # Description
/// {{= schema.description }}
///
/// Note: This struct is automatically generated
{{?}}
#[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 }) }},
{{
}
}}
}
{{
}
}}
}
{{
}
2019-10-19 09:25:09 +00:00
}}