softwaremill / softwaremill/tapir

Cross-platform reuse blocker: OnDecodeFailureNextEndpointAttribute is server-only and private

Open
#4,935 6 comments 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

We're utilizing tapir endpoint definitions for both server and client (with scala js).
We've recently encountered a problem with routing, described at #141

To be honest it was (an unpleasant) surprise that if there's a path decoding mismatch, interpreter doesn't try other endpoints. IMHO it makes no sense for this not to be the default

The documented workaround suggestion is to adjust definition with special attribute to endpoint Atom input, using a onDecodeFailureNextEndpoint extension

import sttp.tapir.server.interceptor.decodefailure.DefaultDecodeFailureHandler.OnDecodeFailure.*

// If your codec for UserId fails, allow checking other endpoints for possible matches, like /customer/some_special_case
endpoint.in("customer" / path[UserId]("user_id").onDecodeFailureNextEndpoint)

But the problem is that this involves a server-side library.

Theoretically, I could traverse inputs of every endpoint before mounting them, and apply extension to PathCaptures, but I can't find how do it easily. Constructing a Pair back requires ParamConcat implicits which are not carried.

I think I will end up with platform-specific helper code around path[Input] that will use server library attributes at JVM and do nothing on JS, but that doesn't look pretty.

As the everyday user of the tapir, I wish I can set this in my shared endpoint-definition code.
But make it a default behaviour is better! 😃

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 by reading the routing problem in #141 and tracing OnDecodeFailureNextEndpointAttribute, onDecodeFailureNextEndpoint, and path[UserId] through the shared endpoint-definition and server-side code. Determine how the behavior can be expressed without a server-only dependency, then verify that shared Scala/Scala.js definitions support the intended fallback routing.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.