Interface IJsonApiOptions
- Namespace
- JsonApiDotNetCore.Configuration
- Assembly
- JsonApiDotNetCore.dll
Global options that configure the behavior of JsonApiDotNetCore.
public interface IJsonApiOptions
Properties
AllowClientGeneratedIds
Whether clients can provide IDs when creating resources. When not allowed, a 403 Forbidden response is returned if a client attempts to create a
resource with a defined ID. false
by default.
[PublicAPI]
[Obsolete("Use ClientIdGeneration instead.")]
bool AllowClientGeneratedIds { get; }
Property Value
Remarks
AllowUnknownFieldsInRequestBody
Whether to produce an error on unknown attribute and relationship keys in request bodies. false
by default.
bool AllowUnknownFieldsInRequestBody { get; }
Property Value
AllowUnknownQueryStringParameters
Whether to produce an error on unknown query string parameters. false
by default.
bool AllowUnknownQueryStringParameters { get; }
Property Value
ClientIdGeneration
Whether clients are allowed or required to provide IDs when creating resources. Forbidden by default. This setting can be overruled per resource type using ClientIdGeneration.
ClientIdGenerationMode ClientIdGeneration { get; }
Property Value
DefaultAttrCapabilities
Specifies the default set of allowed capabilities on JSON:API attributes. Defaults to All. This setting can be overruled per attribute using Capabilities.
AttrCapabilities DefaultAttrCapabilities { get; }
Property Value
DefaultHasManyCapabilities
Specifies the default set of allowed capabilities on JSON:API to-many relationships. Defaults to All. This setting can be overruled per relationship using Capabilities.
HasManyCapabilities DefaultHasManyCapabilities { get; }
Property Value
DefaultHasOneCapabilities
Specifies the default set of allowed capabilities on JSON:API to-one relationships. Defaults to All. This setting can be overruled per relationship using Capabilities.
HasOneCapabilities DefaultHasOneCapabilities { get; }
Property Value
DefaultPageSize
The page size (10 by default) that is used when not specified in query string. Set to null
to not use pagination by default.
PageSize? DefaultPageSize { get; }
Property Value
EnableLegacyFilterNotation
Determines whether legacy filter notation in query strings (such as =eq:, =like:, and =in:) is enabled. false
by default.
bool EnableLegacyFilterNotation { get; }
Property Value
Extensions
Lists the JSON:API extensions that are turned on. Empty by default, but if your project contains a controller that derives from BaseJsonApiOperationsController, the AtomicOperations and RelaxedAtomicOperations extensions are automatically added.
IReadOnlySet<JsonApiMediaTypeExtension> Extensions { get; }
Property Value
Remarks
To implement a custom JSON:API extension, add it here and override GetPossibleMediaTypes() to indicate which combinations of extensions are available, depending on the current endpoint. Use Extensions to obtain the active extensions when implementing extension-specific logic.
IncludeExceptionStackTraceInErrors
bool IncludeExceptionStackTraceInErrors { get; }
Property Value
IncludeJsonApiVersion
Whether to include a 'jsonapi' object in responses, which contains the highest JSON:API version supported. false
by default.
bool IncludeJsonApiVersion { get; }
Property Value
IncludeRequestBodyInErrors
Whether to include the request body in Meta responses when it is invalid. false
by default.
bool IncludeRequestBodyInErrors { get; }
Property Value
IncludeTotalResourceCount
Whether to include the total resource count in top-level meta objects. This requires an additional database query. false
by default.
bool IncludeTotalResourceCount { get; }
Property Value
MaximumIncludeDepth
Controls how many levels deep includes are allowed to be nested. For example, MaximumIncludeDepth=1 would allow ?include=articles but not
?include=articles.revisions. null
by default, which means unconstrained.
int? MaximumIncludeDepth { get; }
Property Value
- int?
MaximumOperationsPerRequest
Limits the maximum number of operations allowed per atomic:operations request. Defaults to 10. Set to null
for unlimited.
int? MaximumOperationsPerRequest { get; }
Property Value
- int?
MaximumPageNumber
The maximum page number that can be used, or null
for unconstrained (default).
PageNumber? MaximumPageNumber { get; }
Property Value
MaximumPageSize
The maximum page size that can be used, or null
for unconstrained (default).
PageSize? MaximumPageSize { get; }
Property Value
Namespace
The URL prefix to use for exposed endpoints.
string? Namespace { get; }
Property Value
Examples
options.Namespace = "api/shopping";
RelationshipLinks
Configures which links to write in the RelationshipLinks object. Defaults to All. This setting can be overruled for all relationships per resource type by adding ResourceLinksAttribute on the class definition of a resource. This can be further overruled per relationship by setting Links.
LinkTypes RelationshipLinks { get; }
Property Value
ResourceLinks
Configures which links to write in the ResourceLinks object. Defaults to All. This setting can be overruled per resource type by adding ResourceLinksAttribute on the class definition of a resource.
LinkTypes ResourceLinks { get; }
Property Value
SerializerOptions
Enables to customize the settings that are used by the JsonSerializer.
JsonSerializerOptions SerializerOptions { get; }
Property Value
Examples
The next example sets the naming convention to camel casing.
options.SerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
options.SerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase;
SerializerReadOptions
Gets the settings used for deserializing request bodies. This value is based on SerializerOptions and is intended for internal use.
JsonSerializerOptions SerializerReadOptions { get; }
Property Value
SerializerWriteOptions
Gets the settings used for serializing response bodies. This value is based on SerializerOptions and is intended for internal use.
JsonSerializerOptions SerializerWriteOptions { get; }
Property Value
TopLevelLinks
Configures which links to write in the TopLevelLinks object. Defaults to All. This setting can be overruled per resource type by adding ResourceLinksAttribute on the class definition of a resource.
LinkTypes TopLevelLinks { get; }
Property Value
TransactionIsolationLevel
Enables to override the default isolation level for database transactions, enabling to balance between consistency and performance. Defaults to
null
, which leaves this up to Entity Framework Core to choose (and then it varies per database provider).
IsolationLevel? TransactionIsolationLevel { get; }
Property Value
UseRelativeLinks
Whether to use relative links for all resources. false
by default.
bool UseRelativeLinks { get; }
Property Value
Examples
options.UseRelativeLinks = true;
{
"type": "articles",
"id": "4309",
"relationships": {
"author": {
"links": {
"self": "/api/shopping/articles/4309/relationships/author",
"related": "/api/shopping/articles/4309/author"
}
}
}
}
ValidateModelState
Whether ASP.NET ModelState validation is enabled. true
by default.
bool ValidateModelState { get; }