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 6, 2015
1 parent f2faa56 commit 6966216
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,32 @@ import argo.jdom.JsonNodeFactories._
import io.github.daviddenton.fintrospect.FintrospectModule._
import io.github.daviddenton.fintrospect._
import io.github.daviddenton.fintrospect.util.ArgoUtil._
import org.jboss.netty.handler.codec.http.HttpMethod

import scala.collection.JavaConversions._

object Swagger1dot1Json {

private case class PathMethod(method: HttpMethod, summary: String, params: Seq[Parameter], responses: Seq[PathResponse], securities: Seq[Security])

private def render(p: Parameter): JsonNode = obj(
"name" -> string(p.name),
"paramType" -> string(p.location.toString),
"required" -> booleanNode(true),
"dataType" -> string(p.paramType)
)

private def render(pm: PathMethod): (String, JsonNode) = pm.method.getName.toLowerCase -> obj(
"httpMethod" -> string(pm.method.getName),
"nickname" -> string(pm.summary),
"summary" -> string(pm.summary),
"produces" -> array(string("application/json")),
"parameters" -> array(pm.params.map(render): _*),
"errorResponses" -> {
array(pm.responses.map(r => r.code -> string(r.description)).map(p => obj("code" -> number(p._1), "description" -> p._2)))
}
)

private def render(r: ModuleRoute): (String, JsonNode) = {
render(PathMethod(r.description.method, r.description.value, r.segmentMatchers.flatMap(_.toParameter), Seq(), Seq()))
val params = r.segmentMatchers.flatMap(_.toParameter)

r.description.method.getName.toLowerCase -> obj(
"httpMethod" -> string(r.description.method.getName),
"nickname" -> string(r.description.value),
"summary" -> string(r.description.value),
"produces" -> array(string("application/json")),
"parameters" -> array(params.map(render): _*),
"errorResponses" -> {
array(Seq[PathResponse]().map(r => r.code -> string(r.description)).map(p => obj("code" -> number(p._1), "description" -> p._2)))
}
)
}

def apply(): Renderer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.github.daviddenton.fintrospect.util.ArgoUtil._
import org.jboss.netty.handler.codec.http.HttpMethod

object Swagger2dot0Json {

private case class PathMethod(method: HttpMethod, summary: String, params: Seq[Parameter], responses: Seq[PathResponse], securities: Seq[Security])

private def render(p: Parameter): JsonNode = obj(
Expand All @@ -17,21 +18,17 @@ object Swagger2dot0Json {
"type" -> string(p.paramType)
)


private def render(pm: PathMethod): (String, JsonNode) = {
pm.method.getName.toLowerCase -> obj(
"summary" -> string(pm.summary),
private def render(r: ModuleRoute): (String, JsonNode) = {
val params = r.segmentMatchers.flatMap(_.toParameter)
r.description.method.getName.toLowerCase -> obj(
"summary" -> string(r.description.value),
"produces" -> array(string("application/json")),
"parameters" -> array(pm.params.map(render): _*),
"responses" -> obj(pm.responses.map(r => r.code -> obj("description" -> string(r.description))).map(cd => cd._1.toString -> cd._2)),
"security" -> array(obj(pm.securities.map(_.toPathSecurity)))
"parameters" -> array(params.map(render): _*),
"responses" -> obj(Seq(PathResponse(200, "")).map(r => r.code -> obj("description" -> string(r.description))).map(cd => cd._1.toString -> cd._2)),
"security" -> array(obj(Seq[Security]().map(_.toPathSecurity)))
)
}

private def render(r: ModuleRoute): (String, JsonNode) = {
render(PathMethod(r.description.method, r.description.value, r.segmentMatchers.flatMap(_.toParameter), Seq(PathResponse(200, "")), Seq()))
}

def apply(): Renderer =
mr => {
val paths = mr
Expand Down

0 comments on commit 6966216

Please sign in to comment.