You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/usage/extensibility/resource-definitions.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -34,10 +34,10 @@ from Entity Framework Core `IQueryable` execution.
34
34
35
35
### Excluding fields
36
36
37
-
There are some cases where you want attributes (or relationships) conditionally excluded from your resource response.
37
+
There are some cases where you want attributes or relationships conditionally excluded from your resource response.
38
38
For example, you may accept some sensitive data that should only be exposed to administrators after creation.
39
39
40
-
**Note:** to exclude attributes unconditionally, use `[Attr(Capabilities = ~AttrCapabilities.AllowView)]` on a resource class property.
40
+
**Note:** to exclude fields unconditionally, [attribute capabilities](~/usage/resources/attributes.md#capabilities) and [relationship capabilities](~/usage/resources/relationships.md#capabilities) can be used instead.
Copy file name to clipboardExpand all lines: docs/usage/resources/attributes.md
+29-14
Original file line number
Diff line number
Diff line change
@@ -43,9 +43,10 @@ options.DefaultAttrCapabilities = AttrCapabilities.None; // default: All
43
43
44
44
This can be overridden per attribute.
45
45
46
-
### Viewability
46
+
### AllowView
47
47
48
-
Attributes can be marked to allow returning their value in responses. When not allowed and requested using `?fields[]=`, it results in an HTTP 400 response.
48
+
Indicates whether the attribute value can be returned in responses. When not allowed and requested using `?fields[]=`, it results in an HTTP 400 response.
49
+
Otherwise, the attribute is silently omitted.
49
50
50
51
```c#
51
52
#nullable enable
@@ -57,45 +58,59 @@ public class User : Identifiable<int>
57
58
}
58
59
```
59
60
60
-
### Creatability
61
+
### AllowFilter
61
62
62
-
Attributes can be marked as creatable, which will allow `POST` requests to assign a value to them. When sent but not allowed, an HTTP 422 response is returned.
63
+
Indicates whether the attribute can be filtered on. When not allowed and used in `?filter=`, an HTTP 400 is returned.
63
64
64
65
```c#
65
66
#nullable enable
66
67
67
68
publicclassPerson : Identifiable<int>
68
69
{
69
-
[Attr(Capabilities=AttrCapabilities.AllowCreate)]
70
-
publicstring? CreatorName { get; set; }
70
+
[Attr(Capabilities=AttrCapabilities.AllowFilter)]
71
+
publicstring? FirstName { get; set; }
71
72
}
72
73
```
73
74
74
-
### Changeability
75
+
### AllowSort
75
76
76
-
Attributes can be marked as changeable, which will allow `PATCH` requests to update them. When sent but not allowed, an HTTP 422 response is returned.
77
+
Indicates whether the attribute can be sorted on. When not allowed and used in `?sort=`, an HTTP 400 is returned.
77
78
78
79
```c#
79
80
#nullable enable
80
81
81
82
publicclassPerson : Identifiable<int>
82
83
{
83
-
[Attr(Capabilities=AttrCapabilities.AllowChange)]
84
-
publicstring? FirstName { get; set; };
84
+
[Attr(Capabilities=~AttrCapabilities.AllowSort)]
85
+
publicstring? FirstName { get; set; }
85
86
}
86
87
```
87
88
88
-
### Filter/Sort-ability
89
+
### AllowCreate
89
90
90
-
Attributes can be marked to allow filtering and/or sorting. When not allowed, it results in an HTTP 400 response.
91
+
Indicates whether POST requests can assign the attribute value. When sent but not allowed, an HTTP 422 response is returned.
options.DefaultHasOneCapabilities=HasOneCapabilities.None; // default: All
173
+
options.DefaultHasManyCapabilities=HasManyCapabilities.None; // default: All
174
+
```
175
+
176
+
This can be overridden per relationship.
177
+
178
+
### AllowView
179
+
180
+
Indicates whether the relationship can be returned in responses. When not allowed and requested using `?fields[]=`, it results in an HTTP 400 response.
181
+
Otherwise, the relationship (and its related resources, when included) are silently omitted.
182
+
183
+
Note that this setting does not affect retrieving the related resources directly.
publicISet<Group> Groups { get; set; } =newHashSet<Group>();
206
+
}
207
+
```
208
+
209
+
### AllowFilter
210
+
211
+
For to-many relationships only. Indicates whether it can be used in the `count()` and `has()` filter functions. When not allowed and used in `?filter=`, an HTTP 400 is returned.
For to-many relationships only. Indicates whether POST requests can add resources to the relationship. When sent but not allowed, an HTTP 422 response is returned.
publicISet<Group> Groups { get; set; } =newHashSet<Group>();
248
+
}
249
+
```
250
+
251
+
### AllowRemove
252
+
253
+
For to-many relationships only. Indicates whether DELETE requests can remove resources from the relationship. When sent but not allowed, an HTTP 422 response is returned.
publicISet<Group> Groups { get; set; } =newHashSet<Group>();
262
+
}
263
+
```
264
+
265
+
## CanInclude
266
+
267
+
_obsolete since v5.1_
164
268
165
269
Relationships can be marked to disallow including them using the `?include=` query string parameter. When not allowed, it results in an HTTP 400 response.
/// The set of capabilities that are allowed to be performed on this attribute. When not explicitly assigned, the configured default set of capabilities
18
-
/// is used.
17
+
/// The set of allowed capabilities on this attribute. When not explicitly set, the configured default set of capabilities is used.
Copy file name to clipboardExpand all lines: src/JsonApiDotNetCore.Annotations/Resources/Annotations/AttrCapabilities.shared.cs
+11-8
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
namespaceJsonApiDotNetCore.Resources.Annotations;
4
4
5
5
/// <summary>
6
-
/// Indicates capabilities that can be performed on an <see cref="AttrAttribute" />.
6
+
/// Indicates what can be performed on an <see cref="AttrAttribute" />.
7
7
/// </summary>
8
8
[PublicAPI]
9
9
[Flags]
@@ -12,29 +12,32 @@ public enum AttrCapabilities
12
12
None=0,
13
13
14
14
/// <summary>
15
-
/// Whether or not GET requests can retrieve the attribute. Attempts to retrieve when disabled will return an HTTP 400 response.
15
+
/// Whether or not the attribute value can be returned in responses. Attempts to explicitly request it via the <c>fields</c> query string parameter when
16
+
/// disabled will return an HTTP 400 response. Otherwise, the attribute is silently omitted.
16
17
/// </summary>
17
18
AllowView=1,
18
19
19
20
/// <summary>
20
21
/// Whether or not POST requests can assign the attribute value. Attempts to assign when disabled will return an HTTP 422 response.
21
22
/// </summary>
22
-
AllowCreate=2,
23
+
AllowCreate=1<<1,
23
24
24
25
/// <summary>
25
26
/// Whether or not PATCH requests can update the attribute value. Attempts to update when disabled will return an HTTP 422 response.
26
27
/// </summary>
27
-
AllowChange=4,
28
+
AllowChange=1<<2,
28
29
29
30
/// <summary>
30
-
/// Whether or not an attribute can be filtered on via a query string parameter. Attempts to filter when disabled will return an HTTP 400 response.
31
+
/// Whether or not the attribute can be filtered on. Attempts to use it in the <c>filter</c> query string parameter when disabled will return an HTTP 400
32
+
/// response.
31
33
/// </summary>
32
-
AllowFilter=8,
34
+
AllowFilter=1<<3,
33
35
34
36
/// <summary>
35
-
/// Whether or not an attribute can be sorted on via a query string parameter. Attempts to sort when disabled will return an HTTP 400 response.
37
+
/// Whether or not the attribute can be sorted on. Attempts to use it in the <c>sort</c> query string parameter when disabled will return an HTTP 400
0 commit comments