Skip to content
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

Open
wants to merge 13 commits into
base: series/0.19
Choose a base branch
from

Conversation

denisrosca
Copy link
Contributor

@denisrosca denisrosca commented May 9, 2024

Closes #1490

PR Checklist (not all items are relevant to all PRs)

  • Add support for sparse lists in query parameters
  • Add support for sparse maps in query parameters
  • Added unit-tests (for runtime code)
  • Added bootstrapped code + smoke tests (when the rendering logic is modified)
  • Updated changelog

@denisrosca denisrosca closed this Jun 6, 2024
@denisrosca denisrosca reopened this Jun 6, 2024
@denisrosca denisrosca changed the title Support for sparse lists in query params Support for sparse collections in query params Jun 6, 2024
@denisrosca denisrosca marked this pull request as ready for review June 6, 2024 19:00
import smithy4s.example.{ServiceWithSparseQueryParams, SparseQueryOutput}
import weaver._

object SparseQueryParametersSuite extends SimpleIOSuite with CirceInstances {
Copy link
Contributor

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

Copy link
Contributor Author

@denisrosca denisrosca Jun 14, 2024

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 🤯

Comment on lines +71 to +92
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 -> _)
}

Copy link
Contributor Author

@denisrosca denisrosca Jun 18, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants