feat(codegen): properly transform all property names which collide with

keywords
This commit is contained in:
pyrite 2025-07-10 17:53:44 +02:00
parent 485c2ea176
commit 3819ed1b7d
Signed by: pyrite
GPG key ID: 7F1BA9170CD35D15
3 changed files with 55 additions and 2 deletions

2
Cargo.lock generated
View file

@ -2316,7 +2316,7 @@ dependencies = [
[[package]]
name = "torn-api-codegen"
version = "0.7.0"
version = "0.7.1"
dependencies = [
"heck",
"indexmap",

View file

@ -1,7 +1,7 @@
[package]
name = "torn-api-codegen"
authors = ["Pyrit [2111649]"]
version = "0.7.0"
version = "0.7.1"
edition = "2021"
description = "Contains the v2 torn API model descriptions and codegen for the bindings"
license-file = { workspace = true }

View file

@ -273,7 +273,60 @@ impl Property {
let name = &self.name;
let (name, serde_attr) = match name.as_str() {
// https://doc.rust-lang.org/reference/keywords.html#r-lex.keywords
"as" => (format_ident!("r#as"), None),
"break" => (format_ident!("r#break"), None),
"const" => (format_ident!("r#const"), None),
"continue" => (format_ident!("r#continue"), None),
"crate" => (format_ident!("r#crate"), None),
"else" => (format_ident!("r#else"), None),
"enum" => (format_ident!("r#enum"), None),
"extern" => (format_ident!("r#extern"), None),
"false" => (format_ident!("r#false"), None),
"fn" => (format_ident!("r#fn"), None),
"for" => (format_ident!("r#for"), None),
"if" => (format_ident!("r#if"), None),
"impl" => (format_ident!("r#impl"), None),
"in" => (format_ident!("r#in"), None),
"let" => (format_ident!("r#let"), None),
"loop" => (format_ident!("r#loop"), None),
"match" => (format_ident!("r#match"), None),
"mod" => (format_ident!("r#mod"), None),
"move" => (format_ident!("r#move"), None),
"mut" => (format_ident!("r#mut"), None),
"pub" => (format_ident!("r#pub"), None),
"ref" => (format_ident!("r#ref"), None),
"return" => (format_ident!("r#return"), None),
"self" => (format_ident!("r#self"), None),
"Self" => (format_ident!("r#Self"), None),
"static" => (format_ident!("r#static"), None),
"struct" => (format_ident!("r#struct"), None),
"super" => (format_ident!("r#super"), None),
"trait" => (format_ident!("r#trait"), None),
"true" => (format_ident!("r#true"), None),
"type" => (format_ident!("r#type"), None),
"unsafe" => (format_ident!("r#unsafe"), None),
"use" => (format_ident!("r#use"), None),
"where" => (format_ident!("r#where"), None),
"while" => (format_ident!("r#while"), None),
"async" => (format_ident!("r#async"), None),
"await" => (format_ident!("r#await"), None),
"dyn" => (format_ident!("r#dyn"), None),
"abstract" => (format_ident!("r#abstract"), None),
"become" => (format_ident!("r#become"), None),
"box" => (format_ident!("r#box"), None),
"do" => (format_ident!("r#do"), None),
"final" => (format_ident!("r#final"), None),
"macro" => (format_ident!("r#macro"), None),
"override" => (format_ident!("r#override"), None),
"priv" => (format_ident!("r#priv"), None),
"typeof" => (format_ident!("r#typeof"), None),
"unsized" => (format_ident!("r#unsized"), None),
"virtual" => (format_ident!("r#virtual"), None),
"yield" => (format_ident!("r#yield"), None),
"try" => (format_ident!("r#try"), None),
"gen" => (format_ident!("r#gen"), None),
name if name != self.field_name => (
format_ident!("{}", self.field_name),
Some(quote! { #[serde(rename = #name)]}),