Skip to content
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

oapi 的 QueryParam 不支持 struct类型 #628

Closed
z91300 opened this issue Jan 11, 2024 · 2 comments
Closed

oapi 的 QueryParam 不支持 struct类型 #628

z91300 opened this issue Jan 11, 2024 · 2 comments

Comments

@z91300
Copy link

z91300 commented Jan 11, 2024

Is your feature request related to a problem? Please describe.
image

Describe the solution you'd like
QueryParam 支持 struct 传参并且能够在openapi中能够正常显示对应的字段属性

Describe alternatives you've considered

还是说只能如 example-oapi-todos 中的list示例一样列举出所有字段

pub async fn list_todos(offset: QueryParam<usize, false>, limit: QueryParam<usize, false>) -> Json<Vec<Todo>> {
}

Additional context

@z91300
Copy link
Author

z91300 commented Jan 11, 2024

还有个问题在 #168 ,提供的代码在salvo更新至 0.64 版本无法正常使用。

@chrislearn
Copy link
Member

可以使用 ToParameters, 把所有的参数集合起来存放在一个或者多个 struct 中,比如:

#[derive(ToParameters, serde::Deserialize)]
#[salvo(parameters(default_parameter_in = Query))]
struct Filter {
    #[salvo(parameter(value_type = Id))]
    id: String
    #[salvo(parameter(max_length = 10, min_length = 5, pattern = "[a-z]*"))]
    value: String,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants