diff options
author | Cyborus <cyborus@cyborus.xyz> | 2024-04-26 18:55:32 +0200 |
---|---|---|
committer | Cyborus <cyborus@cyborus.xyz> | 2024-04-26 18:55:32 +0200 |
commit | a1000e31bf2231f82c652be9d72fa203a3452b73 (patch) | |
tree | f55b2f70efbf20c273a7c70cd591a329ca0a95a2 /generator | |
parent | strongly type repository default merge style in swagger file (diff) | |
download | forgejo-api-a1000e31bf2231f82c652be9d72fa203a3452b73.tar.xz forgejo-api-a1000e31bf2231f82c652be9d72fa203a3452b73.zip |
correctly generate field type names for referenced enums
Diffstat (limited to 'generator')
-rw-r--r-- | generator/src/main.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/generator/src/main.rs b/generator/src/main.rs index 64173bf..5d9d2c7 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -72,12 +72,21 @@ fn schema_type_name( match ty { SchemaType::One(prim) => { let name = match prim { - Primitive::String => match schema.format.as_deref() { + Primitive::String if schema._enum.is_none() => match schema.format.as_deref() { Some("date") => "time::Date", Some("date-time") => "time::OffsetDateTime", _ => "String", } .to_string(), + Primitive::String => { + match (&schema.title, definition_name) { + // Some of the titles are actually descriptions; not sure why + // Checking for a space filters that out + (Some(title), _) if !title.contains(' ') => title.to_string(), + (_, Some(definition_name)) => definition_name.to_string(), + (_, None) => "String".to_string(), + } + } Primitive::Number => match schema.format.as_deref() { Some("float") => "f32", Some("double") => "f64", |