Skip to content

Commit

Permalink
dave - tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
david denton committed Mar 28, 2015
1 parent 4020cc3 commit 300e328
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ class Swagger2dot0Json private(apiInfo: ApiInfo) extends Renderer {
"type" -> string(rp._2.paramType)
)

private def render(r: ModuleRoute): Field = {
r.on.method.getName.toLowerCase -> obj(
private def render(r: ModuleRoute): (Field, List[Field]) = {
val (fields, definitions) = renderPaths(r)
val route = r.on.method.getName.toLowerCase -> obj(
"tags" -> array(Seq(string(r.basePath.toString)): _*),
"summary" -> r.description.summary.map(string).getOrElse(nullNode()),
"produces" -> array(r.description.produces.map(m => string(m.value)): _*),
"consumes" -> array(r.description.consumes.map(m => string(m.value)): _*),
"parameters" -> array(r.allParams.map(render).toSeq: _*),
"responses" -> obj(renderPaths(r)._1),
"responses" -> obj(fields),
"security" -> array(obj(Seq[Security]().map(_.toPathSecurity)))
)
(route, definitions)
}

private def renderPaths(r: ModuleRoute) = {
private def renderPaths(r: ModuleRoute): (List[Field], List[Field]) = {
r.description.responses.foldLeft((List[Field](), List[Field]())) {
case ((fields, models), nextResp) =>
val newSchema: Option[Schema] = Option(nextResp.example).map(schemaGenerator.toSchema)
Expand All @@ -48,7 +50,7 @@ class Swagger2dot0Json private(apiInfo: ApiInfo) extends Renderer {
def apply(mr: Seq[ModuleRoute]): JsonRootNode = {
val paths = mr
.groupBy(_.toString)
.map { case (path, routes) => path -> obj(routes.map(render))}.toSeq
.map { case (path, routes) => path -> obj(routes.map(a => render(a)._1))}.toSeq

obj(
"swagger" -> string("2.0"),
Expand Down

0 comments on commit 300e328

Please sign in to comment.