mirror of
https://github.com/sbt/sbt.git
synced 2026-09-08 11:13:23 +02:00
id is mandatory in json rpc responses
This commit is contained in:
+5
-8
@@ -12,7 +12,7 @@ package sbt.internal.protocol
|
||||
*/
|
||||
final class JsonRpcResponseMessage private (
|
||||
jsonrpc: String,
|
||||
val id: Option[String],
|
||||
val id: String,
|
||||
val result: Option[sjsonnew.shaded.scalajson.ast.unsafe.JValue],
|
||||
val error: Option[sbt.internal.protocol.JsonRpcResponseError]) extends sbt.internal.protocol.JsonRpcMessage(jsonrpc) with Serializable {
|
||||
|
||||
@@ -28,17 +28,14 @@ final class JsonRpcResponseMessage private (
|
||||
override def toString: String = {
|
||||
s"""JsonRpcResponseMessage($jsonrpc, $id, ${sbt.protocol.Serialization.compactPrintJsonOpt(result)}, $error)"""
|
||||
}
|
||||
private[this] def copy(jsonrpc: String = jsonrpc, id: Option[String] = id, result: Option[sjsonnew.shaded.scalajson.ast.unsafe.JValue] = result, error: Option[sbt.internal.protocol.JsonRpcResponseError] = error): JsonRpcResponseMessage = {
|
||||
private[this] def copy(jsonrpc: String = jsonrpc, id: String = id, result: Option[sjsonnew.shaded.scalajson.ast.unsafe.JValue] = result, error: Option[sbt.internal.protocol.JsonRpcResponseError] = error): JsonRpcResponseMessage = {
|
||||
new JsonRpcResponseMessage(jsonrpc, id, result, error)
|
||||
}
|
||||
def withJsonrpc(jsonrpc: String): JsonRpcResponseMessage = {
|
||||
copy(jsonrpc = jsonrpc)
|
||||
}
|
||||
def withId(id: Option[String]): JsonRpcResponseMessage = {
|
||||
copy(id = id)
|
||||
}
|
||||
def withId(id: String): JsonRpcResponseMessage = {
|
||||
copy(id = Option(id))
|
||||
copy(id = id)
|
||||
}
|
||||
def withResult(result: Option[sjsonnew.shaded.scalajson.ast.unsafe.JValue]): JsonRpcResponseMessage = {
|
||||
copy(result = result)
|
||||
@@ -55,6 +52,6 @@ final class JsonRpcResponseMessage private (
|
||||
}
|
||||
object JsonRpcResponseMessage {
|
||||
|
||||
def apply(jsonrpc: String, id: Option[String], result: Option[sjsonnew.shaded.scalajson.ast.unsafe.JValue], error: Option[sbt.internal.protocol.JsonRpcResponseError]): JsonRpcResponseMessage = new JsonRpcResponseMessage(jsonrpc, id, result, error)
|
||||
def apply(jsonrpc: String, id: String, result: sjsonnew.shaded.scalajson.ast.unsafe.JValue, error: sbt.internal.protocol.JsonRpcResponseError): JsonRpcResponseMessage = new JsonRpcResponseMessage(jsonrpc, Option(id), Option(result), Option(error))
|
||||
def apply(jsonrpc: String, id: String, result: Option[sjsonnew.shaded.scalajson.ast.unsafe.JValue], error: Option[sbt.internal.protocol.JsonRpcResponseError]): JsonRpcResponseMessage = new JsonRpcResponseMessage(jsonrpc, id, result, error)
|
||||
def apply(jsonrpc: String, id: String, result: sjsonnew.shaded.scalajson.ast.unsafe.JValue, error: sbt.internal.protocol.JsonRpcResponseError): JsonRpcResponseMessage = new JsonRpcResponseMessage(jsonrpc, id, Option(result), Option(error))
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ type JsonRpcResponseMessage implements JsonRpcMessage
|
||||
jsonrpc: String!
|
||||
|
||||
## The request id.
|
||||
id: String
|
||||
id: String!
|
||||
|
||||
## The result of a request. This can be omitted in
|
||||
## the case of an error.
|
||||
|
||||
+5
-7
@@ -32,10 +32,10 @@ trait JsonRpcResponseMessageFormats {
|
||||
unbuilder.beginObject(js)
|
||||
val jsonrpc = unbuilder.readField[String]("jsonrpc")
|
||||
val id = try {
|
||||
unbuilder.readField[Option[String]]("id")
|
||||
unbuilder.readField[String]("id")
|
||||
} catch {
|
||||
case _: DeserializationException =>
|
||||
unbuilder.readField[Option[Long]]("id") map { _.toString }
|
||||
unbuilder.readField[Long]("id").toString
|
||||
}
|
||||
|
||||
val result = unbuilder.lookupField("result") map {
|
||||
@@ -77,11 +77,9 @@ trait JsonRpcResponseMessageFormats {
|
||||
}
|
||||
builder.beginObject()
|
||||
builder.addField("jsonrpc", obj.jsonrpc)
|
||||
obj.id foreach { id =>
|
||||
parseId(id) match {
|
||||
case Right(strId) => builder.addField("id", strId)
|
||||
case Left(longId) => builder.addField("id", longId)
|
||||
}
|
||||
parseId(obj.id) match {
|
||||
case Right(strId) => builder.addField("id", strId)
|
||||
case Left(longId) => builder.addField("id", longId)
|
||||
}
|
||||
builder.addField("result", obj.result map parseResult)
|
||||
builder.addField("error", obj.error)
|
||||
|
||||
Reference in New Issue
Block a user