forked from loafle/openapi-generator-original
added main app, now validates with 51756c1d8e
This commit is contained in:
parent
6636acf2d3
commit
53721239f4
@ -44,23 +44,26 @@ object ScalatraServerGenerator extends BasicScalaGenerator {
|
|||||||
("README.mustache", outputFolder, "README.md"),
|
("README.mustache", outputFolder, "README.md"),
|
||||||
("build.sbt", outputFolder, "build.sbt"),
|
("build.sbt", outputFolder, "build.sbt"),
|
||||||
("JsonUtil.scala", destinationDir, "JsonUtil.scala"),
|
("JsonUtil.scala", destinationDir, "JsonUtil.scala"),
|
||||||
|
("ServletApp.mustache", destinationDir, "ServletApp.scala"),
|
||||||
("project/build.properties", outputFolder, "project/build.properties"),
|
("project/build.properties", outputFolder, "project/build.properties"),
|
||||||
("project/plugins.sbt", outputFolder, "project/plugins.sbt"))
|
("project/plugins.sbt", outputFolder, "project/plugins.sbt"))
|
||||||
|
|
||||||
def processApiMap(m: Map[String, AnyRef]): Map[String, AnyRef] = {
|
override def processApiMap(m: Map[String, AnyRef]): Map[String, AnyRef] = {
|
||||||
val mutable = scala.collection.mutable.Map() ++ m
|
val mutable = scala.collection.mutable.Map() ++ m
|
||||||
|
|
||||||
mutable.map(k => {
|
mutable.map(k => {
|
||||||
k._1 match {
|
k._1 match {
|
||||||
// the scalatra templates like lower-case httpMethods
|
// the scalatra templates like lower-case httpMethods
|
||||||
case e: String if (e == "httpMethod") => mutable += "httpMethod" -> k._2.toString.toLowerCase
|
case e: String if (e == "httpMethod") => mutable += "httpMethod" -> k._2.toString.toLowerCase
|
||||||
// convert path into ruby-ish syntax (i.e. /pet.{format}/{petId} => /:petId
|
|
||||||
|
// convert path into ruby-ish syntax without basePart (i.e. /pet.{format}/{petId} => /:petId
|
||||||
case e: String if (e == "path") => {
|
case e: String if (e == "path") => {
|
||||||
val path = {
|
val path = {
|
||||||
val arr = k._2.toString.split("/")
|
val arr = k._2.toString.split("/")
|
||||||
if (arr.length >= 2)
|
if (arr.length >= 2) {
|
||||||
|
mutable += "basePart" -> k._2
|
||||||
"/" + arr.slice(2, arr.length).mkString("", "/", "")
|
"/" + arr.slice(2, arr.length).mkString("", "/", "")
|
||||||
else
|
} else
|
||||||
k._2.toString
|
k._2.toString
|
||||||
}
|
}
|
||||||
// rip out the root path
|
// rip out the root path
|
||||||
|
@ -8,7 +8,7 @@ import org.scalatra.swagger._
|
|||||||
|
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
|
|
||||||
class {{name}} (implicit val swagger: Swagger) extends ScalatraServlet with SwaggerBase with SwaggerSupport {
|
class {{className}} (implicit val swagger: Swagger) extends ScalatraServlet with SwaggerBase with SwaggerSupport {
|
||||||
protected def buildFullUrl(path: String) = "{{basePath}}/%s" format path
|
protected def buildFullUrl(path: String) = "{{basePath}}/%s" format path
|
||||||
|
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
@ -17,34 +17,34 @@ class {{name}} (implicit val swagger: Swagger) extends ScalatraServlet with Swag
|
|||||||
summary("{{{summary}}}"),
|
summary("{{{summary}}}"),
|
||||||
nickname("{{nickname}}"),
|
nickname("{{nickname}}"),
|
||||||
responseClass("{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}void{{/returnType}}"),
|
responseClass("{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}void{{/returnType}}"),
|
||||||
endpoint("{TBD}"),
|
endpoint("{{basePart}}"),
|
||||||
notes("{{{notes}}}"),
|
notes("{{{notes}}}"),
|
||||||
parameters(
|
parameters(
|
||||||
{{#allParams}}
|
{{#allParams}}
|
||||||
{{#queryParam}}
|
{{#queryParameter}}
|
||||||
Parameter("{{paramName}}", "{{{description}}}",
|
Parameter("{{paramName}}", "{{{description}}}",
|
||||||
paramType = ParamType.Query,
|
paramType = ParamType.Query,
|
||||||
required = {{required}},
|
required = {{required}},
|
||||||
allowMultiple = {{allowMultiple}},
|
allowMultiple = {{allowMultiple}},
|
||||||
{{#allowableValues}}allowableValues = "{{{allowableValues}}}",{{/allowableValues}}
|
{{#allowableValues}}allowableValues = AllowableValues("{{{allowableValues}}}"),{{/allowableValues}}
|
||||||
defaultValue = {{#defaultValue}}Some({{{defaultValue}}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}},
|
defaultValue = {{#defaultValue}}Some({{{defaultValue}}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}},
|
||||||
dataType = DataType("{{dataType}}"))
|
dataType = DataType("{{dataType}}"))
|
||||||
{{/queryParam}}
|
{{/queryParameter}}
|
||||||
{{#pathParam}}
|
{{#pathParameter}}
|
||||||
Parameter("{{paramName}}", "{{{description}}}",
|
Parameter("{{paramName}}", "{{{description}}}",
|
||||||
dataType = DataType.String,
|
dataType = DataType.String,
|
||||||
paramType = ParamType.Path)
|
paramType = ParamType.Path)
|
||||||
{{/pathParam}}
|
{{/pathParameter}}
|
||||||
{{#headerParam}}
|
{{#headerParameter}}
|
||||||
Parameter("{{paramName}}", "{{{description}}}",
|
Parameter("{{paramName}}", "{{{description}}}",
|
||||||
dataType = DataType("{{dataType}}"),
|
dataType = DataType("{{dataType}}"),
|
||||||
paramType = ParamType.Header)
|
paramType = ParamType.Header)
|
||||||
{{/headerParam}}
|
{{/headerParameter}}
|
||||||
{{#bodyParam}}
|
{{#bodyParameter}}
|
||||||
Parameter("{{paramName}}", "{{{description}}}",
|
Parameter("{{paramName}}", "{{{description}}}",
|
||||||
dataType = DataType("{{dataType}}"),
|
dataType = DataType("{{dataType}}"),
|
||||||
paramType = ParamType.Body)
|
paramType = ParamType.Body)
|
||||||
{{/bodyParam}}
|
{{/bodyParameter}}
|
||||||
{{#hasMore}},{{/hasMore}}{{newline}}
|
{{#hasMore}},{{/hasMore}}{{newline}}
|
||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
)) {
|
)) {
|
||||||
|
@ -24,6 +24,8 @@ libraryDependencies ++= Seq(
|
|||||||
"javax.servlet" % "javax.servlet-api" % "3.0.1" % "provided;container;test;runtime"
|
"javax.servlet" % "javax.servlet-api" % "3.0.1" % "provided;container;test;runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
resolvers += Resolver.url("local-ivy", new URL("file://" + Path.userHome.absolutePath + "/.ivy2/local"))(Resolver.ivyStylePatterns)
|
||||||
|
|
||||||
resolvers += "Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
|
resolvers += "Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
|
||||||
|
|
||||||
ivyXML := <dependencies>
|
ivyXML := <dependencies>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user