-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trying to use an enum as a Query
parameter causes a panic
#1244
Comments
It's possible we have a bug, but I suspect the issue is that that particular enum can't be easily represented as a query string, or at least, if it were it would have to be an opinionated encoding (imagine base64ed JSON or something). How do you picture that enum being represented as a string? (I'm sure we could have a better error message here too.)
dropshot/dropshot/src/pagination.rs Line 221 in 6ca54c2
dropshot/dropshot/src/pagination.rs Lines 232 to 233 in 6ca54c2
|
Oops, yep, that's a bad repro. Apologies! My actual types look more like this: #[derive(Serialize, Deserialize, JsonSchema)]
#[serde(tag = "type")]
enum QueryParamEnum {
Foo(Foo),
Bar(Bar),
}
#[derive(Serialize, Deserialize, JsonSchema)]
struct Foo {
thing_one: String,
}
#[derive(Serialize, Deserialize, JsonSchema)]
struct Bar {
thing_one: String,
thing_two: String,
} Serialized with
Ah, I didn't notice the |
Also try putting it in a struct with |
#[derive(Serialize, Deserialize, JsonSchema)]
struct QueryParam {
#[serde(flatten)]
inner: QueryParamEnum,
}
#[derive(Serialize, Deserialize, JsonSchema)]
#[serde(tag = "type")]
enum QueryParamEnum {
Foo(Foo),
Bar(Bar),
} That gets me a slightly different error with no hint in the error message:
I'm going to try to work around this for now with a QueryParam that just contains a #[derive(Serialize, Deserialize, JsonSchema)]
struct QueryParam {
#[serde(flatten)]
inner: serde_json::Map<String, serde_json::Value>,
} |
I've got an enum as part of my API and tried to use it as a
Query
type, and immediately got a panic from dropshot while generating the API. I expected this to work, since it looks likePaginationParams
andWhichParams
are enums and there's no warnings in the docs.Here's a minimal repro:
The panic dumps the schema for
QueryParamEnum
and suggests wrapping it in a struct:If I try to wrap everything in a struct like the error message suggests I do, I still get a panic.
The text was updated successfully, but these errors were encountered: