Closed
Description
DESCRIPTION
Cannot make a client POST request to create a resource derived from Identifiable<string>
- Controller validates the model saying
The Id field is required.
For many reasons, we might want to assign the Id from the server-side. In the 4.x version, I assign an Id at OnWritingAsync
. However, with the 5.x version, we validate the ModelState before reaching the OnWritingAsync
function
STEPS TO REPRODUCE
public sealed class RgbColor : Identifiable<string>
{
[Attr]
public string DisplayName { get; set; } = null!;
[HasOne]
public WorkItemGroup? Group { get; set; }
}
options.AllowClientGeneratedIds = false;
options.ValidateModelState = true;
POST request with the request body
{
"data":{
"type":"rgbColor",
"attributes":{
"DisplayName":"Blue"
}
}
}
EXPECTED BEHAVIOR
- Allow assigning Id from server-side
- Don't throw the Modal Validation with Id
ACTUAL BEHAVIOR
- The controller always validates the model and throws
The Id field is required.
exception
VERSIONS USED
- JsonApiDotNetCore version: 5.0.1
- ASP.NET Core version: 6.0
- Entity Framework Core version: 6.0
- Database provider: InMemory
Metadata
Metadata
Assignees
Labels
No labels