Skip to content

Commit fda4a4a

Browse files
Document behavior of missing attributes in JSON:API responses and how to include them
1 parent 4be0862 commit fda4a4a

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

docs/docs/querying.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,33 @@ With this request, the toolkit will:
4646
- Sort the results with the newest published books first.
4747
- Return the first 10 results.
4848
- Include related author and reviews data in the response.
49+
50+
## Missing Attributes in JSON:API Responses
51+
52+
When using our JSON:API implementation, you might notice that certain properties—such as `CompanyTenantId`—are not included in the API responses. This is because the default attribute mapping logic intentionally excludes any property that ends with "`Id`" (other than the primary `Id`).
53+
54+
### Default Behavior and Rationale
55+
56+
This behavior is deliberate and conforms to JSON:API best practices:
57+
- **Separation of Identity and Attributes:** The primary identifier is kept separate from the resource’s attributes. The `"id"` field uniquely identifies a resource, while attributes describe its state.
58+
- **Avoiding Redundancy:** By not duplicating identifier values as attributes, the response remains clean and unambiguous.
59+
- **Clarifying Relationships:** Properties ending in "`Id`" often indicate foreign keys or relational links. Excluding them from attributes discourages treating these as simple data values.
60+
61+
### How to Circumvent the Default Behavior
62+
63+
If your design requires that additional identifier fields be exposed as attributes—because they carry significant, non-relational context—you can override the default exclusion by using the `[IncludeAsAttribute]` attribute. For example:
64+
65+
```csharp
66+
using static JsonApiToolkit.Mapping.EntityMapper;
67+
68+
public class Company
69+
{
70+
public Guid Id { get; set; }
71+
public string CompanyName { get; set; } = string.Empty;
72+
public string CompanyCode { get; set; } = string.Empty;
73+
[IncludeAsAttribute]
74+
public Guid CompanyTenantId { get; set; }
75+
}
76+
```
77+
78+

0 commit comments

Comments
 (0)