Skip to content

Replace API for change tracking with NSwag to support atomic operations #1684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2025

Conversation

bkoelman
Copy link
Member

@bkoelman bkoelman commented Feb 22, 2025

This PR replaces the WithPartialAttributeSerialization extension method to support partial POST/PATCH with a new API, TrackChangesFor, which directly operates on the request document. This makes it possible to use partial updates in atomic:operations requests.

Example usage:

var updatePersonRequest = new UpdatePersonRequestDocument
{
    Data = new DataInUpdatePersonRequest
    {
        Id = "1",
        // Using TrackChangesFor to send "firstName: null" instead of omitting it.
        Attributes = new TrackChangesFor<AttributesInUpdatePersonRequest>(_apiClient)
        {
            Initializer =
            {
                FirstName = null,
                LastName = "Doe"
            }
        }.Initializer
    }
};

await ApiResponse.TranslateAsync(async () =>
    await _apiClient.PatchPersonAsync(updatePersonRequest.Data.Id, updatePersonRequest));
}

To accomplish this, the JsonApiDotNetCore.OpenApi.Client.NSwag package now includes custom NSwag liquid templates. It abuses the Prism class style to intercept INotifyPropertyChanged. Preliminary support for resource inheritance is included for upcoming changes.

Shipping liquid templates enables us to auto-generate the partial class to initialize JSON:API, so users can skip that step.

Closes #1577, closes #1673.

QUALITY CHECKLIST

Copy link

codecov bot commented Feb 22, 2025

Codecov Report

Attention: Patch coverage is 90.84967% with 14 lines in your changes missing coverage. Please review.

Project coverage is 90.40%. Comparing base (cdc6962) to head (fd1f6c4).

Files with missing lines Patch % Lines
...pi.Client.NSwag/BlockedJsonInheritanceConverter.cs 41.66% 7 Missing ⚠️
...piDotNetCore.OpenApi.Client.NSwag/JsonApiClient.cs 94.53% 2 Missing and 5 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           openapi    #1684      +/-   ##
===========================================
- Coverage    90.41%   90.40%   -0.01%     
===========================================
  Files          458      461       +3     
  Lines        13984    14043      +59     
  Branches      2177     2190      +13     
===========================================
+ Hits         12643    12695      +52     
- Misses         910      913       +3     
- Partials       431      435       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bkoelman bkoelman marked this pull request as ready for review February 22, 2025 13:19
@bkoelman bkoelman force-pushed the refactor-nswag-client branch from 120ae1b to fd1f6c4 Compare February 22, 2025 14:27
@bkoelman bkoelman merged commit e8e3093 into openapi Feb 22, 2025
16 checks passed
@bkoelman bkoelman deleted the refactor-nswag-client branch February 22, 2025 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant