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

support serde skip_serializing #438

Merged
merged 4 commits into from
Jan 23, 2023
Merged

support serde skip_serializing #438

merged 4 commits into from
Jan 23, 2023

Conversation

samchouse
Copy link
Contributor

No description provided.

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 good, but there is a test missing, and docs as well.

Docs should be updated here: https://github.com/juhaku/utoipa/blob/master/utoipa-gen/src/lib.rs#L179

And here:
https://github.com/juhaku/utoipa/blob/master/utoipa-gen/src/lib.rs#L1569

I suppose this skip_serializing should work in both IntoParams and in ToSchema

@samchouse
Copy link
Contributor Author

I couldn't find where the tests are for the original skip and I couldn't find anything for the original skip related to IntoParams. Can you point them out for me please?

@juhaku
Copy link
Owner

juhaku commented Jan 20, 2023

Sure here is the example test for skip for ToSchema

fn derive_parse_serde_field_attributes() {
struct S;
let post = api_doc! {
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct Post<S> {
#[serde(rename = "uuid")]
id: String,
#[serde(skip)]
_p: PhantomData<S>,
long_field_num: i64,
}
};
assert_value! {post=>
"properties.uuid.type" = r#""string""#, "Post id type"
"properties.longFieldNum.type" = r#""integer""#, "Post long_field_num type"
"properties.longFieldNum.format" = r#""int64""#, "Post logn_field_num format"
}
}
#[test]
fn derive_parse_serde_simple_enum_attributes() {
let value = api_doc! {
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
enum Value {
A,
B,
#[serde(skip)]
C,
}
};
assert_value! {value=>
"enum" = r#"["a","b"]"#, "Value enum variants"
}
}

Seems like the skip support is not implemented for IntoParams. I remembered wrong. So we can ignore it now. That can be another PR because it needs more changes for IntoParams than just updating docs and adding tests.

So just creating a test for for skip_serializing attribute is enough in tests/schema_derive_test.rs

@juhaku
Copy link
Owner

juhaku commented Jan 20, 2023

Also instead of using assert_value! macro you can use assert_json_eq! as well.

@samchouse samchouse requested a review from juhaku January 21, 2023 15:41
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.

It's good, since you added the skip_serializing to the same test, we can remove the assert_value!

@juhaku juhaku merged commit b167838 into juhaku:master Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Released
Development

Successfully merging this pull request may close these issues.

2 participants