Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 22a7ec5

Browse files
committed
SDK regeneration
1 parent b83e710 commit 22a7ec5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1289
-152
lines changed

reference.md

Lines changed: 1009 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!--
2+
Configure additional MSBuild properties for your project in this file:
3+
- Step 1: Add this file to your .fernignore file to ensure it is not overwritten.
4+
- Step 2: Modify this file to your liking.
5+
-->
6+
<Project>
7+
<!--
8+
<PropertyGroup>
9+
<Title>Contoso SDK</Title>
10+
<Authors>Contoso</Authors>
11+
<Company>Contoso</Company>
12+
<AssemblyName>Contoso.Sdk</AssemblyName>
13+
<AssemblyTitle>Contoso SDK</AssemblyTitle>
14+
<PackageIcon>icon.png</PackageIcon>
15+
</PropertyGroup>
16+
<ItemGroup>
17+
<None Include="..\..\icon.png" Pack="true" PackagePath="" />
18+
</ItemGroup>
19+
-->
20+
</Project>

src/AssemblyAI/Core/EnumSerializer.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System.Runtime.Serialization;
2+
using System.Text.Json;
3+
using System.Text.Json.Serialization;
4+
5+
namespace AssemblyAI.Core;
6+
7+
internal class EnumSerializer<TEnum> : JsonConverter<TEnum>
8+
where TEnum : struct, System.Enum
9+
{
10+
private readonly Dictionary<TEnum, string> _enumToString = new();
11+
private readonly Dictionary<string, TEnum> _stringToEnum = new();
12+
13+
public EnumSerializer()
14+
{
15+
var type = typeof(TEnum);
16+
var values = Enum.GetValues(type);
17+
18+
foreach (var value in values)
19+
{
20+
var enumValue = (TEnum)value;
21+
var enumMember = type.GetMember(enumValue.ToString())[0];
22+
var attr = enumMember
23+
.GetCustomAttributes(typeof(EnumMemberAttribute), false)
24+
.Cast<EnumMemberAttribute>()
25+
.FirstOrDefault();
26+
27+
var stringValue =
28+
attr?.Value
29+
?? value.ToString()
30+
?? throw new Exception("Unexpected null enum toString value");
31+
32+
_enumToString.Add(enumValue, stringValue);
33+
_stringToEnum.Add(stringValue, enumValue);
34+
}
35+
}
36+
37+
public override TEnum Read(
38+
ref Utf8JsonReader reader,
39+
System.Type typeToConvert,
40+
JsonSerializerOptions options
41+
)
42+
{
43+
var stringValue =
44+
reader.GetString()
45+
?? throw new Exception("The JSON value could not be read as a string.");
46+
return _stringToEnum.TryGetValue(stringValue, out var enumValue) ? enumValue : default;
47+
}
48+
49+
public override void Write(Utf8JsonWriter writer, TEnum value, JsonSerializerOptions options)
50+
{
51+
writer.WriteStringValue(_enumToString[value]);
52+
}
53+
}

src/AssemblyAI/Core/Extensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ namespace AssemblyAI.Core;
44

55
internal static class Extensions
66
{
7-
internal static string Stringify(this Enum value)
7+
public static string Stringify(this Enum value)
88
{
99
var field = value.GetType().GetField(value.ToString());
1010
var attribute = (EnumMemberAttribute)
11-
Attribute.GetCustomAttribute(field!, typeof(EnumMemberAttribute))!;
11+
Attribute.GetCustomAttribute(field, typeof(EnumMemberAttribute));
1212
return attribute?.Value ?? value.ToString();
1313
}
1414
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Net.Http;
3+
4+
#nullable enable
5+
6+
namespace AssemblyAI.Core;
7+
8+
internal interface IRequestOptions
9+
{
10+
/// <summary>
11+
/// The Base URL for the API.
12+
/// </summary>
13+
public string? BaseUrl { get; init; }
14+
15+
/// <summary>
16+
/// The http client used to make requests.
17+
/// </summary>
18+
public HttpClient? HttpClient { get; init; }
19+
20+
/// <summary>
21+
/// The http headers sent with the request.
22+
/// </summary>
23+
internal Headers Headers { get; init; }
24+
25+
/// <summary>
26+
/// The http client used to make requests.
27+
/// </summary>
28+
public int? MaxRetries { get; init; }
29+
30+
/// <summary>
31+
/// The timeout for the request.
32+
/// </summary>
33+
public TimeSpan? Timeout { get; init; }
34+
}

src/AssemblyAI/Core/OneOfSerializer.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66
namespace AssemblyAI.Core;
77

8-
internal class OneOfSerializer<TOneOf> : JsonConverter<TOneOf>
9-
where TOneOf : IOneOf
8+
internal class OneOfSerializer : JsonConverter<IOneOf>
109
{
11-
public override TOneOf? Read(
10+
public override IOneOf? Read(
1211
ref Utf8JsonReader reader,
1312
System.Type typeToConvert,
1413
JsonSerializerOptions options
@@ -17,14 +16,14 @@ JsonSerializerOptions options
1716
if (reader.TokenType is JsonTokenType.Null)
1817
return default;
1918

20-
foreach (var (type, cast) in s_types)
19+
foreach (var (type, cast) in GetOneOfTypes(typeToConvert))
2120
{
2221
try
2322
{
2423
var readerCopy = reader;
2524
var result = JsonSerializer.Deserialize(ref readerCopy, type, options);
2625
reader.Skip();
27-
return (TOneOf)cast.Invoke(null, [result])!;
26+
return (IOneOf)cast.Invoke(null, [result])!;
2827
}
2928
catch (JsonException) { }
3029
}
@@ -34,20 +33,18 @@ JsonSerializerOptions options
3433
);
3534
}
3635

37-
private static readonly (System.Type type, MethodInfo cast)[] s_types = GetOneOfTypes();
38-
39-
public override void Write(Utf8JsonWriter writer, TOneOf value, JsonSerializerOptions options)
36+
public override void Write(Utf8JsonWriter writer, IOneOf value, JsonSerializerOptions options)
4037
{
4138
JsonSerializer.Serialize(writer, value.Value, options);
4239
}
4340

44-
private static (System.Type type, MethodInfo cast)[] GetOneOfTypes()
41+
private static (System.Type type, MethodInfo cast)[] GetOneOfTypes(System.Type typeToConvert)
4542
{
46-
var casts = typeof(TOneOf)
43+
var casts = typeToConvert
4744
.GetRuntimeMethods()
4845
.Where(m => m.IsSpecialName && m.Name == "op_Implicit")
4946
.ToArray();
50-
var type = typeof(TOneOf);
47+
var type = typeToConvert;
5148
while (type != null)
5249
{
5350
if (
@@ -62,6 +59,11 @@ private static (System.Type type, MethodInfo cast)[] GetOneOfTypes()
6259

6360
type = type.BaseType;
6461
}
65-
throw new InvalidOperationException($"{typeof(TOneOf)} isn't OneOf or OneOfBase");
62+
throw new InvalidOperationException($"{type} isn't OneOf or OneOfBase");
63+
}
64+
65+
public override bool CanConvert(System.Type typeToConvert)
66+
{
67+
return typeof(IOneOf).IsAssignableFrom(typeToConvert);
6668
}
6769
}
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
// ReSharper disable CheckNamespace
21
namespace AssemblyAI;
32

4-
/// <summary>
5-
/// Available AssemblyAI API environments
6-
/// </summary>
7-
public static class AssemblyAIClientEnvironment
3+
public class AssemblyAIClientEnvironment
84
{
9-
/// <summary>
10-
/// The default base URL for the AssemblyAI API.
11-
/// </summary>
12-
public const string Default = "https://api.assemblyai.com";
5+
public static string Default = "https://api.assemblyai.com";
136
}
Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
using System;
12
using System.Net.Http;
23
using AssemblyAI.Core;
3-
// ReSharper disable CheckNamespace
4+
5+
#nullable enable
46

57
namespace AssemblyAI;
68

@@ -9,25 +11,40 @@ public partial class ClientOptions
911
/// <summary>
1012
/// The Base URL for the API.
1113
/// </summary>
12-
public string BaseUrl { get; set; } = AssemblyAIClientEnvironment.Default;
14+
public string BaseUrl { get; init; } = AssemblyAIClientEnvironment.Default;
1315

1416
/// <summary>
1517
/// The http client used to make requests.
1618
/// </summary>
17-
public HttpClient HttpClient { get; set; } = new();
19+
public HttpClient HttpClient { get; init; } = new HttpClient();
1820

1921
/// <summary>
20-
/// The amount to retry sending the HTTP request if it fails.
22+
/// The http client used to make requests.
2123
/// </summary>
22-
public int MaxRetries { get; set; } = 2;
24+
public int MaxRetries { get; init; } = 2;
2325

2426
/// <summary>
2527
/// The timeout for the request.
2628
/// </summary>
27-
public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(30);
29+
public TimeSpan Timeout { get; init; } = TimeSpan.FromSeconds(30);
2830

2931
/// <summary>
3032
/// The http headers sent with the request.
3133
/// </summary>
3234
internal Headers Headers { get; init; } = new();
35+
36+
/// <summary>
37+
/// Clones this and returns a new instance
38+
/// </summary>
39+
internal ClientOptions Clone()
40+
{
41+
return new ClientOptions
42+
{
43+
BaseUrl = BaseUrl,
44+
HttpClient = HttpClient,
45+
MaxRetries = MaxRetries,
46+
Timeout = Timeout,
47+
Headers = new Headers(new Dictionary<string, HeaderValue>(Headers)),
48+
};
49+
}
3350
}

src/AssemblyAI/Core/Public/ExtendedClientOptions.cs

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

src/AssemblyAI/Core/Public/ExtendedRequestOptions.cs

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

0 commit comments

Comments
 (0)