json-api-dotnet / JsonApiDotNetCore

A framework for building JSON:API compliant REST APIs using ASP.NET and Entity Framework Core.
https://www.jsonapi.net
MIT License
662 stars 160 forks source link

Add [DisallowNull] on id parameters #1571

Closed bkoelman closed 1 week ago

bkoelman commented 2 weeks ago

Controllers, resource services, repositories, repository accessors, and IQueryLayerComposer should be annotated with [DisallowNull] for method parameters named id. While it can be null in the resource type itself (to support zero values), they should never be for incoming requests.

Adding this annotation produces a compiler warning when called directly from custom code.

We can't add the notnull constraint on TId, because that breaks the contract with IIdentifiable<TId>.