diff --git a/typegen/src/outform.rs b/typegen/src/outform.rs index a7910f6..641d64c 100644 --- a/typegen/src/outform.rs +++ b/typegen/src/outform.rs @@ -9,10 +9,18 @@ pub struct ModuleIndex { pub details: String, } +#[derive(Debug, Serialize)] +pub struct TypeInfo { + pub name: String, + pub module: String, + #[serde(flatten)] + pub details: TypeDetails, +} + #[derive(Debug, Serialize)] #[serde(rename_all = "lowercase")] #[serde(tag = "type")] -pub enum TypeInfo { +pub enum TypeDetails { Class(ClassInfo), Enum(EnumInfo), } diff --git a/typegen/src/resolver.rs b/typegen/src/resolver.rs index 8c2f609..984c582 100644 --- a/typegen/src/resolver.rs +++ b/typegen/src/resolver.rs @@ -211,37 +211,42 @@ pub fn resolve_types( None => HashMap::new(), }; - let type_ = outform::ClassInfo { - superclass, - description: class.description.clone(), - details: class.details.clone(), - flags: { - let mut flags = Vec::new(); + let type_ = outform::TypeInfo { + name: mapping.name.clone(), + module: mapping.module.clone().unwrap(), + details: outform::TypeDetails::Class(outform::ClassInfo { + superclass, + description: class.description.clone(), + details: class.details.clone(), + flags: { + let mut flags = Vec::new(); - if coreenum.is_some() { - flags.push(Flag::Enum); - } else if class.singleton { - flags.push(Flag::Singleton); - } else if class.uncreatable { - flags.push(Flag::Uncreatable); - } + if coreenum.is_some() { + flags.push(Flag::Enum); + } else if class.singleton { + flags.push(Flag::Singleton); + } else if class.uncreatable { + flags.push(Flag::Uncreatable); + } - flags - }, - properties, - functions, - signals, - variants, + flags + }, + properties, + functions, + signals, + variants, + }), }; - outtypes.insert(mapping.name.clone(), outform::TypeInfo::Class(type_)); + outtypes.insert(mapping.name.clone(), type_); } for enum_ in typespec.enums { if enum_.module.as_ref().map(|v| v as &str) == Some(module) { - outtypes.insert( - enum_.name, - outform::TypeInfo::Enum(outform::EnumInfo { + outtypes.insert(enum_.name.clone(), outform::TypeInfo { + name: enum_.name, + module: enum_.module.unwrap(), + details: outform::TypeDetails::Enum(outform::EnumInfo { description: enum_.description, details: enum_.details, variants: enum_ @@ -254,7 +259,7 @@ pub fn resolve_types( }) .collect(), }), - ); + }); } }