Skip to content

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

@codecov
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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@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.

2 participants