-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support bijection in OptionDefaultVisitor
- Loading branch information
1 parent
b18c7bf
commit 01df1ab
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
modules/bootstrapped/test/src/smithy4s/http/MetadataDecoderSpec.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,44 @@ | ||
package smithy4s.http | ||
|
||
import munit._ | ||
import smithy4s.schema.Schema | ||
import smithy.api | ||
// import smithy4s.schema.Field | ||
|
||
final class MetadataDecoderSpec extends FunSuite { | ||
test("Optional header") { | ||
case class Foo(deviceType: Option[String]) | ||
val schema = | ||
Schema | ||
.struct( | ||
Schema.string | ||
.optional[Foo]("deviceType", _.deviceType) | ||
.addHints(api.HttpHeader("x-device-type")) | ||
.addHints(api.Input()) | ||
)(Foo(_)) | ||
.addHints(smithy4s.internals.InputOutput.Input.widen) | ||
|
||
val decoder = Metadata.Decoder.fromSchema(schema) | ||
val result = decoder.decode(Metadata()) | ||
|
||
assertEquals(result, Right(Foo(None))) | ||
} | ||
|
||
test("Optional bijection header") { | ||
case class Foo(name: Option[String]) | ||
val schema: Schema[Foo] = { | ||
val field = Schema.string.option | ||
.biject[Option[String]](identity[Option[String]](_))(identity(_)) | ||
.required[Foo]("name", _.name) | ||
.addHints(smithy.api.HttpHeader("X-Name")) | ||
Schema | ||
.struct(field)(Foo(_)) | ||
.addHints(smithy4s.internals.InputOutput.Input.widen) | ||
} | ||
|
||
val decoder = Metadata.Decoder.fromSchema(schema) | ||
val result = decoder.decode(Metadata()) | ||
|
||
assertEquals(result, Right(Foo(None))) | ||
} | ||
} |
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