Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/to_typescript/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,23 @@ pub fn process_fields<'a>(

// Check if the field has the serde flatten attribute, if so, skip it
let has_flatten_attr = utils::get_attribute_arg("serde", "flatten", &field.attrs).is_some();
if has_flatten_attr {
let serde_skip = utils::get_attribute_arg("serde", "skip", &field.attrs).is_some();
let serde_rename = utils::get_attribute_arg("serde", "rename", &field.attrs);
if has_flatten_attr || serde_skip {
continue;
}

let comments = utils::get_comments(field.attrs);

state.write_comments(&comments, 2);
let field_name = if let Some(name_case) = case {

let field_name = if let Some(field_name) = serde_rename {
if field_name.contains(" ") {
format!("\"{field_name}\"")
} else {
field_name
}
} else if let Some(name_case) = case {
field
.ident
.map(|id| id.unraw().to_string().to_case(name_case))
Expand Down
8 changes: 8 additions & 0 deletions test/issue-42-serde-rename/rust.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[tsync]
struct TestThingey {
#[serde(rename = "im_correct ")]
not_me: String,
how_bout_me: String,
#[serde(skip)]
skip_me: SuperSecretStructThatsInternal,
}
8 changes: 8 additions & 0 deletions test/issue-42-serde-rename/tsync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

cd $SCRIPT_DIR

cargo run -- -i rust.rs -o typescript.d.ts
cargo run -- -i rust.rs -o typescript.ts
6 changes: 6 additions & 0 deletions test/issue-42-serde-rename/typescript.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* This file is generated and managed by tsync */

interface TestThingey {
"im_correct ": string;
how_bout_me: string;
}
6 changes: 6 additions & 0 deletions test/issue-42-serde-rename/typescript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* This file is generated and managed by tsync */

export interface TestThingey {
"im_correct ": string;
how_bout_me: string;
}
1 change: 1 addition & 0 deletions test/test_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ cd $SCRIPT_DIR
./enum_numeric/tsync.sh
./doc_comments/tsync.sh
./generic/tsync.sh
./issue-42-serde-rename/tsync.sh
./issue-43/tsync.sh
./issue-55/tsync.sh
./issue-58/tsync.sh
Expand Down