-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for sparse collections in query params #1513
base: series/0.19
Are you sure you want to change the base?
Support for sparse collections in query params #1513
Conversation
import smithy4s.example.{ServiceWithSparseQueryParams, SparseQueryOutput} | ||
import weaver._ | ||
|
||
object SparseQueryParametersSuite extends SimpleIOSuite with CirceInstances { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not have a bespoke http4s test for this. I'd rather the test was encoded as a compliance test in alloy instead, but that could happen in later PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried adding a compliance test in disneystreaming/alloy#172 , but for some reason that I can't comprehend it fails:
[info] [http4s] smithy4s.http4s.SimpleRestJsonComplianceSuite
...
[info] [http4s] + alloy.test#SparseQueryParam(client|Request): SparseQueryParam 676ms
[info] [http4s] - alloy.test#SparseQueryParam(server|Request): SparseQueryParam 202ms
[info] [http4s] *************FAILURES**************
[info] [http4s] smithy4s.http4s.SimpleRestJsonComplianceSuite
[error] [http4s] - alloy.test#SparseQueryParam(server|Request): SparseQueryParam 202ms
[error] [http4s] the result value: Array(List(Some(value = "bar"), Some(value = ""), Some(value = "baz"), Some(value = ""))) was not equal to the expected TestCase value Array(List(Some(value = "bar"), None, Some(value = "baz"), Some(value = ""))). (modules/tests/src/smithy4s/tests/ProtocolComplianceSuite.scala:183)
The client part passes, but the server one doesn't and I just can't wrap my head around why 🤯
val expectedQueryParams: Vector[(String, Option[String])] = | ||
parseQueryParams(testCase.queryParams) | ||
.foldLeft[ListMap[String, Vector[Option[String]]]](ListMap.empty) { | ||
case (acc, (k, v)) => | ||
acc.get(k) match { | ||
case Some(value) => acc + (k -> (value :+ v)) | ||
case None => acc + (k -> Vector(v)) | ||
} | ||
} | ||
.map { | ||
// FIXME: replacing single query parameter without value with empty string | ||
// to make sure that https://github.com/smithy-lang/smithy/blob/6c42bc9d60a681e63c66f4cde33d7a189a1ff9a6/smithy-aws-protocol-tests/model/restJson1/http-query.smithy#L476-L489 | ||
// passes. | ||
// Previously this was done in `parseQueryParams`. | ||
case (k, Vector(None)) => k -> Vector(Some("")) | ||
case kv => kv | ||
} | ||
.toVector | ||
.flatMap { case (k, v) => | ||
v.map(k -> _) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit of a hack to get the compliance tests passing, but will require some discussion.
As far as I can tell, this aws restJson compliance test expects a query of example.com/?foo
to be treated as foo=Some("")
instead of foo=None
which is a bit problematic for this change.
Closes #1490
PR Checklist (not all items are relevant to all PRs)