Skip to content
Permalink
Browse files

Merge pull request #283 from avast/issue255

#255 improvement - Fixed issue with type:file
  • Loading branch information...
blast-hardcheese committed May 10, 2019
2 parents 5de428a + 17d85ea commit e413b916742bfe5c407d8bf56fc571aa55769e77
@@ -238,22 +238,23 @@ object SwaggerUtil {
customTpe <- customType.flatTraverse(liftCustomType _)
result <- customTpe.fold({
(typeName, format) match {
case ("string", Some("password")) => stringType(None)
case ("string", Some("date")) => dateType()
case ("string", Some("date-time")) => dateTimeType()
case ("string", fmt) => stringType(fmt).map(log(fmt, _))
case ("number", Some("float")) => floatType()
case ("number", Some("double")) => doubleType()
case ("number", fmt) => numberType(fmt).map(log(fmt, _))
case ("integer", Some("int32")) => intType()
case ("integer", Some("int64")) => longType()
case ("integer", fmt) => integerType(fmt).map(log(fmt, _))
case ("boolean", fmt) => booleanType(fmt).map(log(fmt, _))
case ("array", fmt) => arrayType(fmt).map(log(fmt, _))
case ("string", Some("password")) => stringType(None)
case ("string", Some("date")) => dateType()
case ("string", Some("date-time")) => dateTimeType()
case ("string", fmt @ Some("binary")) => fileType(None).map(log(fmt, _))
case ("string", fmt) => stringType(fmt).map(log(fmt, _))
case ("number", Some("float")) => floatType()
case ("number", Some("double")) => doubleType()
case ("number", fmt) => numberType(fmt).map(log(fmt, _))
case ("integer", Some("int32")) => intType()
case ("integer", Some("int64")) => longType()
case ("integer", fmt) => integerType(fmt).map(log(fmt, _))
case ("boolean", fmt) => booleanType(fmt).map(log(fmt, _))
case ("array", fmt) => arrayType(fmt).map(log(fmt, _))
case ("file", fmt) =>
fileType(fmt).map(log(fmt, _))
case ("binary", _) =>
fileType(None).map(log(None, _))
fileType(None).map(log(fmt, _))
case ("binary", fmt) =>
fileType(None).map(log(fmt, _))
case ("object", fmt) => objectType(fmt).map(log(fmt, _))
case (tpe, fmt) =>
fallbackType(tpe, fmt)
@@ -345,6 +346,12 @@ object SwaggerUtil {
res <- typeName[L, F]("string", Option(p.getFormat), customTpeName).map(Resolved[L](_, None, None))
} yield res

case f: FileSchema =>
for {
customTpeName <- customTypeName(f)
res <- typeName[L, F]("file", Option(f.getFormat), customTpeName).map(Resolved[L](_, None, None))
} yield res

case x =>
fallbackPropertyTypeHandler(x).map(Resolved[L](_, None, None))
})
@@ -1,7 +1,7 @@
package core.issues

import com.twilio.guardrail.generators.Http4s
import com.twilio.guardrail.{ClassDefinition, Context, ProtocolDefinitions, RandomType}
import com.twilio.guardrail.{ClassDefinition, Context, ProtocolDefinitions}
import org.scalatest.{FunSuite, Matchers}
import support.SwaggerSpecRunner

@@ -23,6 +23,11 @@ class Issue255 extends FunSuite with Matchers with SwaggerSpecRunner {
| somePassword:
| type: string
| format: password
| someFile:
| type: file
| someBinary:
| type: string
| format: binary
|""".stripMargin

test("Test password format generation") {
@@ -31,7 +36,12 @@ class Issue255 extends FunSuite with Matchers with SwaggerSpecRunner {
_,
_
) = runSwaggerSpec(swagger)(Context.empty, Http4s)

c1.structure shouldBe q"case class Foo(somePassword: Option[String] = None)".structure

val expected = q"case class Foo(somePassword: Option[String] = None, someFile: Option[java.io.File] = None, someBinary: Option[java.io.File] = None)"
compare(c1, expected)
}

def compare(t: Tree, t2: Tree) = {
t.structure shouldBe t2.structure
}
}

0 comments on commit e413b91

Please sign in to comment.
You can’t perform that action at this time.