play-swagger
play-swagger copied to clipboard
Support `Json.valueFormat`
If class is defined like this:
case class TaskId(value: UUID) extends AnyVal
object TaskId {
implicit val jsonFormat = Json.valueFormat[TaskId]
}
And play is used for serialization:
Json.toJson(TaskId(UUID.randomUUID()))
It will serialize to:
"482a4c0a-dc04-4c67-8821-b93096978a3d"
It would be nice if play-swagger handled this automatically. Currently i'm writing mappings like this:
- type:models\.ids\.taskid
specAsParameter:
- type: string
format: uuid
Hello. I'm writing (only one) mappings for UUID like this:
- type: uuid
specAsParameter:
- type: string
format: uuid
in file conf/swagger-custom-mappings.yml
@vnt-83 This issue is about value classes.
For example, if you have following definition:
case class Foo(bar: String)
object Foo {
implicit val jsonFormat = Json.valueFormat[Foo]
}
You can do this:
scala> Json.parse("\"foo\"").as[Foo]
val res1: Foo = Foo(foo)
However play-swagger plugin will generate api definition like this:
components:
schemas:
Foo:
properties:
bar:
type: string
@lalnuo We are currently reviewing it. It may take some time, but we plan to address it.