Skip to content

Commit cf7d85d

Browse files
committed
Fix go-gen acronym replacement
1 parent 1ad75ec commit cf7d85d

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

packages/go-gen/src/main.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn generate_go(root: RootSchema) -> Result<String> {
3737
for (name, additional_type) in &root.definitions {
3838
additional_type
3939
.object()
40-
.map(|def| build_type(&replace_acronyms(name), def, &mut types))
40+
.map(|def| build_type(name, def, &mut types))
4141
.and_then(|r| r)
4242
.context("failed to generate additional definitions")?;
4343
}
@@ -107,7 +107,7 @@ pub fn build_struct(
107107
let fields = fields.collect::<Result<Vec<_>>>()?;
108108

109109
Ok(GoStruct {
110-
name: to_pascal_case(name),
110+
name: replace_acronyms(to_pascal_case(name)),
111111
docs,
112112
fields,
113113
})
@@ -121,6 +121,7 @@ pub fn build_enum<'a>(
121121
variants: impl Iterator<Item = &'a Schema>,
122122
additional_structs: &mut Vec<GoStruct>,
123123
) -> Result<GoStruct> {
124+
let name = replace_acronyms(name);
124125
let docs = documentation(enm);
125126

126127
// go through all fields
@@ -131,18 +132,14 @@ pub fn build_enum<'a>(
131132
.with_context(|| format!("expected schema object for enum variants of {name}"))?;
132133

133134
// analyze the variant
134-
let variant_field = build_enum_variant(v, name, additional_structs)
135+
let variant_field = build_enum_variant(v, &name, additional_structs)
135136
.context("failed to extract enum variant")?;
136137

137138
anyhow::Ok(variant_field)
138139
});
139140
let fields = fields.collect::<Result<Vec<_>>>()?;
140141

141-
Ok(GoStruct {
142-
name: name.to_string(),
143-
docs,
144-
fields,
145-
})
142+
Ok(GoStruct { name, docs, fields })
146143
}
147144

148145
/// Tries to extract the name and type of the given enum variant and returns it as a `GoField`.

0 commit comments

Comments
 (0)