Add unit test to check that AnyRequest handles missing parameters #24
+51
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First part of the issue:
Here's a unit test that shows part of the issue. When a new message comes in, the JSON is first decoded into an AnyRequest in Server's input stream handler, and then is decoded to the concrete Request type in
TypedRequestHandler
.This means that the AnyRequest type must also be able to handle missing
params
.These screenshots show the issue. First screenshot shows the list tools request arrive with
{"method":"tools/list","jsonrpc":"2.0","id":1}
trying to decode into an AnyRequestsecond screenshot shows the decoding fail because
M.Parameters.self
isValue
notEmpty
Second part of the issue:
I believe this wouldn't fix it entirely, as the parameters from the
AnyRequest
are re-encoded and decoded incallAsFunction
of theTypedRequestHandler
. This decodes intoM.Parameters.self
directly, so theNotRequired
handling inRequest.init(from decoder:)
doesn't get called here, and instead the decoding would fail immediately.