From ca6149b0edd64a5cc9d684805d554a479d0f5767 Mon Sep 17 00:00:00 2001 From: Mingwei Samuel Date: Wed, 13 Mar 2024 14:46:10 -0700 Subject: [PATCH] fix: codgen handle field name collisions --- riven/srcgen/models.rs.dt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/riven/srcgen/models.rs.dt b/riven/srcgen/models.rs.dt index 77f756b..76a1291 100644 --- a/riven/srcgen/models.rs.dt +++ b/riven/srcgen/models.rs.dt @@ -49,10 +49,16 @@ pub mod {{= dotUtils.changeCase.snakeCase(endpoint) }} { #[cfg_attr(feature = "deny-unknown-fields", serde(deny_unknown_fields))] pub struct {{= schemaName }} { {{ + const usedNames = new Set(); for (let [ propKey, prop ] of Object.entries(props)) { - const name = dotUtils.normalizePropName(propKey); const optional = !requiredSet.has(propKey); + + let name = dotUtils.normalizePropName(propKey); + while (usedNames.has(name)) { + name += '_'; + } + usedNames.add(name); }} {{? prop.description }} /// {{= prop.description.split('\n').map(x => x.trim()).join('
\r\n /// ') }}