oscartbeaumont / rspc

A framework for building typesafe web backends in Rust
https://rspc.dev
MIT License
1.11k stars 51 forks source link

extra quotation mark is parsed when exporting an enum after a `serde` rename #152

Closed mnpqraven closed 1 year ago

mnpqraven commented 1 year ago

I ran across this issue when trying to transfer my rust enums to the frontend after some serde renaming. For context, the enum's string variation won't be processed in the rust backend other than FromStr to work with SQLite database, but for the frontend I'm using the enum's Display to get string presentation Given this enum

use std::str::FromStr;
use serde::{Deserialize, Serialize};
use strum::{Display, EnumIter, EnumString, IntoEnumIterator};

#[derive(Serialize, Deserialize, Type, EnumString, EnumIter, Display)]
enum CoolEnum {
    #[serde(rename = "Foo Bar")]
    FooBar,
    #[serde(rename(serialize= "Foo Baz", deserialize = "Foo Baz"))]
    #[strum(serialize = "Foo Baz")]
    FooBaz,
}

the exported TS would be:

export type CoolEnum = ""Foo Bar"" | "FooBaz"
oscartbeaumont commented 1 year ago

This was an issue in the santiser of Specta. A fix has been published for Specta. I am under the impression Cargo should pick it up so maybe try cargo add specta and see if it fixes it.

If not I can publish a new rspc release because i'm not too far off that.