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

Added password format support #256

Merged
merged 3 commits into from
Apr 27, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ 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, _))
Expand Down Expand Up @@ -338,6 +339,12 @@ object SwaggerUtil {
res <- typeName[L, F]("number", Option(d.getFormat), customTpeName).map(Resolved[L](_, None, None))
} yield res

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

case x =>
fallbackPropertyTypeHandler(x).map(Resolved[L](_, None, None))
})
Expand Down
37 changes: 37 additions & 0 deletions modules/codegen/src/test/scala/core/issues/Issue255.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package core.issues

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

import scala.meta._

class Issue255 extends FunSuite with Matchers with SwaggerSpecRunner {
val swagger: String = s"""
|swagger: "2.0"
|info:
| title: Whatever
| version: 1.0.0
|host: localhost:1234
|schemes:
| - http
|definitions:
| Foo:
| type: object
| properties:
| somePassword:
| type: string
| format: password
|""".stripMargin

test("Test password format generation") {
val (
ProtocolDefinitions(ClassDefinition(_, _, c1, _, _) :: Nil, _, _, _),
_,
_
) = runSwaggerSpec(swagger)(Context.empty, Http4s)

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