-
Notifications
You must be signed in to change notification settings - Fork 200
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
The ignore
attribute now accepts an optional bool value
#1177
Conversation
34622f7
to
2fe1774
Compare
ignore
attribute now accepts an optional bool value
I think accepting any expression is misleading and breaks very easily. It would be simpler/more sane to accept either a literal bool or a path to a If ones wants to use generics const, it's still possible like this: #[derive(Debug, Serialize, ToSchema)]
pub struct SuccessResponsePayload<T: ResourceObject, const IGNORE_INCLUDED: bool = true> {
pub data: Vec<T>,
#[schema(ignore = Self::ignore_included())]
pub included: Vec<T::RelationshipValue>,
#[schema(inline)]
pub links: LinksObject<T>,
}
impl<T: ResourceObject, const IGNORE_INCLUDED: bool> SuccessResponsePaylod<T, IGNORE_INCLUDED> {
fn ignore_included() -> bool { IGNORE_INCLUDED }
} Any input on this @juhaku ? |
Yup, I am fine even without the support of expression and const generic support or |
2fe1774
to
2da570c
Compare
@juhaku I'm handling it because I need it. I need some fields to be statically ignored based on some associated const value/associated function. |
@JMLX42 That's a valid point, If you think the |
2da570c
to
f412f8e
Compare
@juhaku I have updated the PR to implement I'll see how it reports errors on my code base and report back. |
The error does mention the type error. But it highlights |
f412f8e
to
21cbcc7
Compare
Done in 21cbcc7: let value = api_doc! {
struct SchemaIgnoredField {
value: String,
#[schema(ignore = 42)]
this_is_not_private: String,
}
};
The trick was to use |
Just a thought, could this be changed to syntax, similar to
You need a correct span for that. The error need to be spanned with the span of the parsed attribute. For example here in utoipa/utoipa-gen/src/component/features/validation.rs Lines 135 to 142 in ca643ef
You could use Hope this helps |
21cbcc7
to
783f807
Compare
Great, just as I wrote some help, ignore me then 🤣 |
783f807
to
8c04f8c
Compare
@juhaku IMHO I'm good to go. I've updated the doc and the CHANGELOG too. Let me know if there is anything else required. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty neat, thanks 👍 🥇
@JMLX42 It looks good to me. Just wondering whether the syntax of the function parsing can be altered to be without the ending parenthesis |
a43f049
to
0bcb24a
Compare
@juhaku done! |
0bcb24a
to
4eab0fc
Compare
@juhaku actually no, it does not work as expected: #[derive(Debug, Serialize, ToSchema)]
pub struct SuccessResponsePayload<T: ResourceObject> {
pub data: Vec<T>,
#[schema(ignore = Self::ignore_included())]
#[serde(skip_serializing_if = "Option::is_none")]
pub included: Option<Vec<T::RelationshipValue>>,
#[schema(inline)]
pub links: LinksObject<T>,
} Error message:
|
Ok, I guess it can be then as is. |
@juhaku nope. I'll make it work 👍 |
@juhaku actually it does work exactly as expected: I wrote So I guess we're all good ✔️ . |
Nice, well great. We are good to go, I merge this then, thanks for the patch 🙂 |
Allow to statically ignore field using const generics:
The following syntaxes are also supported:
#[schema(ignore)]
(defaults totrue
)#[schema(ignore = false)]
#[schema(ignore = <exp>)]
with<exp>
any expression that returnsbool