Skip to content
Merged
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
116 changes: 116 additions & 0 deletions output/csharp/src/Seam.Test/Client/SeamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,120 @@ public void TestUnknownEnumValue()
device.Properties.AvailableFanModeSettings[1]
);
}

[Fact]
public void TestDiscriminatedUnionArrayWithUnknownTypes()
{
var json =
@"{
""connected_account_id"": ""test-account-id"",
""account_type"": ""august"",
""account_type_display_name"": ""August Lock"",
""automatically_manage_new_devices"": true,
""created_at"": ""2024-01-15T10:00:00Z"",
""accepted_capabilities"": [],
""custom_metadata"": {},
""errors"": [
{
""error_code"": ""unknown_error_type"",
""message"": ""An unknown error occurred"",
""created_at"": ""2024-01-15T10:00:00Z""
}
],
""warnings"": [
{
""warning_code"": ""unknown_warning_type"",
""message"": ""An unknown warning occurred"",
""created_at"": ""2024-01-15T10:00:00Z""
}
]
}";

var settings = new JsonSerializerSettings
{
Converters = new List<JsonConverter> { new SafeStringEnumConverter() },
MissingMemberHandling = MissingMemberHandling.Ignore,
};

// Unknown discriminated union types should fall back to unrecognized type
var account = JsonConvert.DeserializeObject<ConnectedAccount>(json, settings);

Assert.NotNull(account);
Assert.NotNull(account.Errors);
Assert.Single(account.Errors);

// The unknown error type should fall back to an unrecognized error type
var error = account.Errors[0];
Assert.Equal("unrecognized", error.ErrorCode);
Assert.Equal("An unknown error occurred", error.Message);
}

[Fact]
public void TestEventArrayWithUnknownTypes()
{
var json =
@"[
{
""event_id"": ""event-1"",
""event_type"": ""device.connected"",
""created_at"": ""2024-01-15T10:00:00Z"",
""occurred_at"": ""2024-01-15T10:00:00Z"",
""device_id"": ""device-123"",
""connected_account_id"": ""account-123"",
""workspace_id"": ""workspace-123""
},
{
""event_id"": ""event-2"",
""event_type"": ""unknown_event_type"",
""created_at"": ""2024-01-15T10:00:00Z"",
""custom_field"": ""custom_value""
}
]";

var settings = new JsonSerializerSettings
{
Converters = new List<JsonConverter> { new SafeStringEnumConverter() },
MissingMemberHandling = MissingMemberHandling.Ignore,
};

// Unknown event types should fall back to unrecognized type
var events = JsonConvert.DeserializeObject<List<Event>>(json, settings);

Assert.NotNull(events);
Assert.Equal(2, events.Count);

// First event should deserialize normally
Assert.IsType<EventDeviceConnected>(events[0]);

// Second event with unknown type should fall back to unrecognized
var unknownEvent = events[1];
Assert.IsType<EventUnrecognized>(unknownEvent);
Assert.Equal("unrecognized", unknownEvent.EventType);
}

[Fact]
public void TestActionAttemptWithUnknownType()
{
// Test case for ActionAttempt with unknown action types
var json =
@"{
""action_attempt_id"": ""attempt-123"",
""action_type"": ""UNKNOWN_ACTION"",
""status"": ""success"",
""result"": {},
""error"": null
}";

var settings = new JsonSerializerSettings
{
Converters = new List<JsonConverter> { new SafeStringEnumConverter() },
MissingMemberHandling = MissingMemberHandling.Ignore,
};

// Unknown action types should fall back to unrecognized type
var actionAttempt = JsonConvert.DeserializeObject<ActionAttempt>(json, settings);

Assert.NotNull(actionAttempt);
Assert.Equal("unrecognized", actionAttempt.ActionType);
}
}
84 changes: 84 additions & 0 deletions output/csharp/src/Seam/Model/AccessCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public AccessCode(
}

[JsonConverter(typeof(JsonSubtypes), "error_code")]
[JsonSubtypes.FallBackSubType(typeof(AccessCodeErrorsUnrecognized))]
[JsonSubtypes.KnownSubType(
typeof(AccessCodeErrorsBridgeDisconnected),
"bridge_disconnected"
Expand Down Expand Up @@ -2362,6 +2363,47 @@ public override string ToString()
}
}

[DataContract(Name = "seamModel_accessCodeErrorsUnrecognized_model")]
public class AccessCodeErrorsUnrecognized : AccessCodeErrors
{
[JsonConstructorAttribute]
protected AccessCodeErrorsUnrecognized() { }

public AccessCodeErrorsUnrecognized(
string errorCode = default,
string message = default
)
{
ErrorCode = errorCode;
Message = message;
}

[DataMember(Name = "error_code", IsRequired = true, EmitDefaultValue = false)]
public override string ErrorCode { get; } = "unrecognized";

[DataMember(Name = "message", IsRequired = true, EmitDefaultValue = false)]
public override string Message { get; set; }

public override string ToString()
{
JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(null);

StringWriter stringWriter = new StringWriter(
new StringBuilder(256),
System.Globalization.CultureInfo.InvariantCulture
);
using (JsonTextWriter jsonTextWriter = new JsonTextWriter(stringWriter))
{
jsonTextWriter.IndentChar = ' ';
jsonTextWriter.Indentation = 2;
jsonTextWriter.Formatting = Formatting.Indented;
jsonSerializer.Serialize(jsonTextWriter, this, null);
}

return stringWriter.ToString();
}
}

[JsonConverter(typeof(SafeStringEnumConverter))]
public enum StatusEnum
{
Expand Down Expand Up @@ -2398,6 +2440,7 @@ public enum TypeEnum
}

[JsonConverter(typeof(JsonSubtypes), "warning_code")]
[JsonSubtypes.FallBackSubType(typeof(AccessCodeWarningsUnrecognized))]
[JsonSubtypes.KnownSubType(
typeof(AccessCodeWarningsKwiksetUnableToConfirmCode),
"kwikset_unable_to_confirm_code"
Expand Down Expand Up @@ -3010,6 +3053,47 @@ public override string ToString()
}
}

[DataContract(Name = "seamModel_accessCodeWarningsUnrecognized_model")]
public class AccessCodeWarningsUnrecognized : AccessCodeWarnings
{
[JsonConstructorAttribute]
protected AccessCodeWarningsUnrecognized() { }

public AccessCodeWarningsUnrecognized(
string warningCode = default,
string message = default
)
{
WarningCode = warningCode;
Message = message;
}

[DataMember(Name = "warning_code", IsRequired = true, EmitDefaultValue = false)]
public override string WarningCode { get; } = "unrecognized";

[DataMember(Name = "message", IsRequired = true, EmitDefaultValue = false)]
public override string Message { get; set; }

public override string ToString()
{
JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(null);

StringWriter stringWriter = new StringWriter(
new StringBuilder(256),
System.Globalization.CultureInfo.InvariantCulture
);
using (JsonTextWriter jsonTextWriter = new JsonTextWriter(stringWriter))
{
jsonTextWriter.IndentChar = ' ';
jsonTextWriter.Indentation = 2;
jsonTextWriter.Formatting = Formatting.Indented;
jsonSerializer.Serialize(jsonTextWriter, this, null);
}

return stringWriter.ToString();
}
}

[DataMember(Name = "access_code_id", IsRequired = true, EmitDefaultValue = false)]
public string AccessCodeId { get; set; }

Expand Down
42 changes: 42 additions & 0 deletions output/csharp/src/Seam/Model/AccessGrant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public AccessGrant(
}

[JsonConverter(typeof(JsonSubtypes), "warning_code")]
[JsonSubtypes.FallBackSubType(typeof(AccessGrantWarningsUnrecognized))]
[JsonSubtypes.KnownSubType(typeof(AccessGrantWarningsBeingDeleted), "being_deleted")]
public abstract class AccessGrantWarnings
{
Expand Down Expand Up @@ -110,6 +111,47 @@ public override string ToString()
}
}

[DataContract(Name = "seamModel_accessGrantWarningsUnrecognized_model")]
public class AccessGrantWarningsUnrecognized : AccessGrantWarnings
{
[JsonConstructorAttribute]
protected AccessGrantWarningsUnrecognized() { }

public AccessGrantWarningsUnrecognized(
string warningCode = default,
string message = default
)
{
WarningCode = warningCode;
Message = message;
}

[DataMember(Name = "warning_code", IsRequired = true, EmitDefaultValue = false)]
public override string WarningCode { get; } = "unrecognized";

[DataMember(Name = "message", IsRequired = true, EmitDefaultValue = false)]
public override string Message { get; set; }

public override string ToString()
{
JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(null);

StringWriter stringWriter = new StringWriter(
new StringBuilder(256),
System.Globalization.CultureInfo.InvariantCulture
);
using (JsonTextWriter jsonTextWriter = new JsonTextWriter(stringWriter))
{
jsonTextWriter.IndentChar = ' ';
jsonTextWriter.Indentation = 2;
jsonTextWriter.Formatting = Formatting.Indented;
jsonSerializer.Serialize(jsonTextWriter, this, null);
}

return stringWriter.ToString();
}
}

[DataMember(Name = "access_grant_id", IsRequired = true, EmitDefaultValue = false)]
public string AccessGrantId { get; set; }

Expand Down
42 changes: 42 additions & 0 deletions output/csharp/src/Seam/Model/AccessMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public enum ModeEnum
}

[JsonConverter(typeof(JsonSubtypes), "warning_code")]
[JsonSubtypes.FallBackSubType(typeof(AccessMethodWarningsUnrecognized))]
[JsonSubtypes.KnownSubType(typeof(AccessMethodWarningsBeingDeleted), "being_deleted")]
public abstract class AccessMethodWarnings
{
Expand Down Expand Up @@ -118,6 +119,47 @@ public override string ToString()
}
}

[DataContract(Name = "seamModel_accessMethodWarningsUnrecognized_model")]
public class AccessMethodWarningsUnrecognized : AccessMethodWarnings
{
[JsonConstructorAttribute]
protected AccessMethodWarningsUnrecognized() { }

public AccessMethodWarningsUnrecognized(
string warningCode = default,
string message = default
)
{
WarningCode = warningCode;
Message = message;
}

[DataMember(Name = "warning_code", IsRequired = true, EmitDefaultValue = false)]
public override string WarningCode { get; } = "unrecognized";

[DataMember(Name = "message", IsRequired = true, EmitDefaultValue = false)]
public override string Message { get; set; }

public override string ToString()
{
JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(null);

StringWriter stringWriter = new StringWriter(
new StringBuilder(256),
System.Globalization.CultureInfo.InvariantCulture
);
using (JsonTextWriter jsonTextWriter = new JsonTextWriter(stringWriter))
{
jsonTextWriter.IndentChar = ' ';
jsonTextWriter.Indentation = 2;
jsonTextWriter.Formatting = Formatting.Indented;
jsonSerializer.Serialize(jsonTextWriter, this, null);
}

return stringWriter.ToString();
}
}

[DataMember(Name = "access_method_id", IsRequired = true, EmitDefaultValue = false)]
public string AccessMethodId { get; set; }

Expand Down
Loading
Loading