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

Support Json.valueFormat #401

Open
lalnuo opened this issue Jun 18, 2021 · 3 comments
Open

Support Json.valueFormat #401

lalnuo opened this issue Jun 18, 2021 · 3 comments

Comments

@lalnuo
Copy link
Contributor

lalnuo commented Jun 18, 2021

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
@vnt-83
Copy link

vnt-83 commented Jul 28, 2021

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

@lalnuo
Copy link
Contributor Author

lalnuo commented Aug 26, 2021

@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

@Javakky-pxv
Copy link
Collaborator

@lalnuo
We are currently reviewing it. It may take some time, but we plan to address it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants