Skip to content

Commit

Permalink
fix: properly serialize StringEnum list when inside query params (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
box-sdk-build authored Oct 24, 2024
1 parent bef2632 commit dac8392
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "2443714", "specHash": "abd6037", "version": "1.3.0" }
{ "engineHash": "2efc8ab", "specHash": "e798cb1", "version": "1.3.0" }
25 changes: 25 additions & 0 deletions Box.Sdk.Gen.Tests.Integration/Test/Events/EventsManagerTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Box.Sdk.Gen.Internal;
using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using Box.Sdk.Gen;
using Box.Sdk.Gen.Schemas;
using Box.Sdk.Gen.Managers;
Expand All @@ -21,6 +24,28 @@ public async System.Threading.Tasks.Task TestEvents() {
Assert.IsTrue(StringUtils.ToStringRepresentation(NullableUtils.Unwrap(firstEvent.EventType)) != "");
}

[TestMethod]
public async System.Threading.Tasks.Task TestEventUpload() {
Events events = await client.Events.GetEventsAsync(queryParams: new GetEventsQueryParams() { StreamType = GetEventsQueryParamsStreamTypeField.AdminLogs, EventType = Array.AsReadOnly(new [] {new StringEnum<GetEventsQueryParamsEventTypeField>(GetEventsQueryParamsEventTypeField.Upload)}) });
Assert.IsTrue(NullableUtils.Unwrap(events.Entries).Count > 0);
Event firstEvent = NullableUtils.Unwrap(events.Entries)[0];
Assert.IsTrue(StringUtils.ToStringRepresentation(NullableUtils.Unwrap(firstEvent.EventType)) == "UPLOAD");
}

[TestMethod]
public async System.Threading.Tasks.Task TestEventDeleteUser() {
Events events = await client.Events.GetEventsAsync(queryParams: new GetEventsQueryParams() { StreamType = GetEventsQueryParamsStreamTypeField.AdminLogs, EventType = Array.AsReadOnly(new [] {new StringEnum<GetEventsQueryParamsEventTypeField>(GetEventsQueryParamsEventTypeField.DeleteUser)}) });
Assert.IsTrue(NullableUtils.Unwrap(events.Entries).Count > 0);
Event firstEvent = NullableUtils.Unwrap(events.Entries)[0];
Assert.IsTrue(StringUtils.ToStringRepresentation(NullableUtils.Unwrap(firstEvent.EventType)) == "DELETE_USER");
}

[TestMethod]
public async System.Threading.Tasks.Task TestEventSourceFileOrFolder() {
Events events = await client.Events.GetEventsAsync(queryParams: new GetEventsQueryParams() { StreamType = GetEventsQueryParamsStreamTypeField.Changes });
Assert.IsTrue(NullableUtils.Unwrap(events.Entries).Count > 0);
}

[TestMethod]
public async System.Threading.Tasks.Task TestGetEventsWithLongPolling() {
RealtimeServers servers = await client.Events.GetEventsWithLongPollingAsync();
Expand Down
17 changes: 16 additions & 1 deletion Box.Sdk.Gen/Internal/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,22 @@ public static class StringUtils
}
}

private static bool isNotPrimitive(object? obj) => obj != null && !obj.GetType().IsPrimitive && obj.GetType() != typeof(string);
private static bool isNotPrimitive(object? obj) =>
obj != null &&
!obj.GetType().IsPrimitive &&
obj.GetType() != typeof(string) &&
!IsStringEnumType(obj.GetType());

private static bool IsStringEnumType(Type type)
{
if (type.IsGenericType)
{
var genericTypeDefinition = type.GetGenericTypeDefinition();
return genericTypeDefinition == typeof(StringEnum<>);
}

return false;
}

private static bool anyNonPrimitives(IList list)
{
Expand Down
7 changes: 4 additions & 3 deletions Box.Sdk.Gen/Schemas/ClientError/ClientError.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Box.Sdk.Gen;
using System.Text.Json.Serialization;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text.Json.Serialization;
using Box.Sdk.Gen.Internal;

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

protected ClientErrorContextInfoField? _contextInfo { get; set; }
protected Dictionary<string, object>? _contextInfo { get; set; }

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

/// <summary>
/// A URL that links to more information about why this error occurred.
Expand Down
26 changes: 0 additions & 26 deletions Box.Sdk.Gen/Schemas/ClientError/ClientErrorContextInfoField.cs

This file was deleted.

0 comments on commit dac8392

Please sign in to comment.