Giter Site home page Giter Site logo

Comments (9)

escritorio-gustavo avatar escritorio-gustavo commented on September 22, 2024 1

The rename_all fix was introduced in #122

from ts-rs.

linulas avatar linulas commented on September 22, 2024

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.

escritorio-gustavo avatar escritorio-gustavo commented on September 22, 2024

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.

NyxCode avatar NyxCode commented on September 22, 2024

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.

NyxCode avatar NyxCode commented on September 22, 2024

right now, it's sadly neccessary to rename each field individually with #[serde(rename = "..")] or #[ts(rename = "..")]

from ts-rs.

escritorio-gustavo avatar escritorio-gustavo commented on September 22, 2024

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.

escritorio-gustavo avatar escritorio-gustavo commented on September 22, 2024

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.

escritorio-gustavo avatar escritorio-gustavo commented on September 22, 2024

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.

NyxCode avatar NyxCode commented on September 22, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.