diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3fd6ca1..4a81ad7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,14 @@ name: CI on: push: - branches-ignore: - - 'generated' - - 'codegen/**' - - 'integrated/**' - - 'stl-preview-head/**' - - 'stl-preview-base/**' + branches: + - '**' + - '!integrated/**' + - '!stl-preview-head/**' + - '!stl-preview-base/**' + - '!generated' + - '!codegen/**' + - 'codegen/stl/**' pull_request: branches-ignore: - 'stl-preview-head/**' @@ -17,13 +19,13 @@ jobs: timeout-minutes: 10 name: lint runs-on: ${{ github.repository == 'stainless-sdks/api-dental-pro-csharp' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} - if: github.event_name == 'push' || github.event.pull_request.head.repo.fork + if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Set up .NET - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@55ec9447dda3d1cf6bd587150f3262f30ee10815 # v3.4.2 with: dotnet-version: '8.0.x' @@ -36,13 +38,13 @@ jobs: timeout-minutes: 10 name: build runs-on: ${{ github.repository == 'stainless-sdks/api-dental-pro-csharp' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} - if: github.event_name == 'push' || github.event.pull_request.head.repo.fork + if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Set up .NET - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@55ec9447dda3d1cf6bd587150f3262f30ee10815 # v3.4.2 with: dotnet-version: '8.0.x' @@ -55,10 +57,10 @@ jobs: runs-on: ${{ github.repository == 'stainless-sdks/api-dental-pro-csharp' && 'depot-windows-2022' || 'windows-latest' }} if: github.event_name == 'push' || github.event.pull_request.head.repo.fork steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Set up .NET - uses: actions/setup-dotnet@v5 + uses: actions/setup-dotnet@c2fa09f4bde5ebb9d1777cf28262a3eb3db3ced7 # v5.2.0 with: dotnet-version: '8.0.x' diff --git a/.github/workflows/publish-nuget.yml b/.github/workflows/publish-nuget.yml index 3f328ba..a3043d4 100644 --- a/.github/workflows/publish-nuget.yml +++ b/.github/workflows/publish-nuget.yml @@ -12,10 +12,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Set up .NET - uses: actions/setup-dotnet@v5 + uses: actions/setup-dotnet@c2fa09f4bde5ebb9d1777cf28262a3eb3db3ced7 # v5.2.0 with: dotnet-version: '8.0.x' diff --git a/.gitignore b/.gitignore index cb0f784..1ce7f84 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .prism.log +.stdy.log bin/ obj/ .vs/ diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 4208b5c..1b77f50 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.6.0" + ".": "0.7.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index bc84e50..cec13d5 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 3 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/velocitys3%2Fapi-dental-pro-d7d63efc6c52d056de2c33d52c5e447da05558069adee45c65b01edd0bd1788c.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/velocitys3/api-dental-pro-331b628a571f60efd1e47614a49095ad5abefac2d83c958464f5f24132a31082.yml openapi_spec_hash: 5660fa0723e9da2c6d2dc12e893ce3dc config_hash: b371739ff56067c75874a694203404de diff --git a/CHANGELOG.md b/CHANGELOG.md index 41c0c1f..af98cfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,30 @@ # Changelog +## 0.7.0 (2026-05-13) + +Full Changelog: [v0.6.0...v0.7.0](https://github.com/api-dental/api-dental-pro-csharp/compare/v0.6.0...v0.7.0) + +### Features + +* **client:** enable gzip decompression ([28a0428](https://github.com/api-dental/api-dental-pro-csharp/commit/28a042808c79875fafb7b5962bc65395b1f178f6)) +* support setting headers via env ([d9a086c](https://github.com/api-dental/api-dental-pro-csharp/commit/d9a086cec7ca67bcf0bebc7079c07b9c6c0e8884)) + + +### Bug Fixes + +* **client:** allow cancelling when enumerating over an http response ([64c8d16](https://github.com/api-dental/api-dental-pro-csharp/commit/64c8d16ae1585b38f24f06d23de377a6f7ce6959)) +* **client:** handle root bodies in requests properly ([6e7339b](https://github.com/api-dental/api-dental-pro-csharp/commit/6e7339bb0bbcedcc534a1567a32ed4d64b7edd33)) +* **docs:** make xml syntactically correct ([dfe612c](https://github.com/api-dental/api-dental-pro-csharp/commit/dfe612c869be928316e00bbc3d500dfce79823bd)) +* **internal:** disable default HttpClient timeout as we have our own ([fa2eb23](https://github.com/api-dental/api-dental-pro-csharp/commit/fa2eb2348f1f1e9ccddef6c2d49b05f99c644a0e)) +* **tests:** round-trip urls correctly ([06fb914](https://github.com/api-dental/api-dental-pro-csharp/commit/06fb914acf21a2dd230cb32ead201db856792dad)) + + +### Chores + +* **ci:** skip lint on metadata-only changes ([b7b69d4](https://github.com/api-dental/api-dental-pro-csharp/commit/b7b69d483b2c767749617e0af05880b4eb227891)) +* **internal:** tweak CI branches ([aff0c12](https://github.com/api-dental/api-dental-pro-csharp/commit/aff0c128246e68eebd71a1fc4dc3388d74a7a62d)) +* **internal:** update gitignore ([3d69bda](https://github.com/api-dental/api-dental-pro-csharp/commit/3d69bda70b5295832c20fde7af1edf84c3618e50)) + ## 0.6.0 (2026-03-15) Full Changelog: [v0.5.0...v0.6.0](https://github.com/api-dental/api-dental-pro-csharp/compare/v0.5.0...v0.6.0) diff --git a/src/ApiDentalPro.Tests/Models/ClearCoverage/ClearCoverageRequestParamsTest.cs b/src/ApiDentalPro.Tests/Models/ClearCoverage/ClearCoverageRequestParamsTest.cs index c2d1b4f..527af06 100644 --- a/src/ApiDentalPro.Tests/Models/ClearCoverage/ClearCoverageRequestParamsTest.cs +++ b/src/ApiDentalPro.Tests/Models/ClearCoverage/ClearCoverageRequestParamsTest.cs @@ -140,7 +140,7 @@ public void Url_Works() var url = parameters.Url(new() { ApiKey = "My API Key" }); - Assert.Equal(new Uri("https://wg.api.dental/rest/ClearCoverage"), url); + Assert.True(TestBase.UrisEqual(new Uri("https://wg.api.dental/rest/ClearCoverage"), url)); } [Fact] diff --git a/src/ApiDentalPro.Tests/Models/Eligibility/EligibilityRequestParamsTest.cs b/src/ApiDentalPro.Tests/Models/Eligibility/EligibilityRequestParamsTest.cs index 93bb53f..9866ba3 100644 --- a/src/ApiDentalPro.Tests/Models/Eligibility/EligibilityRequestParamsTest.cs +++ b/src/ApiDentalPro.Tests/Models/Eligibility/EligibilityRequestParamsTest.cs @@ -128,7 +128,7 @@ public void Url_Works() var url = parameters.Url(new() { ApiKey = "My API Key" }); - Assert.Equal(new Uri("https://wg.api.dental/rest/Eligibility"), url); + Assert.True(TestBase.UrisEqual(new Uri("https://wg.api.dental/rest/Eligibility"), url)); } [Fact] diff --git a/src/ApiDentalPro.Tests/TestBase.cs b/src/ApiDentalPro.Tests/TestBase.cs index 2054183..db2fd27 100644 --- a/src/ApiDentalPro.Tests/TestBase.cs +++ b/src/ApiDentalPro.Tests/TestBase.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using ApiDentalPro; namespace ApiDentalPro.Tests; @@ -16,4 +18,42 @@ public TestBase() ApiKey = "My API Key", }; } + + internal static bool UrisEqual(Uri uri1, Uri uri2) + { + if ( + uri1.Scheme != uri2.Scheme + || uri1.Host != uri2.Host + || uri1.Port != uri2.Port + || uri1.AbsolutePath != uri2.AbsolutePath + ) + { + return false; + } + + var query1 = ParseQueryString(uri1.Query); + var query2 = ParseQueryString(uri2.Query); + + return Enumerable.SequenceEqual(query1, query2); + } + + static SortedDictionary ParseQueryString(string query) + { + var ret = new SortedDictionary(StringComparer.Ordinal); + + if (string.IsNullOrEmpty(query)) + return ret; + + var pairs = query.TrimStart('?').Split(['&'], StringSplitOptions.RemoveEmptyEntries); + + foreach (var pair in pairs) + { + var parts = pair.Split(['&'], 2); + var key = Uri.UnescapeDataString(parts[0]); + var value = parts.Length > 1 ? Uri.UnescapeDataString(parts[1]) : string.Empty; + ret[key] = value; + } + + return ret; + } } diff --git a/src/ApiDentalPro/ApiDentalPro.csproj b/src/ApiDentalPro/ApiDentalPro.csproj index 6a0a4d4..eb6aad0 100644 --- a/src/ApiDentalPro/ApiDentalPro.csproj +++ b/src/ApiDentalPro/ApiDentalPro.csproj @@ -3,7 +3,7 @@ API Dental Pro C# ApiDentalPro - 0.6.0 + 0.7.0 The official .NET library for the API Dental Pro API. Library README.md diff --git a/src/ApiDentalPro/Core/ClientOptions.cs b/src/ApiDentalPro/Core/ClientOptions.cs index aba8a47..5d368ed 100644 --- a/src/ApiDentalPro/Core/ClientOptions.cs +++ b/src/ApiDentalPro/Core/ClientOptions.cs @@ -21,8 +21,16 @@ public record struct ClientOptions() /// /// The HTTP client to use for making requests in the SDK. + /// + /// Note: The HttpClient has a built-in timeout, which defaults to 100 seconds. + /// When passing a custom HttpClient, this timeout may conflict with the SDK's + /// own timeout handler and cause premature cancellation. /// - public HttpClient HttpClient { get; set; } = new(); + public HttpClient HttpClient { get; set; } = + new(new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.Available }) + { + Timeout = global::System.Threading.Timeout.InfiniteTimeSpan, + }; Lazy _baseUrl = new(() => Environment.GetEnvironmentVariable("API_DENTAL_PRO_BASE_URL") ?? EnvironmentUrl.Production diff --git a/src/ApiDentalPro/Core/DecompressionMethods.cs b/src/ApiDentalPro/Core/DecompressionMethods.cs new file mode 100644 index 0000000..6dfa3ea --- /dev/null +++ b/src/ApiDentalPro/Core/DecompressionMethods.cs @@ -0,0 +1,49 @@ +using System.IO; +using System.IO.Compression; +using Net = System.Net; + +namespace ApiDentalPro.Core; + +static class DecompressionMethods +{ + internal static readonly Net::DecompressionMethods Available; + + static DecompressionMethods() + { + try + { + // Minimal valid GZip payload (empty body). + var gzipPayload = new byte[] + { + 0x1f, + 0x8b, + 0x08, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x03, + 0x03, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + }; + using var memoryStream = new MemoryStream(gzipPayload); + using var gzipStream = new GZipStream(memoryStream, CompressionMode.Decompress); + gzipStream.CopyTo(Stream.Null); + Available = Net::DecompressionMethods.GZip; + } + catch + { + Available = Net::DecompressionMethods.None; + } + } +} diff --git a/src/ApiDentalPro/Core/HttpResponse.cs b/src/ApiDentalPro/Core/HttpResponse.cs index d2ad105..4493dbb 100644 --- a/src/ApiDentalPro/Core/HttpResponse.cs +++ b/src/ApiDentalPro/Core/HttpResponse.cs @@ -4,6 +4,7 @@ using System.IO; using System.Net; using System.Net.Http; +using System.Runtime.CompilerServices; using System.Text.Json; using System.Threading.Tasks; using ApiDentalPro.Exceptions; @@ -161,12 +162,17 @@ internal StreamingHttpResponse( this.CancellationToken = response.CancellationToken; } - public IAsyncEnumerable Enumerate(Threading::CancellationToken cancellationToken = default) + public async IAsyncEnumerable Enumerate( + [EnumeratorCancellationAttribute] Threading::CancellationToken cancellationToken = default + ) { using var cts = Threading::CancellationTokenSource.CreateLinkedTokenSource( this.CancellationToken, cancellationToken ); - return this._enumerate(cts.Token); + await foreach (var item in this._enumerate(cts.Token)) + { + yield return item; + } } } diff --git a/src/ApiDentalPro/Core/JsonDictionary.cs b/src/ApiDentalPro/Core/JsonDictionary.cs index 73ddbfa..5d479c0 100644 --- a/src/ApiDentalPro/Core/JsonDictionary.cs +++ b/src/ApiDentalPro/Core/JsonDictionary.cs @@ -11,9 +11,9 @@ namespace ApiDentalPro.Core; /// /// A dictionary that holds JSON data. /// -/// It can be mutated and then frozen once no more mutations are expected. This -/// is useful for allowing the dictionary to be modified by a class's init -/// properties, but then preventing it from being modified afterwards. +/// It can be mutated and then frozen once no more mutations are expected. +/// This is useful for allowing the dictionary to be modified by a class's +/// init properties, but then preventing it from being modified afterwards. /// /// It also caches data deserialization for performance. /// @@ -94,20 +94,7 @@ public T GetNotNullClass(string key) { throw new ApiDentalProInvalidDataException($"'{key}' cannot be absent"); } - T deserialized; - try - { - deserialized = - JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) - ?? throw new ApiDentalProInvalidDataException($"'{key}' cannot be null"); - } - catch (JsonException e) - { - throw new ApiDentalProInvalidDataException( - $"'{key}' must be of type {typeof(T).FullName}", - e - ); - } + T deserialized = WrappedJsonSerializer.GetNotNullClass(element, key); _deserializedData[key] = deserialized; return deserialized; } @@ -123,20 +110,7 @@ public T GetNotNullStruct(string key) { throw new ApiDentalProInvalidDataException($"'{key}' cannot be absent"); } - T deserialized; - try - { - deserialized = - JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) - ?? throw new ApiDentalProInvalidDataException($"'{key}' cannot be null"); - } - catch (JsonException e) - { - throw new ApiDentalProInvalidDataException( - $"'{key}' must be of type {typeof(T).FullName}", - e - ); - } + T deserialized = WrappedJsonSerializer.GetNotNullStruct(element, key); _deserializedData[key] = deserialized; return deserialized; } @@ -153,18 +127,7 @@ public T GetNotNullStruct(string key) _deserializedData[key] = null; return null; } - T? deserialized; - try - { - deserialized = JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); - } - catch (JsonException e) - { - throw new ApiDentalProInvalidDataException( - $"'{key}' must be of type {typeof(T).FullName}", - e - ); - } + T? deserialized = WrappedJsonSerializer.GetNullableClass(element, key); _deserializedData[key] = deserialized; return deserialized; } @@ -181,18 +144,7 @@ public T GetNotNullStruct(string key) _deserializedData[key] = null; return null; } - T? deserialized; - try - { - deserialized = JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); - } - catch (JsonException e) - { - throw new ApiDentalProInvalidDataException( - $"'{key}' must be of type {typeof(T).FullName}", - e - ); - } + T? deserialized = WrappedJsonSerializer.GetNullableStruct(element, key); _deserializedData[key] = deserialized; return deserialized; } diff --git a/src/ApiDentalPro/Core/MultipartJsonDictionary.cs b/src/ApiDentalPro/Core/MultipartJsonDictionary.cs index 6e6cf5c..cc9d228 100644 --- a/src/ApiDentalPro/Core/MultipartJsonDictionary.cs +++ b/src/ApiDentalPro/Core/MultipartJsonDictionary.cs @@ -11,9 +11,9 @@ namespace ApiDentalPro.Core; /// /// A dictionary that holds mixed JSON and binary content. /// -/// It can be mutated and then frozen once no more mutations are expected. This -/// is useful for allowing the dictionary to be modified by a class's init -/// properties, but then preventing it from being modified afterwards. +/// It can be mutated and then frozen once no more mutations are expected. +/// This is useful for allowing the dictionary to be modified by a class's +/// init properties, but then preventing it from being modified afterwards. /// /// It also caches data deserialization for performance. /// @@ -97,20 +97,7 @@ public T GetNotNullClass(string key) { throw new ApiDentalProInvalidDataException($"'{key}' cannot be absent"); } - T deserialized; - try - { - deserialized = - MultipartJsonSerializer.Deserialize(element, ModelBase.SerializerOptions) - ?? throw new ApiDentalProInvalidDataException($"'{key}' cannot be null"); - } - catch (JsonException e) - { - throw new ApiDentalProInvalidDataException( - $"'{key}' must be of type {typeof(T).FullName}", - e - ); - } + T? deserialized = WrappedMultipartJsonSerializer.GetNotNullClass(element, key); _deserializedData[key] = deserialized; return deserialized; } @@ -126,20 +113,7 @@ public T GetNotNullStruct(string key) { throw new ApiDentalProInvalidDataException($"'{key}' cannot be absent"); } - T deserialized; - try - { - deserialized = - MultipartJsonSerializer.Deserialize(element, ModelBase.SerializerOptions) - ?? throw new ApiDentalProInvalidDataException($"'{key}' cannot be null"); - } - catch (JsonException e) - { - throw new ApiDentalProInvalidDataException( - $"'{key}' must be of type {typeof(T).FullName}", - e - ); - } + T deserialized = WrappedMultipartJsonSerializer.GetNotNullStruct(element, key); _deserializedData[key] = deserialized; return deserialized; } @@ -156,21 +130,7 @@ public T GetNotNullStruct(string key) _deserializedData[key] = null; return null; } - T? deserialized; - try - { - deserialized = MultipartJsonSerializer.Deserialize( - element, - ModelBase.SerializerOptions - ); - } - catch (JsonException e) - { - throw new ApiDentalProInvalidDataException( - $"'{key}' must be of type {typeof(T).FullName}", - e - ); - } + T? deserialized = WrappedMultipartJsonSerializer.GetNullableClass(element, key); _deserializedData[key] = deserialized; return deserialized; } @@ -187,21 +147,7 @@ public T GetNotNullStruct(string key) _deserializedData[key] = null; return null; } - T? deserialized; - try - { - deserialized = MultipartJsonSerializer.Deserialize( - element, - ModelBase.SerializerOptions - ); - } - catch (JsonException e) - { - throw new ApiDentalProInvalidDataException( - $"'{key}' must be of type {typeof(T).FullName}", - e - ); - } + T? deserialized = WrappedMultipartJsonSerializer.GetNullableStruct(element, key); _deserializedData[key] = deserialized; return deserialized; } diff --git a/src/ApiDentalPro/Core/ParamsBase.cs b/src/ApiDentalPro/Core/ParamsBase.cs index 6468f58..7f339f6 100644 --- a/src/ApiDentalPro/Core/ParamsBase.cs +++ b/src/ApiDentalPro/Core/ParamsBase.cs @@ -18,7 +18,7 @@ public abstract record class ParamsBase static ParamsBase() { var runtime = GetRuntime(); - defaultHeaders = new Dictionary + var headers = new Dictionary { ["User-Agent"] = GetUserAgent(), ["X-Stainless-Arch"] = GetOSArch(), @@ -28,6 +28,21 @@ static ParamsBase() ["X-Stainless-Runtime"] = runtime.Name, ["X-Stainless-Runtime-Version"] = runtime.Version, }; + + var customHeadersEnv = Environment.GetEnvironmentVariable("API_DENTAL_PRO_CUSTOM_HEADERS"); + if (customHeadersEnv != null) + { + foreach (var line in customHeadersEnv.Split('\n')) + { + var colon = line.IndexOf(':'); + if (colon >= 0) + { + headers[line.Substring(0, colon).Trim()] = line.Substring(colon + 1).Trim(); + } + } + } + + defaultHeaders = headers; } private protected JsonDictionary _rawQueryData = new(); diff --git a/src/ApiDentalPro/Core/WrappedJsonSerializer.cs b/src/ApiDentalPro/Core/WrappedJsonSerializer.cs new file mode 100644 index 0000000..02e613f --- /dev/null +++ b/src/ApiDentalPro/Core/WrappedJsonSerializer.cs @@ -0,0 +1,87 @@ +using System.Text.Json; +using ApiDentalPro.Exceptions; + +namespace ApiDentalPro.Core; + +/// +/// Helper class for deserializing <c>JsonElement</c> objects. This handles +/// edge-cases around nullability and reference/value types. +/// +sealed class WrappedJsonSerializer +{ + public static T GetNotNullClass(JsonElement element, string name) + where T : class + { + T deserialized; + try + { + deserialized = + JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) + ?? throw new ApiDentalProInvalidDataException($"'{name}' cannot be null"); + } + catch (JsonException e) + { + throw new ApiDentalProInvalidDataException( + $"'{name}' must be of type {typeof(T).FullName}", + e + ); + } + return deserialized; + } + + public static T GetNotNullStruct(JsonElement element, string name) + where T : struct + { + T deserialized; + try + { + deserialized = + JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) + ?? throw new ApiDentalProInvalidDataException($"'{name}' cannot be null"); + } + catch (JsonException e) + { + throw new ApiDentalProInvalidDataException( + $"'{name}' must be of type {typeof(T).FullName}", + e + ); + } + return deserialized; + } + + public static T? GetNullableClass(JsonElement element, string name) + where T : class + { + T? deserialized; + try + { + deserialized = JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + } + catch (JsonException e) + { + throw new ApiDentalProInvalidDataException( + $"'{name}' must be of type {typeof(T).FullName}", + e + ); + } + return deserialized; + } + + public static T? GetNullableStruct(JsonElement element, string name) + where T : struct + { + T? deserialized; + try + { + deserialized = JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + } + catch (JsonException e) + { + throw new ApiDentalProInvalidDataException( + $"'{name}' must be of type {typeof(T).FullName}", + e + ); + } + return deserialized; + } +} diff --git a/src/ApiDentalPro/Core/WrappedMultipartJsonSerializer.cs b/src/ApiDentalPro/Core/WrappedMultipartJsonSerializer.cs new file mode 100644 index 0000000..65787bd --- /dev/null +++ b/src/ApiDentalPro/Core/WrappedMultipartJsonSerializer.cs @@ -0,0 +1,93 @@ +using System.Text.Json; +using ApiDentalPro.Exceptions; + +namespace ApiDentalPro.Core; + +/// +/// Helper class for deserializing <c>MultipartJsonElement</c> objects. +/// This handles edge-cases around nullability and reference/value types. +/// +sealed class WrappedMultipartJsonSerializer +{ + public static T GetNotNullClass(MultipartJsonElement element, string name) + where T : class + { + T deserialized; + try + { + deserialized = + MultipartJsonSerializer.Deserialize(element, ModelBase.SerializerOptions) + ?? throw new ApiDentalProInvalidDataException($"'{name}' cannot be null"); + } + catch (JsonException e) + { + throw new ApiDentalProInvalidDataException( + $"'{name}' must be of type {typeof(T).FullName}", + e + ); + } + return deserialized; + } + + public static T GetNotNullStruct(MultipartJsonElement element, string name) + where T : struct + { + T deserialized; + try + { + deserialized = + MultipartJsonSerializer.Deserialize(element, ModelBase.SerializerOptions) + ?? throw new ApiDentalProInvalidDataException($"'{name}' cannot be null"); + } + catch (JsonException e) + { + throw new ApiDentalProInvalidDataException( + $"'{name}' must be of type {typeof(T).FullName}", + e + ); + } + return deserialized; + } + + public static T? GetNullableClass(MultipartJsonElement element, string name) + where T : class + { + T? deserialized; + try + { + deserialized = MultipartJsonSerializer.Deserialize( + element, + ModelBase.SerializerOptions + ); + } + catch (JsonException e) + { + throw new ApiDentalProInvalidDataException( + $"'{name}' must be of type {typeof(T).FullName}", + e + ); + } + return deserialized; + } + + public static T? GetNullableStruct(MultipartJsonElement element, string name) + where T : struct + { + T? deserialized; + try + { + deserialized = MultipartJsonSerializer.Deserialize( + element, + ModelBase.SerializerOptions + ); + } + catch (JsonException e) + { + throw new ApiDentalProInvalidDataException( + $"'{name}' must be of type {typeof(T).FullName}", + e + ); + } + return deserialized; + } +} diff --git a/src/ApiDentalPro/Models/ClearCoverage/ClearCoverageRequestParams.cs b/src/ApiDentalPro/Models/ClearCoverage/ClearCoverageRequestParams.cs index c023959..48774cc 100644 --- a/src/ApiDentalPro/Models/ClearCoverage/ClearCoverageRequestParams.cs +++ b/src/ApiDentalPro/Models/ClearCoverage/ClearCoverageRequestParams.cs @@ -152,7 +152,7 @@ FrozenDictionary rawBodyData } #pragma warning restore CS8618 - /// + /// public static ClearCoverageRequestParams FromRawUnchecked( IReadOnlyDictionary rawHeaderData, IReadOnlyDictionary rawQueryData, diff --git a/src/ApiDentalPro/Models/Eligibility/EligibilityRequestParams.cs b/src/ApiDentalPro/Models/Eligibility/EligibilityRequestParams.cs index 9bd66c5..145277e 100644 --- a/src/ApiDentalPro/Models/Eligibility/EligibilityRequestParams.cs +++ b/src/ApiDentalPro/Models/Eligibility/EligibilityRequestParams.cs @@ -131,7 +131,7 @@ FrozenDictionary rawBodyData } #pragma warning restore CS8618 - /// + /// public static EligibilityRequestParams FromRawUnchecked( IReadOnlyDictionary rawHeaderData, IReadOnlyDictionary rawQueryData, diff --git a/src/ApiDentalPro/Models/Payer/PayerListParams.cs b/src/ApiDentalPro/Models/Payer/PayerListParams.cs index 1fe414b..0dd1b13 100644 --- a/src/ApiDentalPro/Models/Payer/PayerListParams.cs +++ b/src/ApiDentalPro/Models/Payer/PayerListParams.cs @@ -48,7 +48,7 @@ FrozenDictionary rawQueryData } #pragma warning restore CS8618 - /// + /// public static PayerListParams FromRawUnchecked( IReadOnlyDictionary rawHeaderData, IReadOnlyDictionary rawQueryData diff --git a/src/ApiDentalPro/Services/IClearCoverageService.cs b/src/ApiDentalPro/Services/IClearCoverageService.cs index 3ea821d..ceebb51 100644 --- a/src/ApiDentalPro/Services/IClearCoverageService.cs +++ b/src/ApiDentalPro/Services/IClearCoverageService.cs @@ -28,8 +28,8 @@ public interface IClearCoverageService /// /// Submit an enhanced eligibility and benefits verification request via Vyne - /// ClearCoverage. Returns enriched, standardized, and normalized data relevant - /// for dental use cases with deep benefit insights across supported payers. + /// ClearCoverage. Returns enriched, standardized, and normalized data relevant for + /// dental use cases with deep benefit insights across supported payers. /// Task Request( ClearCoverageRequestParams parameters, @@ -51,7 +51,7 @@ public interface IClearCoverageServiceWithRawResponse IClearCoverageServiceWithRawResponse WithOptions(Func modifier); /// - /// Returns a raw HTTP response for `post /ClearCoverage`, but is otherwise the + /// Returns a raw HTTP response for post /ClearCoverage, but is otherwise the /// same as . /// Task> Request( diff --git a/src/ApiDentalPro/Services/IEligibilityService.cs b/src/ApiDentalPro/Services/IEligibilityService.cs index 34ec11c..952f35a 100644 --- a/src/ApiDentalPro/Services/IEligibilityService.cs +++ b/src/ApiDentalPro/Services/IEligibilityService.cs @@ -51,7 +51,7 @@ public interface IEligibilityServiceWithRawResponse IEligibilityServiceWithRawResponse WithOptions(Func modifier); /// - /// Returns a raw HTTP response for `post /Eligibility`, but is otherwise the + /// Returns a raw HTTP response for post /Eligibility, but is otherwise the /// same as . /// Task> Request( diff --git a/src/ApiDentalPro/Services/IPayerService.cs b/src/ApiDentalPro/Services/IPayerService.cs index 915a283..b302e9c 100644 --- a/src/ApiDentalPro/Services/IPayerService.cs +++ b/src/ApiDentalPro/Services/IPayerService.cs @@ -28,8 +28,8 @@ public interface IPayerService /// /// Retrieve the full list of supported dental insurance payers with their IDs, - /// names, features, and status. No sensitive data is required. Use payer IDs - /// from this list when making Eligibility or ClearCoverage requests. + /// names, features, and status. No sensitive data is required. Use payer IDs from + /// this list when making Eligibility or ClearCoverage requests. /// Task List( PayerListParams? parameters = null, @@ -51,7 +51,7 @@ public interface IPayerServiceWithRawResponse IPayerServiceWithRawResponse WithOptions(Func modifier); /// - /// Returns a raw HTTP response for `get /Payer`, but is otherwise the + /// Returns a raw HTTP response for get /Payer, but is otherwise the /// same as . /// Task> List( diff --git a/src/Directory.Build.props b/src/Directory.Build.props index a2dd19b..f949806 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -12,7 +12,7 @@ true - $(NoWarn),1570,1573,1574,1591 + $(NoWarn),1573,1591 true