Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions client/src/generated/immutable.sdk_models.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ pub struct TokenUsage {
pub r#type: UsageType,
pub token_id: ::prost::alloc::string::String,
#[serde(default)]
#[serde(flatten)]
pub usage: ::core::option::Option<token_usage::Usage>,
}
/// Nested message and enum types in `TokenUsage`.
pub mod token_usage {
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[derive(Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
#[derive(Debug)]
pub enum Usage {
#[serde(rename = "USAGE_SIGNUP")]
Signup(super::SignupUsage),
#[serde(rename = "USAGE_LOGIN")]
Login(super::LoginUsage),
#[serde(rename = "USAGE_SIGNUP_V2")]
SignupV2(super::SignupUsageV2),
LoginV2(super::LoginUsageV2),
SignupV3(super::SignupUsageV3),
}
}
#[derive(Debug)]
Expand Down Expand Up @@ -69,6 +70,44 @@ pub struct SignupUsageV2 {
pub struct LoginUsage {
pub public_key: ::prost::alloc::string::String,
}
#[derive(Debug)]
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "camelCase")]
#[derive(Clone, PartialEq)]
pub struct LoginUsageV2 {
pub organization_id: ::prost::alloc::string::String,
pub public_key: ::prost::alloc::string::String,
#[serde(default)]
pub invalidate_existing: ::core::option::Option<bool>,
#[serde(default)]
pub expiration_seconds: ::core::option::Option<::prost::alloc::string::String>,
#[serde(default)]
pub session_profile_id: ::core::option::Option<::prost::alloc::string::String>,
}
#[derive(Debug)]
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "camelCase")]
#[derive(Clone, PartialEq)]
pub struct SignupUsageV3 {
pub parent_organization_id: ::prost::alloc::string::String,
pub sub_organization_name: ::prost::alloc::string::String,
#[serde(default)]
pub root_users: ::prost::alloc::vec::Vec<
super::super::activity::v1::RootUserParamsV5,
>,
#[serde(default)]
pub root_quorum_threshold: i32,
#[serde(default)]
pub wallet: ::core::option::Option<super::super::activity::v1::WalletParams>,
#[serde(default)]
pub disable_email_recovery: ::core::option::Option<bool>,
#[serde(default)]
pub disable_email_auth: ::core::option::Option<bool>,
#[serde(default)]
pub disable_sms_auth: ::core::option::Option<bool>,
#[serde(default)]
pub disable_otp_email_auth: ::core::option::Option<bool>,
}
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum UsageType {
Expand Down
28 changes: 20 additions & 8 deletions codegen/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ fn mutate_enum(enum_item: &syn::ItemEnum) -> TokenStream {
});

let enum_name_upper = ident.to_string().to_shouty_snake_case();
let is_token_usage = ident == "Usage"
&& enum_item
.variants
.iter()
.any(|variant| variant.ident == "LoginV2")
&& enum_item
.variants
.iter()
.any(|variant| variant.ident == "SignupV3");

let variants = enum_item.variants.iter().map(|v| {
let mut v = v.clone();
Expand All @@ -107,11 +116,11 @@ fn mutate_enum(enum_item: &syn::ItemEnum) -> TokenStream {
variant_name.to_string().to_shouty_snake_case()
);

// A bit of a special case, but it doesn't make sense to rename result::Inner, intent::Inner, or TokenOrClaim
// which are complex enums we flatten at serialization/parsing time.
// A bit of a special case, but it doesn't make sense to rename result::Inner, intent::Inner,
// TokenOrClaims, or TokenUsage's flattened usage oneof with protobuf enum prefixes.
// TODO: would be nice to filter this in a more generic way: basically if the enum isn't a "simple" enum, we shouldn't
// have to individually rename the variants
if ident != "Inner" && ident != "TokenOrClaims" {
if ident != "Inner" && ident != "TokenOrClaims" && !is_token_usage {
let rename_attr: syn::Attribute = syn::parse_quote!(
#[serde(rename = #full_name)]
);
Expand All @@ -121,9 +130,9 @@ fn mutate_enum(enum_item: &syn::ItemEnum) -> TokenStream {
quote! { #v }
});

// Another quick special case: Result::Inner and Intent::Inner and TokenOrClaims require #[serde(rename_all = "camelCase")]
// Another quick special case: flattened oneofs use camelCase protobuf JSON keys.
// We also derive "Debug", it's very useful to be able to serialize activities in a pinch.
if ident == "Inner" || ident == "TokenOrClaims" {
if ident == "Inner" || ident == "TokenOrClaims" || is_token_usage {
attrs.push(quote! {
#[serde(rename_all = "camelCase")]
#[derive(Debug)]
Expand Down Expand Up @@ -196,12 +205,15 @@ fn mutate_struct(struct_value: &syn::ItemStruct) -> TokenStream {
));
}

// Flatten out Result::inner and Intent::inner since we have no "inner" key in the JSON responses we return or expect!
// We also flatten out "tokenOrClaims" (part of Oauth params v2) for the same reason.
// Flatten protobuf JSON oneofs that do not have wrapper keys on the wire.
if field
.ident
.as_ref()
.map(|i| i == "inner" || i == "token_or_claims")
.map(|i| {
i == "inner"
|| i == "token_or_claims"
|| (struct_ident == "TokenUsage" && i == "usage")
})
.unwrap_or(false)
{
field.attrs.push(syn::parse_quote!(
Expand Down
22 changes: 22 additions & 0 deletions proto/immutable/sdk_models/v1/models.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ message TokenUsage {
SignupUsage signup = 3;
LoginUsage login = 4;
SignupUsageV2 signup_v2 = 5;
LoginUsageV2 login_v2 = 6;
SignupUsageV3 signup_v3 = 7;
}
}

Expand All @@ -52,3 +54,23 @@ message LoginUsage {
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {description: "Public key for authentication"}
];
}

message LoginUsageV2 {
string organization_id = 1 [(google.api.field_behavior) = REQUIRED];
string public_key = 2 [(google.api.field_behavior) = REQUIRED];
optional bool invalidate_existing = 3;
optional string expiration_seconds = 4;
optional string session_profile_id = 5;
}

message SignupUsageV3 {
string parent_organization_id = 1 [(google.api.field_behavior) = REQUIRED];
string sub_organization_name = 2 [(google.api.field_behavior) = REQUIRED];
repeated immutable.activity.v1.RootUserParamsV5 root_users = 3 [(google.api.field_behavior) = REQUIRED];
int32 root_quorum_threshold = 4 [(google.api.field_behavior) = REQUIRED];
optional immutable.activity.v1.WalletParams wallet = 5;
optional bool disable_email_recovery = 6;
optional bool disable_email_auth = 7;
optional bool disable_sms_auth = 8;
optional bool disable_otp_email_auth = 9;
}
Loading