Skip to content

Commit 4ac497c

Browse files
authoredJun 12, 2018
Merge pull request #298 from json-api-dotnet/docs/xml-documentation
docs(*): add xml comments
2 parents 50cfa8d + 99ce78e commit 4ac497c

File tree

5 files changed

+100
-15
lines changed

5 files changed

+100
-15
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
51
namespace JsonApiDotNetCore.Builders
62
{
73
public interface IDocumentBuilderOptionsProvider
84
{
9-
DocumentBuilderOptions GetDocumentBuilderOptions();
5+
DocumentBuilderOptions GetDocumentBuilderOptions();
106
}
117
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
51
namespace JsonApiDotNetCore.Configuration
62
{
3+
/// <summary>
4+
/// Allows null attributes to be ommitted from the response payload
5+
/// </summary>
76
public struct NullAttributeResponseBehavior
87
{
8+
/// <param name="omitNullValuedAttributes">Do not serialize null attributes</param>
9+
/// <param name="allowClientOverride">
10+
/// Allow clients to override the serialization behavior through a query parmeter.
11+
/// <example>
12+
/// ```
13+
/// GET /articles?omitNullValuedAttributes=true
14+
/// ```
15+
/// </example>
16+
/// </param>
917
public NullAttributeResponseBehavior(bool omitNullValuedAttributes = false, bool allowClientOverride = false)
1018
{
1119
OmitNullValuedAttributes = omitNullValuedAttributes;
1220
AllowClientOverride = allowClientOverride;
1321
}
1422

23+
/// <summary>
24+
/// Do not include null attributes in the response payload.
25+
/// </summary>
1526
public bool OmitNullValuedAttributes { get; }
27+
28+
/// <summary>
29+
/// Allows clients to specify a `omitNullValuedAttributes` boolean query param to control
30+
/// serialization behavior.
31+
/// </summary>
1632
public bool AllowClientOverride { get; }
17-
// ...
1833
}
1934
}

‎src/JsonApiDotNetCore/Models/AttrAttribute.cs

+52-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,26 @@ namespace JsonApiDotNetCore.Models
55
{
66
public class AttrAttribute : Attribute
77
{
8+
/// <summary>
9+
/// Defines a public attribute exposed by the API
10+
/// </summary>
11+
///
12+
/// <param name="publicName">How this attribute is exposed through the API</param>
13+
/// <param name="isImmutable">Prevent PATCH requests from updating the value</param>
14+
/// <param name="isFilterable">Prevent filters on this attribute</param>
15+
/// <param name="isSortable">Prevent this attribute from being sorted by</param>
16+
///
17+
/// <example>
18+
///
19+
/// <code>
20+
/// public class Author : Identifiable
21+
/// {
22+
/// [Attr("name")]
23+
/// public string Name { get; set; }
24+
/// }
25+
/// </code>
26+
///
27+
/// </example>
828
public AttrAttribute(string publicName, bool isImmutable = false, bool isFilterable = true, bool isSortable = true)
929
{
1030
PublicAttributeName = publicName;
@@ -20,20 +40,51 @@ internal AttrAttribute(string publicName, string internalName, bool isImmutable
2040
IsImmutable = isImmutable;
2141
}
2242

43+
/// <summary>
44+
/// How this attribute is exposed through the API
45+
/// </summary>
2346
public string PublicAttributeName { get; }
47+
48+
/// <summary>
49+
/// The internal property name this attribute belongs to.
50+
/// </summary>
2451
public string InternalAttributeName { get; internal set; }
52+
53+
/// <summary>
54+
/// Prevents PATCH requests from updating the value.
55+
/// </summary>
2556
public bool IsImmutable { get; }
57+
58+
/// <summary>
59+
/// Whether or not this attribute can be filtered on via a query string filters.
60+
/// Attempts to filter on an attribute with `IsFilterable == false` will return
61+
/// an HTTP 400 response.
62+
/// </summary>
2663
public bool IsFilterable { get; }
64+
65+
/// <summary>
66+
/// Whether or not this attribute can be sorted on via a query string sort.
67+
/// Attempts to filter on an attribute with `IsSortable == false` will return
68+
/// an HTTP 400 response.
69+
/// </summary>
2770
public bool IsSortable { get; }
2871

72+
/// <summary>
73+
/// Get the value of the attribute for the given object.
74+
/// Returns null if the attribute does not belong to the
75+
/// provided object.
76+
/// </summary>
2977
public object GetValue(object entity)
3078
{
3179
return entity
3280
.GetType()
3381
.GetProperty(InternalAttributeName)
34-
.GetValue(entity);
82+
?.GetValue(entity);
3583
}
3684

85+
/// <summary>
86+
/// Sets the value of the attribute on the given object.
87+
/// </summary>
3788
public void SetValue(object entity, object newValue)
3889
{
3990
var propertyInfo = entity

‎src/JsonApiDotNetCore/Models/HasManyAttribute.cs

+25-1
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,40 @@ namespace JsonApiDotNetCore.Models
22
{
33
public class HasManyAttribute : RelationshipAttribute
44
{
5+
/// <summary>
6+
/// Create a HasMany relational link to another entity
7+
/// </summary>
8+
///
9+
/// <param name="publicName">The relationship name as exposed by the API</param>
10+
/// <param name="documentLinks">Which links are available. Defaults to <see cref="Link.All"/></param>
11+
/// <param name="canInclude">Whether or not this relationship can be included using the <c>?include=public-name</c> query string</param>
12+
///
13+
/// <example>
14+
///
15+
/// <code>
16+
/// public class Author : Identifiable
17+
/// {
18+
/// [HasMany("articles"]
19+
/// public virtual List<Article> Articles { get; set; }
20+
/// }
21+
/// </code>
22+
///
23+
/// </example>
524
public HasManyAttribute(string publicName, Link documentLinks = Link.All, bool canInclude = true)
625
: base(publicName, documentLinks, canInclude)
726
{ }
827

28+
/// <summary>
29+
/// Sets the value of the property identified by this attribute
30+
/// </summary>
31+
/// <param name="entity">The target object</param>
32+
/// <param name="newValue">The new property value</param>
933
public override void SetValue(object entity, object newValue)
1034
{
1135
var propertyInfo = entity
1236
.GetType()
1337
.GetProperty(InternalRelationshipName);
14-
38+
1539
propertyInfo.SetValue(entity, newValue);
1640
}
1741
}

‎src/JsonApiDotNetCore/Services/QueryComposer.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections.Generic;
22
using JsonApiDotNetCore.Internal.Query;
3-
using Microsoft.Extensions.Logging;
43

54
namespace JsonApiDotNetCore.Services
65
{
@@ -14,8 +13,8 @@ public class QueryComposer : IQueryComposer
1413
public string Compose(IJsonApiContext jsonApiContext)
1514
{
1615
string result = "";
17-
if(jsonApiContext != null && jsonApiContext.QuerySet != null)
18-
{
16+
if (jsonApiContext != null && jsonApiContext.QuerySet != null)
17+
{
1918
List<FilterQuery> filterQueries = jsonApiContext.QuerySet.Filters;
2019
if (filterQueries.Count > 0)
2120
{

0 commit comments

Comments
 (0)
Please sign in to comment.