Table of Contents

Class JsonApiClient

Namespace
JsonApiDotNetCore.OpenApi.Client.NSwag
Assembly
JsonApiDotNetCore.OpenApi.Client.NSwag.dll

Base class to inherit auto-generated NSwag OpenAPI clients from. Provides support for partial POST/PATCH in JSON:API requests, optionally combined with OpenAPI inheritance.

[PublicAPI]
public abstract class JsonApiClient
Inheritance
JsonApiClient
Inherited Members

Properties

AutoClearTracked

Whether to automatically clear tracked properties after sending a request. Default value: true. Set to false to reuse tracked properties for multiple requests and call ClearAllTracked() after the last request to clean up.

public bool AutoClearTracked { get; set; }

Property Value

bool

Methods

ClearAllTracked()

Clears all tracked properties. Call this after sending multiple requests when AutoClearTracked is set to false.

public void ClearAllTracked()

MarkAsTracked(INotifyPropertyChanged, params string[])

Marks the specified properties on an object instance as tracked. Use this when unable to use inline initializer syntax for tracking.

public void MarkAsTracked(INotifyPropertyChanged container, params string[] propertyNames)

Parameters

container INotifyPropertyChanged

The object instance whose properties to mark as tracked.

propertyNames string[]

The names of the properties to mark as tracked. Properties in this list are always included. Any other property is only included if its value differs from the property type's default value.

SetSerializerSettingsForJsonApi(JsonSerializerSettings)

Initial setup. Call this from the Initialize partial method in the auto-generated NSwag client.

protected void SetSerializerSettingsForJsonApi(JsonSerializerSettings serializerSettings)

Parameters

serializerSettings JsonSerializerSettings

The Newtonsoft.Json.JsonSerializerSettings to configure.

Remarks

CAUTION: Calling this method makes the serializer stateful, which removes thread-safety of the owning auto-generated NSwag client. As a result, the client MUST NOT be shared. So don't use a static instance, and don't register as a singleton in the service container. Also, do not execute parallel requests on the same NSwag client instance. Executing multiple sequential requests on the same generated client instance is fine.