juhaku / utoipa

Simple, Fast, Code first and Compile time generated OpenAPI documentation for Rust
Apache License 2.0
2.51k stars 197 forks source link

[Feature Request] Automatically derive "title" for Enum Variants #865

Open wallagib opened 9 months ago

wallagib commented 9 months ago

I'm adding functionality to another code generator that consumes the OpenAPI spec, and I realized that it would be nice to propagate the enum names from Rust into other languages. I'm probably going to do this by pulling the title field if present.

In my environment, I have a lot of enums and adding schema(title="X") for each variant just to have the same name is tedious. Is there any reason not to automatically set title=<enum name> automatically?

EDIT: I'm not sure if/how this would work with the other serde enum tagging types.

bamkrs commented 8 months ago

+1 to automatically set it to title=<enum name><enum value name>

pub enum Schedule {
    #[schema(title = "ScheduleYearly")]
    Yearly(YearlySchedule),
    #[schema(title = "ScheduleMonthly")]
    Monthly(MonthlySchedule),
    #[schema(title = "ScheduleWeekly")]
    Weekly(WeeklySchedule),
    #[schema(title = "ScheduleDaily")]
    Daily(DailySchedule),
    /// execute once on the given date and then never again
    #[schema(title = "ScheduleOnce")]
    Once { date_time: NaiveDateTime },
}