Skip to content

Adopt 422 Unprocessable Entity for payload validation errors #469

@nanotaboada

Description

@nanotaboada

Problem

Field validation failures currently return 400 Bad Request, which conflates two distinct error categories:

  • 400 Bad Request — the request is malformed (unparseable JSON, wrong Content-Type)
  • 422 Unprocessable Entity — the request is syntactically valid but fails business/field validation rules

Proposed Solution

Return 422 Unprocessable Entity for field validation failures and reserve 400 Bad Request for genuinely malformed requests.

TypedResults.ValidationProblem() already produces a ProblemDetails-compatible body — the change is to emit 422 instead of 400 as its status code.

Acceptance Criteria

  • Field validation failures return 422 Unprocessable Entity (RFC 9457 problem details)
  • 400 Bad Request is reserved for malformed requests (unparseable JSON, wrong Content-Type)
  • Swagger/OpenAPI docs updated to declare 422 instead of 400 for validation responses
  • Tests updated to assert the new status code
  • All existing tests continue to pass
  • CHANGELOG.md updated

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETPull requests that update .NET codeenhancementNew feature or requestpriority lowNice-to-have improvement. Can be deferred without blocking other work.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions