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

Can it use the defined Reads and Writes for Json generation #75

Closed
prithvi23 opened this issue Apr 14, 2016 · 6 comments
Closed

Can it use the defined Reads and Writes for Json generation #75

prithvi23 opened this issue Apr 14, 2016 · 6 comments
Labels

Comments

@prithvi23
Copy link

  1. The json that is emitted out is actually not matching the custom Writes that has been defined. I'm not sure if the play Formats are being used for Json generation
  2. The Json generation fails for the class Consumer below as it uses the trait.

sealed trait ValueType
object Mobile extends ValueType

case class Consumer(root: String, users: Map[String, User], valueType: ValueType = Mobile)

@kailuowang
Copy link
Member

@prithvi23 currently it's using reflection to get the fields. It doesn't support using a custom Reads or Writes. If you think about it, to use a custom reads and writes, you will need to provide not only the reads/writes and also an instance of the class, which will probably be more complex to write than just writing the schema in the swagger.yml.
For the error case you provided, did the generation fails with a runtime exception or doe it just fail to provide a valid schema?

@prithvi23
Copy link
Author

Can the Formats be used as an implicit?

[NoSuchElementException: None.get]
This is the error that I get at the time of generation.

Its failing at line number 19

def specs = cached("swaggerDef") {
18 Action.async { _ =>
19 Future.fromTry(generator.generate()).map(Ok(_))
20 }
21

@prithvi23
Copy link
Author

Also Just would like to thank you for a good utility and a prompt response. :)

@kailuowang kailuowang added the bug label Apr 14, 2016
@kailuowang
Copy link
Member

Looks like you are trying to encode an ADT, that is basically an enum. play-swagger doesn't support generating swagger doc for this type of data yet, (although it shouldn't throw a runtime exception). The best work around again is to write your schema definition in swagger.yml yourself ( don't $ref your Consumer class)

@prithvi23
Copy link
Author

That would be nice - can you point me to a sample Swagger.yml file that overrides the definitions?
I also would need to generate custom definitions like List of consumer objects as Consumers etc...

@kailuowang
Copy link
Member

you should be able to find plenty here.
http://editor.swagger.io/#/

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

No branches or pull requests

3 participants