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

Enable cask.UnknownQueryParams and cask.RemainingPathSegments for form endpoints #110

Merged
merged 3 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cask/src/cask/endpoints/FormEndpoint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ object FormReader{
implicit def paramFormReader[T: QueryParamReader]: FormReader[T] = new FormReader[T]{
def arity = implicitly[QueryParamReader[T]].arity

override def unknownQueryParams: Boolean = implicitly[QueryParamReader[T]].unknownQueryParams

override def remainingPathSegments: Boolean = implicitly[QueryParamReader[T]].remainingPathSegments
def read(ctx: Request, label: String, input: Seq[FormEntry]) = {
implicitly[QueryParamReader[T]].read(ctx, label, if (input == null) null else input.map(_.valueOrFileName))
}
Expand Down
8 changes: 8 additions & 0 deletions example/formJsonPost/app/src/FormJsonPost.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,13 @@ object FormJsonPost extends cask.MainRoutes{
"OK " + value1 + " " + value2 + " " + params.value + " " + segments.value
}

@cask.postForm("/form-extra")
def formEndpointExtra(value1: cask.FormValue,
value2: Seq[Int],
params: cask.QueryParams,
segments: cask.RemainingPathSegments) = {
"OK " + value1 + " " + value2 + " " + params.value + " " + segments.value
}

initialize()
}
17 changes: 17 additions & 0 deletions example/formJsonPost/app/test/src/ExampleTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ object ExampleTests extends TestSuite{
s"$host/json-extra/omg/wtf/bbq?iam=cow&hearme=moo",
data = """{"value1": true, "value2": [3]}"""
)

val text6 = response6.text()
assert(
text6 == "\"OK true List(3) Map(hearme -> ArraySeq(moo), iam -> ArraySeq(cow)) List(omg, wtf, bbq)\"" ||
text6 == "\"OK true Vector(3) Map(hearme -> WrappedArray(moo), iam -> WrappedArray(cow)) List(omg, wtf, bbq)\""
)

val response7 = requests.post(
s"$host/form-extra/omg/wtf/bbq?iam=cow&hearme=moo",
data = Seq("value1" -> "hello", "value2" -> "1", "value2" -> "2")
)

val text7 = response7.text()
assert(
text7 == "OK FormValue(hello,null) List(1, 2) Map(hearme -> ArraySeq(moo), iam -> ArraySeq(cow)) List(omg, wtf, bbq)" ||
text7 == "OK FormValue(hello,null) List(1, 2) Map(hearme -> WrappedArray(moo), iam -> WrappedArray(cow)) List(omg, wtf, bbq)"
)
}
}
}