Skip to content

Commit 8084271

Browse files
author
Jan Strnad
committed
Handle byte string format according to specification
1 parent a05146a commit 8084271

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

modules/codegen/src/main/scala/com/twilio/guardrail/SwaggerUtil.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ object SwaggerUtil {
281281
case (Some("string"), Some("email")) => stringType(None)
282282
case (Some("string"), Some("date")) => dateType()
283283
case (Some("string"), Some("date-time")) => dateTimeType()
284+
case (Some("string"), Some("byte")) => stringType(None)
284285
case (Some("string"), fmt @ Some("binary")) => fileType(None).map(log(fmt, _))
285286
case (Some("string"), fmt) => stringType(fmt).map(log(fmt, _))
286287
case (Some("number"), Some("float")) => floatType()

modules/codegen/src/test/scala/tests/core/TypesTest.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class TypesTest extends FunSuite with Matchers with SwaggerSpecRunner {
4040
| date_time:
4141
| type: string
4242
| format: date-time
43+
| byte:
44+
| type: string
45+
| format: byte
4346
| long:
4447
| type: integer
4548
| format: int64
@@ -99,6 +102,7 @@ class TypesTest extends FunSuite with Matchers with SwaggerSpecRunner {
99102
string: Option[String] = None,
100103
date: Option[java.time.LocalDate] = None,
101104
date_time: Option[java.time.OffsetDateTime] = None,
105+
byte: Option[String] = None,
102106
long: Option[Long] = None,
103107
int: Option[Int] = None,
104108
float: Option[Float] = None,
@@ -118,9 +122,9 @@ class TypesTest extends FunSuite with Matchers with SwaggerSpecRunner {
118122
object Types {
119123
implicit val encodeTypes: Encoder.AsObject[Types] = {
120124
val readOnlyKeys = Set[String]()
121-
Encoder.AsObject.instance[Types](a => JsonObject.fromIterable(Vector(("array", a.array.asJson), ("map", a.map.asJson), ("obj", a.obj.asJson), ("bool", a.bool.asJson), ("string", a.string.asJson), ("date", a.date.asJson), ("date_time", a.date_time.asJson), ("long", a.long.asJson), ("int", a.int.asJson), ("float", a.float.asJson), ("double", a.double.asJson), ("number", a.number.asJson), ("integer", a.integer.asJson), ("untyped", a.untyped.asJson), ("custom", a.custom.asJson), ("customComplex", a.customComplex.asJson), ("nested", a.nested.asJson), ("nestedArray", a.nestedArray.asJson), ("requiredArray", a.requiredArray.asJson)))).mapJsonObject(_.filterKeys(key => !(readOnlyKeys contains key)))
125+
Encoder.AsObject.instance[Types](a => JsonObject.fromIterable(Vector(("array", a.array.asJson), ("map", a.map.asJson), ("obj", a.obj.asJson), ("bool", a.bool.asJson), ("string", a.string.asJson), ("date", a.date.asJson), ("date_time", a.date_time.asJson), ("byte", a.byte.asJson), ("long", a.long.asJson), ("int", a.int.asJson), ("float", a.float.asJson), ("double", a.double.asJson), ("number", a.number.asJson), ("integer", a.integer.asJson), ("untyped", a.untyped.asJson), ("custom", a.custom.asJson), ("customComplex", a.customComplex.asJson), ("nested", a.nested.asJson), ("nestedArray", a.nestedArray.asJson), ("requiredArray", a.requiredArray.asJson)))).mapJsonObject(_.filterKeys(key => !(readOnlyKeys contains key)))
122126
}
123-
implicit val decodeTypes: Decoder[Types] = new Decoder[Types] { final def apply(c: HCursor): Decoder.Result[Types] = for (v0 <- c.downField("array").as[Option[Vector[Boolean]]]; v1 <- c.downField("map").as[Option[Map[String, Boolean]]]; v2 <- c.downField("obj").as[Option[io.circe.Json]]; v3 <- c.downField("bool").as[Option[Boolean]]; v4 <- c.downField("string").as[Option[String]]; v5 <- c.downField("date").as[Option[java.time.LocalDate]]; v6 <- c.downField("date_time").as[Option[java.time.OffsetDateTime]]; v7 <- c.downField("long").as[Option[Long]]; v8 <- c.downField("int").as[Option[Int]]; v9 <- c.downField("float").as[Option[Float]]; v10 <- c.downField("double").as[Option[Double]]; v11 <- c.downField("number").as[Option[BigDecimal]]; v12 <- c.downField("integer").as[Option[BigInt]]; v13 <- c.downField("untyped").as[Option[io.circe.Json]]; v14 <- c.downField("custom").as[Option[Foo]]; v15 <- c.downField("customComplex").as[Option[Foo[Bar]]]; v16 <- c.downField("nested").as[Option[Types.Nested]]; v17 <- c.downField("nestedArray").as[Option[Vector[Types.NestedArray]]]; v18 <- c.downField("requiredArray").as[Vector[String]]) yield Types(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) }
127+
implicit val decodeTypes: Decoder[Types] = new Decoder[Types] { final def apply(c: HCursor): Decoder.Result[Types] = for (v0 <- c.downField("array").as[Option[Vector[Boolean]]]; v1 <- c.downField("map").as[Option[Map[String, Boolean]]]; v2 <- c.downField("obj").as[Option[io.circe.Json]]; v3 <- c.downField("bool").as[Option[Boolean]]; v4 <- c.downField("string").as[Option[String]]; v5 <- c.downField("date").as[Option[java.time.LocalDate]]; v6 <- c.downField("date_time").as[Option[java.time.OffsetDateTime]]; v7 <- c.downField("byte").as[Option[String]]; v8 <- c.downField("long").as[Option[Long]]; v9 <- c.downField("int").as[Option[Int]]; v10 <- c.downField("float").as[Option[Float]]; v11 <- c.downField("double").as[Option[Double]]; v12 <- c.downField("number").as[Option[BigDecimal]]; v13 <- c.downField("integer").as[Option[BigInt]]; v14 <- c.downField("untyped").as[Option[io.circe.Json]]; v15 <- c.downField("custom").as[Option[Foo]]; v16 <- c.downField("customComplex").as[Option[Foo[Bar]]]; v17 <- c.downField("nested").as[Option[Types.Nested]]; v18 <- c.downField("nestedArray").as[Option[Vector[Types.NestedArray]]]; v19 <- c.downField("requiredArray").as[Vector[String]]) yield Types(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) }
124128
case class Nested(prop1: Option[String] = None)
125129
object Nested {
126130
implicit val encodeNested: Encoder.AsObject[Nested] = {

0 commit comments

Comments
 (0)