Skip to content

No way to create a resource derived from Identifiable<string> without sending Id from client side #1153

Closed
@minhhieugma

Description

@minhhieugma

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions