feat: update codegen to consider model new `x-alias` field

pull/67/head
Mingwei Samuel 2024-03-20 16:47:43 -07:00
parent 3d408d99ba
commit c00c8abace
2 changed files with 7 additions and 3 deletions

View File

@ -97,8 +97,12 @@ function stringifyType(prop, { endpoint = null, optional = false, fullpath = tru
}
}
function formatJsonProperty(name) {
return `#[serde(rename = "${name}")]`;
function formatJsonProperty(name, prop) {
const alias = prop['x-alias'];
if (alias)
return `#[serde(rename = ${JSON.stringify(name)}, alias = ${JSON.stringify(alias)})]`;
else
return `#[serde(rename = ${JSON.stringify(name)})]`;
}
function formatAddQueryParam(param) {

View File

@ -63,7 +63,7 @@ pub mod {{= dotUtils.changeCase.snakeCase(endpoint) }} {
{{? prop.description }}
/// {{= prop.description.split('\n').map(x => x.trim()).join('<br>\r\n /// ') }}
{{?}}
{{= dotUtils.formatJsonProperty(propKey) }}
{{= dotUtils.formatJsonProperty(propKey, prop) }}
{{? optional }}
#[serde(skip_serializing_if = "Option::is_none")]
{{?}}