fix: codgen handle field name collisions

This commit is contained in:
Mingwei Samuel 2024-03-13 14:46:10 -07:00
parent 1ce54275ce
commit ca6149b0ed

View file

@ -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('<br>\r\n /// ') }}