Comments (9)
The rename_all
fix was introduced in #122
from ts-rs.
It seems to be an issue with most serde field attributes, I get the same with #[serde(skip_serializing_if = "Option::is_none")]
, and there's a pull request for fixing the same issue for [serde(with = "...")]
: #146
from ts-rs.
This has already been fixed by #185, sorry I failed to include this issue in the PR before it was merged, I tried to add all issues about this, but I seem to have missed this one.
@ctison, if you see this, please close the issue as completed
from ts-rs.
As @escritorio-gustavo mentioned, the no-serde-warnings
feature can disable these warnings.
I think I'd still like to keep this issue open, in case we want to support serde's rename_all
in the future.
from ts-rs.
right now, it's sadly neccessary to rename each field individually with #[serde(rename = "..")]
or #[ts(rename = "..")]
from ts-rs.
My mistake, due to #165 I thought #[serde(rename_all = "..")]
was generally supported and this issue was just older than support for it, I didn't notice it didn't apply to enums
from ts-rs.
right now, it's sadly neccessary to rename each field individually with #[serde(rename = "..")] or #[ts(rename = "..")]
Hey @NyxCode... I have forked the repo to start working on a fix.
I wrote the following test:
use serde::{Serialize, Deserialize};
use ts_rs::TS;
/// Used enum from issue to test
#[derive(Serialize, Deserialize, TS, Clone)]
#[ts(export)]
#[serde(rename_all = "camelCase")]
pub enum TaskStatus {
#[serde(rename_all = "camelCase")]
Running { started_time: String }, // Changed to string because the `chrono` dependency doesn't include the `serde` flag
#[serde(rename_all = "camelCase")]
Terminated {
status: i32,
stdout: String,
stderr: String,
},
}
#[test]
pub fn enum_struct_variant() {
assert_eq!(TaskStatus::inline(), r#"{ "running": { startedTime: string, } } | { "terminated": { status: number, stdout: string, stderr: string, } }"#)
}
And the test is passing... Has the rename_all
been fixed in the time since this issue was opened in a forgotten commit or am I doing something wrong?
from ts-rs.
The format_field
function used to format enums containng structs does receive a rename_all
parameter
fn format_field(
formatted_fields: &mut Vec<TokenStream>,
dependencies: &mut Dependencies,
field: &Field,
rename_all: &Option<Inflection>,
generics: &Generics,
) -> Result<()>
from ts-rs.
@escritorio-gustavo Hey!
Thanks for testing that, it seems you're right!
Maybe I got tripped up by an inconsistency our camelCase implementation has with serde (I'll add an other issue for that), idk.
Since you've already got the test, could you make a PR for that?
from ts-rs.
Related Issues (20)
- bug: Using `#[ts(rename_all = "...")]` `snake_case`, `SCREAMING_SNAKE_CASE` and `kebab-case` is not compatible with serde
- Randomly failing `imports` test HOT 1
- Unqualified call to `Self::name()`
- `usize` and `isize` should be typed as `bigint` on 64-bit architectures HOT 6
- Feature request: `serde-wasm-bindgen` compatibility. HOT 5
- Feature request: How to export multiple types to the same file HOT 4
- Feature request: Typed array types HOT 3
- bug: Tuples cause imports to be missed HOT 5
- bug: files are missing final newlines
- bug: `export::path:absolute` function fails when `TS_RS_EXPORT_DIR` is set to an absolute path and the `path_bug` test is executed
- bug: TS generated tests fail on struct with `serde_json::Value` type when running `cargo test`. HOT 2
- `ts(optional)` should be working on any which has `skip_serializing_if` HOT 1
- Add all of `ts(function)` to docs. HOT 2
- publish release please HOT 5
- Use std::path::absolute HOT 2
- Feature request: allow method of including `[propName: string]: any` to type HOT 15
- Question to recent change `Records<K, V>` to `{ [key: K]: V }`
- `parse_docs` doesn't handle block doc comments properly
- bug: complex nested (and flattened) enum type produces invalid syntax HOT 1
- Dependency paths in Windows use back slash, though they should use the canonical forward slash HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ts-rs.