You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use axum_extra::routing::TypedPath;use serde_derive::{Deserialize,Serialize};use strum::{AsRefStr,Display,EnumString,EnumVariantNames,IntoStaticStr};#[derive(Debug,Clone,Copy,PartialEq,Eq,Default,Display,Serialize,Deserialize,IntoStaticStr,AsRefStr,EnumVariantNames,EnumString)]#[strum(serialize_all = "lowercase")]#[strum(ascii_case_insensitive)]pubenumTpeKind{Config,#[default]Data,Index,Keys,Locks,Snapshots,}#[derive(TypedPath,Deserialize)]#[typed_path("/:repo/:tpe/:name")]pubstructRepositoryTpeNamePath{pubrepo:String,pubtpe:TpeKind,pubname:String,}
As a response I'm getting:
response body = "Invalid URL: unknown variant `keys`, expected one of `Config`, `Data`, `Index`, `Keys`, `Locks`, `Snapshots`"
Which I don't understand after using strum and making sure the variants are lowercase. How can I make sure axum is using the serialized variants that strum provides? Or how can assure, that the lowercase variants are used for comparison in the path?
EDIT: The fix is to annotate TpeKind with #[serde(rename_all = "lowercase")], but I thought using strum would have the same effect?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Summary
I'm using the following enum and TypedPath:
As a response I'm getting:
response body = "Invalid URL: unknown variant `keys`, expected one of `Config`, `Data`, `Index`, `Keys`, `Locks`, `Snapshots`"
Which I don't understand after using
strum
and making sure the variants are lowercase. How can I make sureaxum
is using the serialized variants thatstrum
provides? Or how can assure, that the lowercase variants are used for comparison in the path?EDIT: The fix is to annotate
TpeKind
with#[serde(rename_all = "lowercase")]
, but I thought using strum would have the same effect?axum version
0.7.4
Beta Was this translation helpful? Give feedback.
All reactions