forked from zio/zio-http
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Schema based header codecs, unified with query codecs (zio#3232)
Fix for publish CI job
- Loading branch information
Showing
29 changed files
with
1,444 additions
and
586 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
zio-http/jvm/src/test/scala/zio/http/endpoint/HeaderSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package zio.http.endpoint | ||
|
||
import zio.Scope | ||
import zio.test.Assertion._ | ||
import zio.test._ | ||
|
||
import zio.schema.Schema | ||
import zio.schema.annotation.fieldName | ||
|
||
import zio.http._ | ||
import zio.http.codec.HttpCodec | ||
import zio.http.endpoint.EndpointSpec.{testEndpoint, testEndpointWithHeaders} | ||
|
||
object HeaderSpec extends ZIOHttpSpec { | ||
case class MyHeaders(age: String, @fieldName("content-type") cType: String = "application", xApiKey: Option[String]) | ||
|
||
object MyHeaders { | ||
implicit val schema: Schema[MyHeaders] = zio.schema.DeriveSchema.gen[MyHeaders] | ||
} | ||
|
||
override def spec: Spec[TestEnvironment with Scope, Any] = | ||
suite("HeaderCodec")( | ||
test("Headers from case class") { | ||
check( | ||
Gen.alphaNumericStringBounded(1, 10), | ||
Gen.alphaNumericStringBounded(1, 10), | ||
Gen.alphaNumericStringBounded(1, 10), | ||
) { (age, cType, apiKey) => | ||
val testRoutes = testEndpointWithHeaders( | ||
Routes( | ||
Endpoint(Method.GET / "users") | ||
.header(HttpCodec.headers[MyHeaders]) | ||
.out[String] | ||
.implementPurely(_.toString), | ||
), | ||
) _ | ||
|
||
testRoutes( | ||
s"/users", | ||
List( | ||
"age" -> age, | ||
"content-type" -> cType, | ||
"x-api-key" -> apiKey, | ||
), | ||
MyHeaders(age, cType, Some(apiKey)).toString, | ||
) && | ||
testRoutes( | ||
s"/users", | ||
List( | ||
"age" -> age, | ||
"content-type" -> cType, | ||
"x-api-key" -> "", | ||
), | ||
MyHeaders(age, cType, Some("")).toString, | ||
) && | ||
testRoutes( | ||
s"/users", | ||
List( | ||
"age" -> age, | ||
), | ||
MyHeaders(age, "application", None).toString, | ||
) | ||
} | ||
}, | ||
test("Optional Headers from case class") { | ||
check( | ||
Gen.alphaNumericStringBounded(1, 10), | ||
Gen.alphaNumericStringBounded(1, 10), | ||
Gen.alphaNumericStringBounded(1, 10), | ||
) { (age, cType, apiKey) => | ||
val testRoutes = testEndpointWithHeaders( | ||
Routes( | ||
Endpoint(Method.GET / "users") | ||
.header(HttpCodec.headers[MyHeaders].optional) | ||
.out[String] | ||
.implementPurely(_.toString), | ||
), | ||
) _ | ||
|
||
testRoutes( | ||
s"/users", | ||
List( | ||
"content-type" -> cType, | ||
), | ||
None.toString, | ||
) | ||
} | ||
}, | ||
) | ||
} |
Oops, something went wrong.