softwaremill / softwaremill/tapir

Validation error response - lack of access to the name of the invalid field

Open
#2,729 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
1.5k
Forks
468
Avg merge
5h 37m
Merged PRs (30d)
34

Description

I want to return the following response on the validation error:

{
  "errors":{
    "fieldName": [
      "field error"
    ]
  }
}

(like in https://realworld-docs.netlify.app/docs/specs/backend-specs/error-handling#errors-and-status-codes)
I've tried to modify the response handler here: https://github.com/softwaremill/tapir/blob/master/server/core/src/main/scala/sttp/tapir/server/interceptor/decodefailure/DecodeFailureHandler.scala#L33
But the response handler doesn't have access to the field name (only to status code, headers, and error message - (StatusCode, List[Header], String) => ValuedEndpointOutput[_].

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with server/core/src/main/scala/sttp/tapir/server/interceptor/decodefailure/DecodeFailureHandler.scala around line 33, where the response handler receives only the status code, headers, and error message. Trace how validation failures reach this handler and where the invalid field name is lost. Done means the handler can produce the requested field-keyed validation error response.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.