Home > Mobile >  Nuget Package is causing API Validation Errors
Nuget Package is causing API Validation Errors

Time:04-17

I have a project that is separated into three layers:

  • An API, which sends MediatR queries and commands to the application layer.
  • A class library of application logic that uses fluent validation.
  • A class library of domain objects.

Originally the domain objects class library was locally referenced by the application layer, which was then referenced by the API layer.

Domain > Application > API

Recently, I moved the domain layer to a Nuget Package, so that it can be used by other projects as well as this one. However, since moving it I'm getting 400 Bad request validation errors when sending requests to my API.

{
  "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
  "title" : "One or more validation errors occurred.",
  "status" : 400,
  "traceId" : <Guid>,
  "errors" : {
        "Id" :[
              "'Id' must not be empty.",
        ],
        "Events": [
              "The events field is required."
         ]
  }
}

Does anybody have any idea how to fix this?

I have tried taking out fluent validation and I've tried switching back to the local project where the problem goes away. As far as I can tell, the NugetPackage version and the local version are identical. All projects are using dotnet 6.0.

Regards, Adam

CodePudding user response:

When you moved your domain layer into a separate project (NuGet) you might have accidentally switched on NRT (see docs) and that's why Fluent Validation is being more strict (which is a good thing).

Check if the validation message are actually true positives. If they're not helpful, keep NRT enabled but relax your validation rules.

  • Related