softwaremill / softwaremill/tapir

[Feature] Add a way to accumulate multiple validations errors

Open
#2,640 1 comment 6 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

Hi guys, I would like to start with congratulate me for your great work, I love use Tapir!
I wanted to ask if it was possible to create an accumulator of validation errors when validating the query parameters/body of a request.
For example in this piece of code:

import sttp.tapir._

val e = endpoint.in(
  query[Int]("amount")
    .validate(Validator.min(0))
    .validate(Validator.max(100)))
 query[Int]("taxes")
    .validate(Validator.min(0))
    .validate(Validator.max(100)))

This piece of code will fail at the first validate but I would like to return to my client something in this format (RFC 7807):

 {
   "type": "https://example.net/validation-error",
   "title": "Your request parameters didn't validate.",
   "invalid-params": [ {
                         "name": "amount",
                         "reason": "must be a greater than 0"
                       },
                       {
                         "name": "taxes",
                         "reason": "must be less than 100"}
                     ]
   }

Do you think that this is possible?

Thanks a lot!

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

No files or tests are named; start by tracing endpoint query/body validation and how multiple Validator results are currently handled. Define the accumulation behavior and RFC 7807 response shape, including each invalid parameter and reason, then verify that multiple validation failures are returned together.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.