ci: regenerated with OpenAPI Doc 0.0.3, Speakeasy CLI 1.205.0

This commit is contained in:
speakeasybot
2024-03-10 00:41:45 +00:00
parent f8e29c091a
commit 1ee5f5349e
147 changed files with 4104 additions and 1755 deletions

View File

@@ -17,7 +17,16 @@ namespace PlexAPI.Utils
internal class BigIntSerializer : JsonConverter
{
public override bool CanConvert(Type objectType) => objectType == typeof(BigInteger);
public override bool CanConvert(Type objectType)
{
var nullableType = Nullable.GetUnderlyingType(objectType);
if (nullableType != null)
{
return nullableType == typeof(BigInteger);
}
return objectType == typeof(BigInteger);
}
public override bool CanRead => true;

View File

@@ -16,7 +16,16 @@ namespace PlexAPI.Utils
internal class DecimalSerializer : JsonConverter
{
public override bool CanConvert(Type objectType) => objectType == typeof(Decimal);
public override bool CanConvert(Type objectType)
{
var nullableType = Nullable.GetUnderlyingType(objectType);
if (nullableType != null)
{
return nullableType == typeof(Decimal);
}
return objectType == typeof(Decimal);
}
public override bool CanRead => true;

View File

@@ -15,7 +15,16 @@ namespace PlexAPI.Utils
{
internal class EnumSerializer : JsonConverter
{
public override bool CanConvert(System.Type objectType) => objectType.IsEnum;
public override bool CanConvert(System.Type objectType)
{
var nullableType = Nullable.GetUnderlyingType(objectType);
if (nullableType != null)
{
return nullableType.IsEnum;
}
return objectType.IsEnum;
}
public override bool CanRead => true;

View File

@@ -16,8 +16,16 @@ namespace PlexAPI.Utils
internal class IsoDateTimeSerializer: JsonConverter
{
public override bool CanConvert(Type objectType) =>
objectType == typeof(DateTime);
public override bool CanConvert(Type objectType)
{
var nullableType = Nullable.GetUnderlyingType(objectType);
if (nullableType != null)
{
return nullableType == typeof(DateTime);
}
return objectType == typeof(DateTime);
}
public override bool CanRead => false;

View File

@@ -22,11 +22,23 @@ namespace PlexAPI.Utils
public static HttpContent? Serialize(
object? request,
string requestFieldName,
string serializationMethod
string serializationMethod,
bool nullable = false,
bool optional = false,
string format = ""
)
{
if (request == null)
{
if (!nullable && !optional)
{
throw new ArgumentNullException("request body is required");
}
else if (nullable && serializationMethod == "json")
{
return new StringContent("null", Encoding.UTF8, "application/json");
}
return null;
}
@@ -56,14 +68,15 @@ namespace PlexAPI.Utils
}
// Not an object or flattened request
return TrySerialize(request, requestFieldName, serializationMethod);
return TrySerialize(request, requestFieldName, serializationMethod, "", format);
}
private static HttpContent? TrySerialize(
object request,
string requestFieldName,
string serializationMethod,
string mediaType = ""
string mediaType = "",
string format = ""
)
{
if (mediaType == "")
@@ -81,7 +94,7 @@ namespace PlexAPI.Utils
switch (serializationMethod)
{
case "json":
return SerializeJson(request, mediaType);
return SerializeJson(request, mediaType, format);
case "form":
return SerializeForm(request, requestFieldName, mediaType);
case "multipart":
@@ -109,9 +122,9 @@ namespace PlexAPI.Utils
}
}
private static HttpContent SerializeJson(object request, string mediaType)
private static HttpContent SerializeJson(object request, string mediaType, string format = "")
{
return new StringContent(Utilities.SerializeJSON(request), Encoding.UTF8, mediaType);
return new StringContent(Utilities.SerializeJSON(request, format), Encoding.UTF8, mediaType);
}
private static HttpContent SerializeForm(
@@ -482,7 +495,7 @@ namespace PlexAPI.Utils
{
form[fieldName] = new List<string>();
}
form[fieldName].Add(Utilities.ValueToString(value));
}
}
@@ -499,4 +512,4 @@ namespace PlexAPI.Utils
}
}
}
}
}

View File

@@ -16,8 +16,14 @@ namespace PlexAPI.Utils
internal static class SecuritySerializer
{
public static ISpeakeasyHttpClient Apply(ISpeakeasyHttpClient client, object security)
public static ISpeakeasyHttpClient Apply(ISpeakeasyHttpClient client, Func<object> securitySource)
{
if (securitySource == null)
{
return client;
}
var security = securitySource();
if (security == null)
{
return client;

View File

@@ -15,24 +15,52 @@ namespace PlexAPI.Utils
using System.Net.Http.Headers;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Numerics;
using Newtonsoft.Json;
using NodaTime;
using System.Collections;
public class Utilities
{
public static string SerializeJSON(object obj)
public static JsonConverter[] GetJsonConverters(Type type, string format = "")
{
if (format == "string")
{
if (type == typeof(BigInteger))
{
return new JsonConverter[] { new BigIntSerializer() };
}
if (type == typeof(Decimal))
{
return new JsonConverter[] { new DecimalSerializer() };
}
}
return new JsonConverter[]
{
new IsoDateTimeSerializer(),
new EnumSerializer(),
};
}
public static string SerializeJSON(object obj, string format = "")
{
var type = obj.GetType();
if (IsList(obj))
{
type = type.GetGenericArguments().Single();
}
else if (IsDictionary(obj))
{
type = type.GetGenericArguments().Last();
}
return JsonConvert.SerializeObject(
obj,
new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore,
Converters = new JsonConverter[]
{
new IsoDateTimeSerializer(),
new EnumSerializer()
}
Converters = GetJsonConverters(type, format)
}
);
}
@@ -82,11 +110,11 @@ namespace PlexAPI.Utils
}
}
public static bool IsPrimitive(object obj) => obj != null && obj.GetType().IsPrimitive;
public static bool IsPrimitive(object? obj) => obj != null && obj.GetType().IsPrimitive;
public static bool IsEnum(object obj) => obj != null && obj.GetType().IsEnum;
public static bool IsEnum(object? obj) => obj != null && obj.GetType().IsEnum;
public static bool IsDate(object obj) =>
public static bool IsDate(object? obj) =>
obj != null && (obj.GetType() == typeof(DateTime) || obj.GetType() == typeof(LocalDate));
private static string StripSurroundingQuotes(string input)
@@ -238,4 +266,4 @@ namespace PlexAPI.Utils
return template;
}
}
}
}