Skip to content

Commit 5d42c8c

Browse files
committed
moved to petstore
1 parent 256485e commit 5d42c8c

File tree

5 files changed

+34
-152
lines changed

5 files changed

+34
-152
lines changed

bin/static-docs.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ cd $APP_DIR
2222

2323

2424
# if you've executed sbt assembly previously it will use that instead.
25-
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties -DfileMap=samples/client/wordnik-api/spec-files/resources.json"
26-
ags="$@ SwaggerDocGenerator https://api.wordnik.com/v4/resources.json"
25+
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties "
26+
ags="$@ com.wordnik.swagger.codegen.SwaggerDocGenerator http://petstore.swagger.wordnik.com/api/api-docs"
2727

2828
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/swagger-codegen.jar ]; then
2929
scala -cp target/scala-$SCALA_RUNNER_VERSION/swagger-codegen.jar $ags

build.sbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ name := "swagger-codegen"
77

88
version := "2.0.17-SNAPSHOT"
99

10-
scalaVersion := "2.10.0"
11-
1210
crossVersion := CrossVersion.full
1311

1412
javacOptions ++= Seq("-target", "1.6", "-source", "1.6", "-Xlint:unchecked", "-Xlint:deprecation")
@@ -17,6 +15,8 @@ scalacOptions ++= Seq("-optimize", "-unchecked", "-deprecation", "-Xcheckinit",
1715

1816
crossScalaVersions := Seq("2.9.0", "2.9.0-1", "2.9.1", "2.9.1-1", "2.9.2", "2.9.3", "2.10.0", "2.10.1", "2.10.2", "2.10.3", "2.10.4", "2.11.0", "2.11.1")
1917

18+
scalaVersion := "2.10.0"
19+
2020
libraryDependencies ++= Seq(
2121
"org.json4s" %% "json4s-jackson" % "3.2.10",
2222
"io.backchat.inflector" %% "scala-inflector" % "1.3.5",
@@ -66,7 +66,7 @@ publishTo <<= (version) { version: String =>
6666
Some("Sonatype Nexus Releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2")
6767
}
6868

69-
//publishTo := Some(Resolver.file("file", new File(Path.userHome.absolutePath+"/.m2/repository")))
69+
publishTo := Some(Resolver.file("file", new File(Path.userHome.absolutePath+"/.m2/repository")))
7070

7171
artifact in (Compile, assembly) ~= { art =>
7272
art.copy(`classifier` = Some("assembly"))

src/main/scala/com/wordnik/swagger/codegen/Codegen.scala

Lines changed: 0 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -43,134 +43,7 @@ object Codegen {
4343

4444
class Codegen(config: CodegenConfig) {
4545
implicit val formats = SwaggerSerializers.formats("1.2")
46-
/*
47-
@deprecated
48-
def generateSource(bundle: Map[String, AnyRef], templateFile: String): String = {
49-
val allImports = new HashSet[String]
50-
val includedModels = new HashSet[String]
51-
val modelList = new ListBuffer[Map[String, AnyRef]]
52-
val models = bundle("models").asInstanceOf[Tuple2[String, List[(String, AnyRef)]]]
53-
54-
models match {
55-
case e: List[Tuple2[String, Model]] => {
56-
e.foreach(m => {
57-
includedModels += m._1
58-
val modelMap = modelToMap(m._1, m._2)
59-
modelMap.getOrElse("imports", None) match {
60-
case im: Set[Map[String, String]] => im.foreach(m => m.map(e => allImports += e._2))
61-
case None =>
62-
}
63-
modelList += modelMap
64-
})
65-
}
66-
case _ =>
67-
}
68-
69-
val modelData = Map[String, AnyRef]("model" -> modelList.toList)
70-
val operationList = new ListBuffer[Map[String, AnyRef]]
71-
val classNameToOperationList = new HashMap[String, ListBuffer[AnyRef]]
72-
val apis = bundle("apis")
73-
apis match {
74-
case a: Map[String, List[(String, Operation)]] => {
75-
a.map(op => {
76-
val classname = op._1
77-
val ops = op._2
78-
for ((apiPath, operation) <- ops) {
79-
val opList = classNameToOperationList.getOrElse(classname, {
80-
val lb = new ListBuffer[AnyRef]
81-
classNameToOperationList += classname -> lb
82-
lb
83-
})
84-
opList += apiToMap(apiPath, operation)
85-
86-
CoreUtils.extractModelNames(operation).foreach(i => allImports += i)
87-
}
88-
})
89-
}
90-
91-
case None =>
92-
}
93-
94-
val f = new ListBuffer[AnyRef]
95-
classNameToOperationList.map(m => f += Map("classname" -> m._1, "operation" -> m._2))
96-
97-
val imports = new ListBuffer[Map[String, String]]
98-
val importScope = config.modelPackage match {
99-
case Some(s) => s + "."
100-
case None => ""
101-
}
102-
// do the mapping before removing primitives!
103-
allImports.foreach(i => {
104-
val model = config.toModelName(i)
105-
includedModels.contains(model) match {
106-
case false => {
107-
config.importMapping.containsKey(model) match {
108-
case true => {
109-
if(!imports.flatten.map(m => m._2).toSet.contains(config.importMapping(model))) {
110-
imports += Map("import" -> config.importMapping(model))
111-
}
112-
}
113-
case false =>
114-
}
115-
}
116-
case true =>
117-
}
118-
})
119-
120-
allImports --= config.defaultIncludes
121-
allImports --= primitives
122-
allImports --= containers
123-
allImports.foreach(i => {
124-
val model = config.toModelName(i)
125-
includedModels.contains(model) match {
126-
case false => {
127-
config.importMapping.containsKey(model) match {
128-
case true =>
129-
case false => {
130-
if(!imports.flatten.map(m => m._2).toSet.contains(importScope + model)){
131-
imports += Map("import" -> (importScope + model))
132-
}
133-
}
134-
}
135-
}
136-
case true => // no need to add the model
137-
}
138-
})
139-
140-
val rootDir = new java.io.File(".")
141-
val (resourcePath, (engine, template)) = Codegen.templates.getOrElseUpdate(templateFile, compileTemplate(templateFile, Some(rootDir)))
142-
143-
val requiredModels = {
144-
for(i <- allImports) yield {
145-
HashMap("name" -> i, "hasMore" -> "true")
146-
}
147-
}.toList
148-
149-
requiredModels.size match {
150-
case i if (i > 0) => requiredModels.last += "hasMore" -> "false"
151-
case _ =>
152-
}
153-
154-
var data = Map[String, AnyRef](
155-
"name" -> bundle("name"),
156-
"modelPackage" -> bundle.getOrElse("modelPackage", None),
157-
"package" -> bundle("package"),
158-
"baseName" -> bundle.getOrElse("baseName", None),
159-
"className" -> bundle("className"),
160-
"invokerPackage" -> bundle("invokerPackage"),
161-
"imports" -> imports,
162-
"requiredModels" -> requiredModels,
163-
"operations" -> f,
164-
"models" -> modelData,
165-
"basePath" -> bundle.getOrElse("basePath", ""))
166-
var output = engine.layout(resourcePath, template, data.toMap)
167-
168-
// a shutdown method will be added to scalate in an upcoming release
169-
engine.compiler.shutdown
170-
output
171-
}
17246

173-
*/
17447
def compileTemplate(templateFile: String, rootDir: Option[File] = None, engine: Option[TemplateEngine] = None): (String, (TemplateEngine, Template)) = {
17548
val engine = new TemplateEngine(rootDir orElse Some(new File(".")))
17649
val srcName = config.templateDir + "/" + templateFile

src/main/scala/com/wordnik/swagger/codegen/ScalaAsyncClientGenerator.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,8 @@ class ScalaAsyncClientGenerator(cfg: SwaggerGenConfig) extends BasicGenerator {
285285
modelTemplateFiles ++= cfg.api.modelTemplates
286286
apiTemplateFiles ++= cfg.api.apiTemplates
287287

288-
289288
codegen = new AsyncClientCodegen(cfg.api.clientName, this, Some(cfg.projectRoot))
290289

291-
292290
override def getBasePath(host: String, basePath: String, fileMap: Option[String]): String =
293291
cfg.api.baseUrl.getOrElse(super.getBasePath(host, basePath, fileMap))
294292
/*

src/main/scala/com/wordnik/swagger/codegen/model/SwaggerValidator.scala

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,77 +16,88 @@ object SwaggerValidator {
1616
val errors = new ListBuffer[ValidationError]
1717

1818
if(resource.apiVersion == "")
19-
errors += ValidationError("resourceListing", "apiVersion", ERROR)
19+
errors += ValidationError("resourceListing", "apiVersion is required", ERROR)
2020
if(resource.swaggerVersion == "")
21-
errors += ValidationError("resourceListing", "apiVersion", ERROR)
21+
errors += ValidationError("resourceListing", "apiVersion is required", ERROR)
2222
for(api <- resource.apis)
2323
validate(api, errors, "resourceListing")
2424
errors.toList
2525
}
2626

2727
def validate(ref: ApiListingReference, errors: ListBuffer[ValidationError], parent: String): Unit = {
2828
if(ref.path == "")
29-
errors += ValidationError(parent + ":api", "path", ERROR)
29+
errors += ValidationError(parent + ":[api]", "path is required", ERROR)
3030
}
3131

3232
def validate(api: ApiListing, errors: ListBuffer[ValidationError]): Unit = {
3333
if(api.swaggerVersion == "")
34-
errors += ValidationError("apiDeclaration", "swaggerVersion", ERROR)
34+
errors += ValidationError("apiDeclaration", "swaggerVersion is required", ERROR)
3535
if(api.apiVersion == "")
36-
errors += ValidationError("apiDeclaration", "apiVersion", ERROR)
36+
errors += ValidationError("apiDeclaration", "apiVersion is required", ERROR)
3737
if(api.basePath == "")
38-
errors += ValidationError("apiDeclaration", "basePath", ERROR)
38+
errors += ValidationError("apiDeclaration", "basePath is required", ERROR)
3939
if(api.resourcePath == "")
40-
errors += ValidationError("apiDeclaration", "resourcePath", ERROR)
40+
errors += ValidationError("apiDeclaration", "resourcePath is required", ERROR)
4141

42+
val name = {
43+
if(api.resourcePath == "") "[unknown]"
44+
else api.resourcePath
45+
}
4246
for(a <- api.apis) {
43-
validate(a, errors, api.resourcePath)
47+
validate(a, errors, name)
4448
}
4549

4650
api.models match {
4751
case Some(m) => for((name, model) <- m) {
48-
validate(model, errors, api.resourcePath)
52+
validate(model, errors, name)
4953
}
5054
case None =>
5155
}
5256
}
5357

5458
def validate(model: Model, errors: ListBuffer[ValidationError], parent: String): Unit = {
5559
if(model.id == "")
56-
errors += ValidationError(parent + ":model", "id", ERROR)
60+
errors += ValidationError(parent + ":[model]", "id is required", ERROR)
5761
}
5862

5963
def validate(desc: ApiDescription, errors: ListBuffer[ValidationError], parent: String): Unit = {
6064
if(desc.path == "")
61-
errors += ValidationError(parent + ":api", "path", ERROR)
65+
errors += ValidationError(parent + ":[api]", "path is required", ERROR)
6266
for(op <- desc.operations)
6367
validate(op, errors, parent + ":" + desc.path)
6468
}
6569

6670
def validate(op: Operation, errors: ListBuffer[ValidationError], parent: String): Unit = {
6771
if(op.method == "")
68-
errors += ValidationError(parent + ":operation", "method", ERROR)
72+
errors += ValidationError(parent + ":[operation]", "method is required", ERROR)
6973
if(op.nickname == "")
70-
errors += ValidationError(parent + ":" + op.method, "nickname", WARNING)
74+
errors += ValidationError(parent + ":" + op.method, "nickname is recommended", WARNING)
7175
if(op.responseClass == "")
72-
errors += ValidationError(parent + ":" + op.method, "responseClass", ERROR)
76+
errors += ValidationError(parent + ":" + op.method, "responseClass is required", ERROR)
7377
for(resp <- op.responseMessages)
7478
validate(resp, errors, parent)
7579
for(param <- op.parameters)
7680
validate(param, errors, parent)
7781
}
7882

7983
def validate(param: Parameter, errors: ListBuffer[ValidationError], parent: String): Unit = {
84+
val name = if(param.name == "")
85+
"[unknown]"
86+
else
87+
param.name
88+
8089
if(param.name == "")
81-
errors += ValidationError("Parameter", "name", ERROR)
90+
errors += ValidationError(parent + ":[parameter]", "name is required", ERROR)
8291
if(param.paramType == "")
83-
errors += ValidationError("Parameter", "paramType", ERROR)
92+
errors += ValidationError(parent + name, "paramType is required", ERROR)
93+
if(param.dataType == "")
94+
errors += ValidationError(parent + name, "type is required", ERROR)
8495
}
8596

8697
def validate(resp: ResponseMessage, errors: ListBuffer[ValidationError], parent: String): Unit = {
8798
if(resp.code == 0)
88-
errors += ValidationError("ResponseMessage", "code", ERROR)
99+
errors += ValidationError(parent + ":[responseMessage]", "code is required", ERROR)
89100
if(resp.message == 0)
90-
errors += ValidationError("ResponseMessage", "message", ERROR)
101+
errors += ValidationError(parent + ":[responseMessage]", "message is required", ERROR)
91102
}
92103
}

0 commit comments

Comments
 (0)