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

allow renaming IntoParams field names #309

Merged
merged 1 commit into from
Oct 8, 2022
Merged

Conversation

fluxxu
Copy link
Contributor

@fluxxu fluxxu commented Oct 4, 2022

Use case:

#[derive(Debug, Deserialize, ToSchema, IntoParams)]
pub struct GetInventorySupplyInput {
  pub warehouse_id: String,
  #[param(rename = "sku_list[]")]
  pub sku_list: Option<Vec<String>>,
}

Without the rename, sku_list is serialized as sku_list=1&sku_list=2, but to use with axum::Query we need sku_list[]=1&sku_list[]=2

@DerZwergGimli
Copy link

much needed please add this in a new version - the fork is working!

i need it for renaming 'type' to something else!

#[derive(Debug, Deserialize, IntoParams)]
#[into_params(parameter_in = Query)]
pub struct SearchParams {
    #[param(style = Form, example = "FOOD")]
    query: Option<String>,
    #[param(rename = "type")]
    stype: Option<String>,
    exchange: Option<String>,
    limit: Option<i32>,
}

@juhaku
Copy link
Owner

juhaku commented Oct 8, 2022

For these few recent days, I haven't had a time to do much regarding this project. I have had my hands full of other things explained a bit here: #276.

I can add this to the master, but I will not create a release before this feature has been rewritten with serde support #313 thus the rename will then be only temporarily within param(rename = ...) and will be removed when the support is written for serde(rename = ...).

Copy link
Owner

@juhaku juhaku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty okay.

Though it is missing docs and tests. But since this will be only a temporary functionality those can be omitted I suppose. The support should be implemented with serde as described here:
#309 (comment) and here: #313

@juhaku juhaku merged commit 00fb59a into juhaku:master Oct 8, 2022
juhaku added a commit that referenced this pull request Nov 8, 2022
Refactor IntoParams field attribute parsing functionality to use the new
Feature based parsing. Add new features for `Rename`, `RenameAll`,
`Style`, `AllowReserved` and `Explode`.

Add support for serde `default`, `rename` and `rename_all` attributes
for container and field level similar to `ToSchema` implementation.

Update docs and add tests for renaming and supported serde attributes.

Resolves #309, fixes #313
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

Successfully merging this pull request may close these issues.

3 participants