Akka http does not handle parameters with dollar signs correctly?

I have query parameters (OData) defined on my route, for example:

parameters(('$top.as[Int].?, '$skip.as[Int].?)) { (top, skip) => 

I have the following rejection handler to handle all invalid parameters (handleAll):

 RejectionHandler.newBuilder() .handleAll[MalformedQueryParamRejection] { paramRejections => // paramRejections is a Seq[MalformedQueryParamRejection] ... } 

The problem is that when called with the following

 some-endpoint?$top=invalid&$skip=invalid 

paramRejections in the deviation handler has 2 entries, both for $ top, not one for $ top and one for $ skip.

This seems to be related to the dollar sign in terms of parameters, because when I delete this, the work is working properly. Is this a known issue or is there an affordable solution ( which does not include removing the dollar sign )?

Note. It seems that only the deviation handler has a problem with several parameters starting with the dollar sign, since this line on the route correctly assigns the top and skips the variables when $ top and $ skip are supplied with valid values ​​in the URI:

 parameters(('$top.as[Int].?, '$skip.as[Int].?)) { (top, skip) => 
+5
source share
1 answer

There is a problem with the route tree configuration, probably two candidate routes are evaluated, and each of them creates a MalformedQueryParamRejection for the query parameter $top .

The parameter expressions in the deviation handler have 2 entries, both for $ top, and for $ top and for $ skip.

handleAll does not collect multiple MalformedQueryParamRejection coming from the same route, but it collects deviations from different routes.

paramRejections is a Seq[MalformedQueryParamRejection] , but one route can only be rejected by one MalformedQueryParamRejection , in particular (only) the first query parameter that does not match the required format.

Try with a minimal route configuration (as in the example below) and you will experience the correct behavior:

 val route = get { parameters(('$top.as[Int].?, '$skip.as[Int].?)) { (top, skip) => complete(s"$top, $skip") } } 
+1
source

Source: https://habr.com/ru/post/1272770/


All Articles