Skip to content

Commit dac8392

Browse files
fix: properly serialize StringEnum list when inside query params (#288)
1 parent bef2632 commit dac8392

File tree

5 files changed

+46
-31
lines changed

5 files changed

+46
-31
lines changed

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "2443714", "specHash": "abd6037", "version": "1.3.0" }
1+
{ "engineHash": "2efc8ab", "specHash": "e798cb1", "version": "1.3.0" }

Box.Sdk.Gen.Tests.Integration/Test/Events/EventsManagerTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
22
using Box.Sdk.Gen.Internal;
3+
using System;
4+
using System.Collections.ObjectModel;
5+
using System.Collections.Generic;
36
using Box.Sdk.Gen;
47
using Box.Sdk.Gen.Schemas;
58
using Box.Sdk.Gen.Managers;
@@ -21,6 +24,28 @@ public async System.Threading.Tasks.Task TestEvents() {
2124
Assert.IsTrue(StringUtils.ToStringRepresentation(NullableUtils.Unwrap(firstEvent.EventType)) != "");
2225
}
2326

27+
[TestMethod]
28+
public async System.Threading.Tasks.Task TestEventUpload() {
29+
Events events = await client.Events.GetEventsAsync(queryParams: new GetEventsQueryParams() { StreamType = GetEventsQueryParamsStreamTypeField.AdminLogs, EventType = Array.AsReadOnly(new [] {new StringEnum<GetEventsQueryParamsEventTypeField>(GetEventsQueryParamsEventTypeField.Upload)}) });
30+
Assert.IsTrue(NullableUtils.Unwrap(events.Entries).Count > 0);
31+
Event firstEvent = NullableUtils.Unwrap(events.Entries)[0];
32+
Assert.IsTrue(StringUtils.ToStringRepresentation(NullableUtils.Unwrap(firstEvent.EventType)) == "UPLOAD");
33+
}
34+
35+
[TestMethod]
36+
public async System.Threading.Tasks.Task TestEventDeleteUser() {
37+
Events events = await client.Events.GetEventsAsync(queryParams: new GetEventsQueryParams() { StreamType = GetEventsQueryParamsStreamTypeField.AdminLogs, EventType = Array.AsReadOnly(new [] {new StringEnum<GetEventsQueryParamsEventTypeField>(GetEventsQueryParamsEventTypeField.DeleteUser)}) });
38+
Assert.IsTrue(NullableUtils.Unwrap(events.Entries).Count > 0);
39+
Event firstEvent = NullableUtils.Unwrap(events.Entries)[0];
40+
Assert.IsTrue(StringUtils.ToStringRepresentation(NullableUtils.Unwrap(firstEvent.EventType)) == "DELETE_USER");
41+
}
42+
43+
[TestMethod]
44+
public async System.Threading.Tasks.Task TestEventSourceFileOrFolder() {
45+
Events events = await client.Events.GetEventsAsync(queryParams: new GetEventsQueryParams() { StreamType = GetEventsQueryParamsStreamTypeField.Changes });
46+
Assert.IsTrue(NullableUtils.Unwrap(events.Entries).Count > 0);
47+
}
48+
2449
[TestMethod]
2550
public async System.Threading.Tasks.Task TestGetEventsWithLongPolling() {
2651
RealtimeServers servers = await client.Events.GetEventsWithLongPollingAsync();

Box.Sdk.Gen/Internal/StringExtensions.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,22 @@ public static class StringUtils
7777
}
7878
}
7979

80-
private static bool isNotPrimitive(object? obj) => obj != null && !obj.GetType().IsPrimitive && obj.GetType() != typeof(string);
80+
private static bool isNotPrimitive(object? obj) =>
81+
obj != null &&
82+
!obj.GetType().IsPrimitive &&
83+
obj.GetType() != typeof(string) &&
84+
!IsStringEnumType(obj.GetType());
85+
86+
private static bool IsStringEnumType(Type type)
87+
{
88+
if (type.IsGenericType)
89+
{
90+
var genericTypeDefinition = type.GetGenericTypeDefinition();
91+
return genericTypeDefinition == typeof(StringEnum<>);
92+
}
93+
94+
return false;
95+
}
8196

8297
private static bool anyNonPrimitives(IList list)
8398
{

Box.Sdk.Gen/Schemas/ClientError/ClientError.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Box.Sdk.Gen;
2-
using System.Text.Json.Serialization;
32
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
using System.Text.Json.Serialization;
45
using Box.Sdk.Gen.Internal;
56

67
namespace Box.Sdk.Gen.Schemas {
@@ -9,7 +10,7 @@ public class ClientError : ISerializable {
910
[JsonPropertyName("_iscontext_infoSet")]
1011
protected bool _isContextInfoSet { get; set; }
1112

12-
protected ClientErrorContextInfoField? _contextInfo { get; set; }
13+
protected Dictionary<string, object>? _contextInfo { get; set; }
1314

1415
/// <summary>
1516
/// error
@@ -43,7 +44,7 @@ public class ClientError : ISerializable {
4344
/// a per-endpoint basis. `message` is only one example.
4445
/// </summary>
4546
[JsonPropertyName("context_info")]
46-
public ClientErrorContextInfoField? ContextInfo { get => _contextInfo; init { _contextInfo = value; _isContextInfoSet = true; } }
47+
public Dictionary<string, object>? ContextInfo { get => _contextInfo; init { _contextInfo = value; _isContextInfoSet = true; } }
4748

4849
/// <summary>
4950
/// A URL that links to more information about why this error occurred.

Box.Sdk.Gen/Schemas/ClientError/ClientErrorContextInfoField.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)