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

73 lines
2.2 KiB
Plaintext

{{
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(Clone, 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) }}
{{? !required }}
#[serde(skip_serializing_if = "Option::is_none")]
{{?}}
pub {{= name }}: {{= dotUtils.stringifyType(prop, { optional: !required }) }},
{{
}
}}
}
{{
}
}}
}
{{
}
}}