input-output-hk / armadillo Goto Github PK
View Code? Open in Web Editor NEWDeclarative, type-safe json-rpc endpoints library
License: Apache License 2.0
Declarative, type-safe json-rpc endpoints library
License: Apache License 2.0
Greetings! I'm very happy to find such an awesome JSON-RPC tool for Scala. My thanks and respect to all creators and contributors.
Describe the bug
When optional param omitted in request, server fails to handle it.
It responds with:
{
"jsonrpc": "2.0",
"error": {
"code": -32602,
"message": "Invalid params"
},
"id": "..."
}
Adding Logging interceptor showed that there is a decoding exception: Error(Too many inputs provided,java.lang.RuntimeException: Too many inputs provided)
.
I suppose, this happens because of actual params check here (ServerInterpreter.scala):
private def combineDecodeAsObject(in: Vector[JsonRpcIO.Single[_]]): Json.JsonObject[Raw] => DecodeResult[Vector[_]] = { json =>
val jsonAsMap = json.fields.toMap
// Seems like the first condition is to blame
if (jsonAsMap.size >= in.count(_.codec.schema.isOptional) && jsonAsMap.size <= in.size) {
// ....
} else {
val msg = "Too many inputs provided"
DecodeResult.Error(msg, new RuntimeException(msg))
}
}
As far as I understand, when optional params are omitted, the first condition is always false
. Maybe, we need just to check that actual ammount of params less or equal to number of inputs?
To Reproduce
val testEndpoint: JsonRpcEndpoint[Option[String], Unit, String] =
jsonRpcEndpoint(m"echo")
.in(param[Option[String]]("msg1").and(param[String]("msg2")))
.out[String]("response")
{
"jsonrpc": "2.0",
"id": "123",
"method": "echo",
"params": {
"msg2": "Two Tiny Little Tigers"
}
}
Expected behavior
Optional params are treated as None
's and cause no errors when decoded.
Additional context
Version: 0.1.0
The jsonrpc spec states:
jsonrpc
A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".
Armadillo does not check for that. So if an hypothetical newer version of the spec would appear the server would try to handle queries with some unknown semantics.
Currently, JValue
gets serialized twice which is obviously not what we want.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.