forked from loafle/openapi-generator-original
added main app, now validates with 51756c1d8e
This commit is contained in:
parent
6636acf2d3
commit
53721239f4
@ -31,7 +31,7 @@ object ScalatraServerGenerator extends BasicScalaGenerator {
|
||||
override def destinationDir = outputFolder + "/src/main/scala"
|
||||
|
||||
override def modelPackage = Some("com.wordnik.client.model")
|
||||
|
||||
|
||||
// template used for apis
|
||||
apiTemplateFiles ++= Map("api.mustache" -> ".scala")
|
||||
|
||||
@ -44,23 +44,26 @@ object ScalatraServerGenerator extends BasicScalaGenerator {
|
||||
("README.mustache", outputFolder, "README.md"),
|
||||
("build.sbt", outputFolder, "build.sbt"),
|
||||
("JsonUtil.scala", destinationDir, "JsonUtil.scala"),
|
||||
("ServletApp.mustache", destinationDir, "ServletApp.scala"),
|
||||
("project/build.properties", outputFolder, "project/build.properties"),
|
||||
("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
|
||||
|
||||
mutable.map(k => {
|
||||
k._1 match {
|
||||
// the scalatra templates like lower-case httpMethods
|
||||
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") => {
|
||||
val path = {
|
||||
val arr = k._2.toString.split("/")
|
||||
if (arr.length >= 2)
|
||||
if (arr.length >= 2) {
|
||||
mutable += "basePart" -> k._2
|
||||
"/" + arr.slice(2, arr.length).mkString("", "/", "")
|
||||
else
|
||||
} else
|
||||
k._2.toString
|
||||
}
|
||||
// rip out the root path
|
||||
|
@ -8,7 +8,7 @@ import org.scalatra.swagger._
|
||||
|
||||
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
|
||||
|
||||
{{#operations}}
|
||||
@ -17,34 +17,34 @@ class {{name}} (implicit val swagger: Swagger) extends ScalatraServlet with Swag
|
||||
summary("{{{summary}}}"),
|
||||
nickname("{{nickname}}"),
|
||||
responseClass("{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}void{{/returnType}}"),
|
||||
endpoint("{TBD}"),
|
||||
endpoint("{{basePart}}"),
|
||||
notes("{{{notes}}}"),
|
||||
parameters(
|
||||
{{#allParams}}
|
||||
{{#queryParam}}
|
||||
{{#queryParameter}}
|
||||
Parameter("{{paramName}}", "{{{description}}}",
|
||||
paramType = ParamType.Query,
|
||||
required = {{required}},
|
||||
allowMultiple = {{allowMultiple}},
|
||||
{{#allowableValues}}allowableValues = "{{{allowableValues}}}",{{/allowableValues}}
|
||||
{{#allowableValues}}allowableValues = AllowableValues("{{{allowableValues}}}"),{{/allowableValues}}
|
||||
defaultValue = {{#defaultValue}}Some({{{defaultValue}}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}},
|
||||
dataType = DataType("{{dataType}}"))
|
||||
{{/queryParam}}
|
||||
{{#pathParam}}
|
||||
{{/queryParameter}}
|
||||
{{#pathParameter}}
|
||||
Parameter("{{paramName}}", "{{{description}}}",
|
||||
dataType = DataType.String,
|
||||
paramType = ParamType.Path)
|
||||
{{/pathParam}}
|
||||
{{#headerParam}}
|
||||
{{/pathParameter}}
|
||||
{{#headerParameter}}
|
||||
Parameter("{{paramName}}", "{{{description}}}",
|
||||
dataType = DataType("{{dataType}}"),
|
||||
paramType = ParamType.Header)
|
||||
{{/headerParam}}
|
||||
{{#bodyParam}}
|
||||
{{/headerParameter}}
|
||||
{{#bodyParameter}}
|
||||
Parameter("{{paramName}}", "{{{description}}}",
|
||||
dataType = DataType("{{dataType}}"),
|
||||
paramType = ParamType.Body)
|
||||
{{/bodyParam}}
|
||||
{{/bodyParameter}}
|
||||
{{#hasMore}},{{/hasMore}}{{newline}}
|
||||
{{/allParams}}
|
||||
)) {
|
||||
|
@ -24,6 +24,8 @@ libraryDependencies ++= Seq(
|
||||
"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/"
|
||||
|
||||
ivyXML := <dependencies>
|
||||
|
Loading…
x
Reference in New Issue
Block a user