Comments (16)
This and issue #22 are things I wanted to address with MetaData. It should be pretty simple to make the functionality, the tricky part is to make it feel nice and not bring swagger specific stuff into rho proper.
from rho.
I would say that our MetaData
should hold a type that describes the resource entity. This is usually a case class that I would add as TypeTag
.
Example Types for Swagger's pet store
GET /pet
should be a Seq[Pet]
GET /pet/{id}
should be a Pet
POST /pet
should be a Seq[Pet]
PUT /pet
should be a Seq[Pet]
Maybe we can use something like this?
object MyService extends RhoService with SwaggerSupport {
GET / "pet" / "findByTags" +? param[String]("tags") ++ typeTag[Seq[Pet]] |>> { (tags: String) => "use a service to find pets by tags" }
GET / "pet" / pathVar[Long]("id") ++ typeTag[Pet] |>> { (id: Long) => "use a service to find a pet by id" }
}
from rho.
What you're doing describes the models which should be taken care of, though they will come back into play as we begin to require a status on the return, eg OK(cat: Pet)
. Do you want the comment, "use a service to find a pet by id"
? That is what is missing from the swagger support.
from rho.
I'm currently only interested to have a Data Type (and there subtypes) in my Swagger API documentation. So if I understood you correctly we can resolve this by using our new way to describe the response (e.g. OK(pets: Seq[Pet])
, OK(pet: Pet)
), right?
Ignore the string "use a service to find a pet by id"
and think about a service call to get the pets ;-)
from rho.
I'm not certain it works in the new way yet, I only have that to the point
of examining the syntax, but the old way should build models for you
automatically from collections and case classes. Check the example for a
case class model, but I haven't tested it first hand with collections.
(Good place for some tests!) I expect the shift to leave this unchanged.
On Aug 6, 2014 2:13 PM, "André Rouél" [email protected] wrote:
I'm currently only interested to have a Data Type (and there subtypes) in
my Swagger API documentation. So if I understood you correctly we can
resolve this by using our new way to describe the response (e.g. OK(pets:
Seq[Pet]), OK(pet: Pet)), right?Ignore the string "use a service to find a pet by id" and think about a
service call to get the pets ;-)—
Reply to this email directly or view it on GitHub
#21 (comment).
from rho.
Sorry, maybe I missed something but in the Rho example for swagger is nothing that forms a DataType.
from rho.
https://github.com/http4s/rho/blob/master/examples/src/main/scala/org/http4s/rho/swaggerdemo/Main.scala#L17
That builds a 'model' for you using reflection based on the return type of the route. I just discovered that the reflection isnt working right for types that have type parameters: I need to figure out how to get a TypeTag converted to a Manifest properly. That means its not working for List etc. I'm adding bug to this issue for that reason.
from rho.
Thank you. Okay, I dig my nose in it. Maybe I can bring that further. FYI, I will use rho-swagger in the next weeks to find hard edges and cut them.
from rho.
Little update, I don't think its worth the effort, or maybe even possible to convert a TypeTag to a Manifest properly. We may need to build our own machinery and quit relying on the json4s reflection until it operates on TypeTags.
from rho.
Maybe we can have a chat about this if you have time.
from rho.
We should think also about the following use case when it comes to the type definition of a response.
GET / "pet" / id |>> { id: Int =>
val found = for {
pet <- businessLayer.findPet(id)
} yield Ok(pet)
found getOrElse NotFound(s"Pet $id not found.")
}
With our existing implementation we cannot determine the data type automatically when explicitly handling different cases with different status codes and bodies.
So I assume it is better to define the data type in this case for Swagger explicitly.
from rho.
I've thought about this myself and its an interesting question. I don't
know if its possible (without macros) to do it. The problem is a function
can only return one result, so each of the two examples you've shown are
different types, so scala will knock the result type down to the greatest
common denominator type. I would like to be able to have rho give a list of
the different result types, but I suspect that will require macros. I'm
actually not against that strategy, but I also don't know if it can be done
even with macros, and am pretty sure it will require a lot of work.
On Thu, Aug 21, 2014 at 1:42 PM, André Rouél [email protected]
wrote:
We should think also about the following use case when it comes to the
type definition of a response.GET / "pet" / id |>> { id: Int =>
val found = for {
pet <- businessLayer.findPet(id)
} yield Ok(pet)
found getOrElse NotFound(s"Pet $id not found.")
}With our existing implementation we cannot determine the data type
automatically when explicitly handling different cases with different
status codes and bodies.So I assume it is better to define the data type in this case for Swagger
explicitly.—
Reply to this email directly or view it on GitHub
#21 (comment).
from rho.
Agree with you. Maybe we should think about to keep it very simplistic at first. I would say in the beginning we should only support the Response Class/Model in the success case when Status.Ok
is in use. If I reduce it to that I come to the conclusion that Either
(or something similar) can help us to determine the model. Usually I use in the non-successful case a case class Message
.
What about this?
GET / "pet" / id |>> { id: Int =>
val found = for {
pet <- businessLayer.findPet(id)
} yield -\/(Ok(pet))
found getOrElse \/-(NotFound(Message(s"Pet $id not found.")))
}
I assume a scalaz.\/[NotFound[Message],Ok[Pet]]
would help to handle it for Swagger.
from rho.
Yes, that would help. The whole concept needs some work, as right now there
isn't support for the status type at all. That would be a good start here,
getting status codes built in. After that, the disjunction stuff would seem
relatively straight forward.
On Fri, Aug 22, 2014 at 3:22 PM, André Rouél [email protected]
wrote:
Agree with you. Maybe we should think about to keep it very simplistic at
first. I would say in the beginning we should only support the Response
Class/Model in the success case when Status.Ok is in use. If I reduce it
to that I come to the conclusion that Either (or something similar) can
help us to determine the model. Usually I use in the non-successful case a
case class Message.What about this?
GET / "pet" / id |>> { id: Int =>
val found = for {
pet <- businessLayer.findPet(id)} yield -\/(Ok(pet)) found getOrElse \/-(NotFound(Message(s"Pet $id not found.")))
}
I assume a scalaz./[NotFound[Message],Ok[Pet]] would help to handle it
for Swagger.—
Reply to this email directly or view it on GitHub
#21 (comment).
from rho.
Additionally we need to group the status code a bit to make something like this possible: scalaz.\/[ClientError[Message],Success[Pet]]
So we should group it as the following:
Informational
(1xx)Success
(2xx)Redirection
(3xx)Error
(4xx or 5xx)ClientError
(4xx)ServerError
(5xx)
from rho.
I believe this is closed. If not, lets make a new ticket with a summary of the problem and not reopen this thread, it seems to have strayed quite a bit from a single topic.
from rho.
Related Issues (20)
- Provide example using the Swagger UI Webjar HOT 1
- Got Error with http4s-scala-xml HOT 2
- NoSuchMethodError from rho 0.20.0-M1 HOT 2
- StringParser for value classes HOT 4
- Broken Links/URLs in `README.md` in branch `master` HOT 1
- Where is RhoService? HOT 2
- Feature Idea: Serving swagger in YAML
- Feature Idea: Customisable generic type names
- Is it possible to disable swagger.json endpoint and generate a plain json?
- Release v0.21.0 with swagger webjar implementation HOT 2
- Simple or-path produces incorrect tags HOT 1
- Getting 405 Method Not Allowed from combined routes HOT 3
- Demo example doesn't work HOT 1
- Non-class Scala types break TypeBuilder
- Logger Options in RhoRoutes
- Publish scala 3 artifacts HOT 3
- Getting 405 Method Not Allowed from combined routes with authentication
- Assembly doesn't like CollectionConverters
- Http4s, Scala, and main dependencies update HOT 3
- Maintainers wanted HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rho.