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

Add skip_serialize_none to OAuth structs with option fields #5046

Merged
merged 7 commits into from
Sep 26, 2024
7 changes: 4 additions & 3 deletions crates/api_common/src/oauth_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ pub struct CreateOAuthProvider {
pub client_id: String,
pub client_secret: String,
pub scopes: String,
pub auto_verify_email: bool,
pub account_linking_enabled: bool,
pub enabled: bool,
pub auto_verify_email: Option<bool>,
pub account_linking_enabled: Option<bool>,
pub enabled: Option<bool>,
}
Copy link
Member

Choose a reason for hiding this comment

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

Good catch, those are not null with default, so the insert should be optional.


#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
Expand Down
12 changes: 7 additions & 5 deletions crates/db_schema/src/source/oauth_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ impl Serialize for PublicOAuthProvider {
}
}

#[derive(Debug, Clone)]
#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Deserialize)]
Copy link
Member

@Nutomic Nutomic Sep 24, 2024

Choose a reason for hiding this comment

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

This struct and the one below arend used anywhere in the api so these derives are not needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

I ended up needing the derives for skip_serializing_none to work.

Copy link
Member

Choose a reason for hiding this comment

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

There is no use for skip_serializing_none if the struct is not exposed in the api.

Copy link
Member

Choose a reason for hiding this comment

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

It looks like its returned in the GetSiteResponse, so it does need it.

Copy link
Member

Choose a reason for hiding this comment

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

It only uses OAuthProvider and PublicOAuthProvider, but Im talking about OAuthProviderInsertForm and OAuthProviderUpdateForm which dont need serde derives.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are the update and insert form even supposed to be exposed to the API client? If not, I'll remove the ts export from them.

Copy link
Member

Choose a reason for hiding this comment

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

No they are only used internally in Rust.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed I removed the TS export stuff from OAuthProviderInsertForm and OAuthProviderUpdateForm.

#[cfg_attr(feature = "full", derive(Insertable, AsChangeset, TS))]
#[cfg_attr(feature = "full", diesel(table_name = oauth_provider))]
#[cfg_attr(feature = "full", ts(export))]
Expand All @@ -104,12 +105,13 @@ pub struct OAuthProviderInsertForm {
pub client_id: String,
pub client_secret: String,
pub scopes: String,
pub auto_verify_email: bool,
pub account_linking_enabled: bool,
pub enabled: bool,
pub auto_verify_email: Option<bool>,
pub account_linking_enabled: Option<bool>,
pub enabled: Option<bool>,
}

#[derive(Debug, Clone)]
#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset, TS))]
#[cfg_attr(feature = "full", diesel(table_name = oauth_provider))]
#[cfg_attr(feature = "full", ts(export))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ CREATE TABLE oauth_provider (
scopes text NOT NULL,
auto_verify_email boolean DEFAULT TRUE NOT NULL,
account_linking_enabled boolean DEFAULT FALSE NOT NULL,
enabled boolean DEFAULT FALSE NOT NULL,
enabled boolean DEFAULT TRUE NOT NULL,
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if there's some reason this was default false, or if it was just an accident. @privacyguard

published timestamp with time zone DEFAULT now() NOT NULL,
updated timestamp with time zone
);
Expand Down