diff --git a/src/JsonApiDotNetCore/Builders/IDocumentBuilderOptionsProvider.cs b/src/JsonApiDotNetCore/Builders/IDocumentBuilderOptionsProvider.cs index d8effd4fe3..fe014bced5 100644 --- a/src/JsonApiDotNetCore/Builders/IDocumentBuilderOptionsProvider.cs +++ b/src/JsonApiDotNetCore/Builders/IDocumentBuilderOptionsProvider.cs @@ -1,11 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Text; - namespace JsonApiDotNetCore.Builders { public interface IDocumentBuilderOptionsProvider { - DocumentBuilderOptions GetDocumentBuilderOptions(); + DocumentBuilderOptions GetDocumentBuilderOptions(); } } diff --git a/src/JsonApiDotNetCore/Configuration/NullAttributeResponseBehavior.cs b/src/JsonApiDotNetCore/Configuration/NullAttributeResponseBehavior.cs index 1b10140f5e..125d38b5fc 100644 --- a/src/JsonApiDotNetCore/Configuration/NullAttributeResponseBehavior.cs +++ b/src/JsonApiDotNetCore/Configuration/NullAttributeResponseBehavior.cs @@ -1,19 +1,34 @@ -using System; -using System.Collections.Generic; -using System.Text; - namespace JsonApiDotNetCore.Configuration { + /// + /// Allows null attributes to be ommitted from the response payload + /// public struct NullAttributeResponseBehavior { + /// Do not serialize null attributes + /// + /// Allow clients to override the serialization behavior through a query parmeter. + /// + /// ``` + /// GET /articles?omitNullValuedAttributes=true + /// ``` + /// + /// public NullAttributeResponseBehavior(bool omitNullValuedAttributes = false, bool allowClientOverride = false) { OmitNullValuedAttributes = omitNullValuedAttributes; AllowClientOverride = allowClientOverride; } + /// + /// Do not include null attributes in the response payload. + /// public bool OmitNullValuedAttributes { get; } + + /// + /// Allows clients to specify a `omitNullValuedAttributes` boolean query param to control + /// serialization behavior. + /// public bool AllowClientOverride { get; } - // ... } } diff --git a/src/JsonApiDotNetCore/Models/AttrAttribute.cs b/src/JsonApiDotNetCore/Models/AttrAttribute.cs index db61cb56ea..e38b47abec 100644 --- a/src/JsonApiDotNetCore/Models/AttrAttribute.cs +++ b/src/JsonApiDotNetCore/Models/AttrAttribute.cs @@ -5,6 +5,26 @@ namespace JsonApiDotNetCore.Models { public class AttrAttribute : Attribute { + /// + /// Defines a public attribute exposed by the API + /// + /// + /// How this attribute is exposed through the API + /// Prevent PATCH requests from updating the value + /// Prevent filters on this attribute + /// Prevent this attribute from being sorted by + /// + /// + /// + /// + /// public class Author : Identifiable + /// { + /// [Attr("name")] + /// public string Name { get; set; } + /// } + /// + /// + /// public AttrAttribute(string publicName, bool isImmutable = false, bool isFilterable = true, bool isSortable = true) { PublicAttributeName = publicName; @@ -20,20 +40,51 @@ internal AttrAttribute(string publicName, string internalName, bool isImmutable IsImmutable = isImmutable; } + /// + /// How this attribute is exposed through the API + /// public string PublicAttributeName { get; } + + /// + /// The internal property name this attribute belongs to. + /// public string InternalAttributeName { get; internal set; } + + /// + /// Prevents PATCH requests from updating the value. + /// public bool IsImmutable { get; } + + /// + /// Whether or not this attribute can be filtered on via a query string filters. + /// Attempts to filter on an attribute with `IsFilterable == false` will return + /// an HTTP 400 response. + /// public bool IsFilterable { get; } + + /// + /// Whether or not this attribute can be sorted on via a query string sort. + /// Attempts to filter on an attribute with `IsSortable == false` will return + /// an HTTP 400 response. + /// public bool IsSortable { get; } + /// + /// Get the value of the attribute for the given object. + /// Returns null if the attribute does not belong to the + /// provided object. + /// public object GetValue(object entity) { return entity .GetType() .GetProperty(InternalAttributeName) - .GetValue(entity); + ?.GetValue(entity); } + /// + /// Sets the value of the attribute on the given object. + /// public void SetValue(object entity, object newValue) { var propertyInfo = entity diff --git a/src/JsonApiDotNetCore/Models/HasManyAttribute.cs b/src/JsonApiDotNetCore/Models/HasManyAttribute.cs index c2d7594400..877df29146 100644 --- a/src/JsonApiDotNetCore/Models/HasManyAttribute.cs +++ b/src/JsonApiDotNetCore/Models/HasManyAttribute.cs @@ -2,16 +2,40 @@ namespace JsonApiDotNetCore.Models { public class HasManyAttribute : RelationshipAttribute { + /// + /// Create a HasMany relational link to another entity + /// + /// + /// The relationship name as exposed by the API + /// Which links are available. Defaults to + /// Whether or not this relationship can be included using the ?include=public-name query string + /// + /// + /// + /// + /// public class Author : Identifiable + /// { + /// [HasMany("articles"] + /// public virtual List
Articles { get; set; } + /// } + /// + /// + /// public HasManyAttribute(string publicName, Link documentLinks = Link.All, bool canInclude = true) : base(publicName, documentLinks, canInclude) { } + /// + /// Sets the value of the property identified by this attribute + /// + /// The target object + /// The new property value public override void SetValue(object entity, object newValue) { var propertyInfo = entity .GetType() .GetProperty(InternalRelationshipName); - + propertyInfo.SetValue(entity, newValue); } } diff --git a/src/JsonApiDotNetCore/Services/QueryComposer.cs b/src/JsonApiDotNetCore/Services/QueryComposer.cs index 8e0819a438..e365811704 100644 --- a/src/JsonApiDotNetCore/Services/QueryComposer.cs +++ b/src/JsonApiDotNetCore/Services/QueryComposer.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using JsonApiDotNetCore.Internal.Query; -using Microsoft.Extensions.Logging; namespace JsonApiDotNetCore.Services { @@ -14,8 +13,8 @@ public class QueryComposer : IQueryComposer public string Compose(IJsonApiContext jsonApiContext) { string result = ""; - if(jsonApiContext != null && jsonApiContext.QuerySet != null) - { + if (jsonApiContext != null && jsonApiContext.QuerySet != null) + { List filterQueries = jsonApiContext.QuerySet.Filters; if (filterQueries.Count > 0) {