Skip to content

Commit 8426d6b

Browse files
committed
fix some errors for finch
1 parent ecb8623 commit 8426d6b

File tree

19 files changed

+439
-591
lines changed

19 files changed

+439
-591
lines changed

bin/finch-petstore-server.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
5+
while [ -h "$SCRIPT" ] ; do
6+
ls=`ls -ld "$SCRIPT"`
7+
link=`expr "$ls" : '.*-> \(.*\)$'`
8+
if expr "$link" : '/.*' > /dev/null; then
9+
SCRIPT="$link"
10+
else
11+
SCRIPT=`dirname "$SCRIPT"`/"$link"
12+
fi
13+
done
14+
15+
if [ ! -d "${APP_DIR}" ]; then
16+
APP_DIR=`dirname "$SCRIPT"`/..
17+
APP_DIR=`cd "${APP_DIR}"; pwd`
18+
fi
19+
20+
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
21+
22+
if [ ! -f "$executable" ]
23+
then
24+
mvn clean package
25+
fi
26+
27+
# if you've executed sbt assembly previously it will use that instead.
28+
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
29+
ags="$@ generate -t modules/swagger-codegen/src/main/resources/finch -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l finch -o samples/server/petstore/finch"
30+
31+
java $JAVA_OPTS -jar $executable $ags

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FinchServerCodegen.java

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@ public class FinchServerCodegen extends DefaultCodegen implements CodegenConfig
2525
protected String artifactId = "swagger-client";
2626
protected String artifactVersion = "1.0.0";
2727
protected String sourceFolder = "src/main/scala";
28+
protected String packageName = "io.swagger.petstore";
2829

2930
public FinchServerCodegen() {
3031
super();
3132
outputFolder = "generated-code/finch";
3233
modelTemplateFiles.put("model.mustache", ".scala");
3334
apiTemplateFiles.put("api.mustache", ".scala");
3435
embeddedTemplateDir = templateDir = "finch";
35-
apiPackage = "com.wordnik.client.api";
36-
modelPackage = "com.wordnik.client.model";
36+
// TODO organize the API scala files into proper folder
37+
// e.g. io/swagger/client/api
38+
apiPackage = "";
39+
// TODO organize the model scala files into proper folder
40+
// e.g. io/swagger/client/model
41+
modelPackage = "";
42+
3743

3844
setReservedWordsLowerCase(
3945
Arrays.asList(
@@ -83,15 +89,21 @@ public FinchServerCodegen() {
8389
additionalProperties.put(CodegenConstants.ARTIFACT_ID, artifactId);
8490
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);
8591

92+
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
93+
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
94+
} else {
95+
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
96+
};
97+
8698
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
8799
supportingFiles.add(new SupportingFile("build.sbt", "", "build.sbt"));
88-
supportingFiles.add(new SupportingFile("web.xml", "/src/main/webapp/WEB-INF", "web.xml"));
89-
supportingFiles.add(new SupportingFile("JettyMain.mustache", sourceFolder, "JettyMain.scala"));
90-
supportingFiles.add(new SupportingFile("Bootstrap.mustache", sourceFolder, "FinchBootstrap.scala"));
91-
supportingFiles.add(new SupportingFile("ServletApp.mustache", sourceFolder, "ServletApp.scala"));
92-
supportingFiles.add(new SupportingFile("project/build.properties", "project", "build.properties"));
93-
supportingFiles.add(new SupportingFile("project/plugins.sbt", "project", "plugins.sbt"));
94-
supportingFiles.add(new SupportingFile("sbt", "", "sbt"));
100+
//supportingFiles.add(new SupportingFile("web.xml", "/src/main/webapp/WEB-INF", "web.xml"));
101+
//supportingFiles.add(new SupportingFile("JettyMain.mustache", sourceFolder, "JettyMain.scala"));
102+
//supportingFiles.add(new SupportingFile("Bootstrap.mustache", sourceFolder, "FinchBootstrap.scala"));
103+
//supportingFiles.add(new SupportingFile("ServletApp.mustache", sourceFolder, "ServletApp.scala"));
104+
//supportingFiles.add(new SupportingFile("project/build.properties", "project", "build.properties"));
105+
//supportingFiles.add(new SupportingFile("project/plugins.sbt", "project", "plugins.sbt"));
106+
//supportingFiles.add(new SupportingFile("sbt", "", "sbt"));
95107

96108
supportingFiles.add(new SupportingFile("endpoint.mustache", sourceFolder, "endpoint.scala"));
97109
supportingFiles.add(new SupportingFile("errors.mustache", sourceFolder, "errors.scala"));
@@ -125,6 +137,9 @@ public FinchServerCodegen() {
125137
importMapping.put("LocalDate", "org.joda.time.LocalDate");
126138
importMapping.put("LocalTime", "org.joda.time.LocalTime");
127139

140+
cliOptions.clear();
141+
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Finch package name (e.g. io.swagger.petstore).")
142+
.defaultValue(this.packageName));
128143
cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
129144
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
130145
}
@@ -176,14 +191,11 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
176191
path = path.substring(0, path.length()-1);
177192
}
178193

179-
LOGGER.info("processing path: " + path);
180194
String[] items = path.split("/", -1);
181195
String scalaPath = "";
182196
int pathParamIndex = 0;
183197

184198
for (int i = 0; i < items.length; ++i) {
185-
//String i : items) {
186-
LOGGER.info("processing item: " + i);
187199
if (items[i].matches("^\\{(.*)\\}$")) { // wrap in {}
188200
// find the datatype of the parameter
189201
final CodegenParameter cp = op.pathParams.get(pathParamIndex);
@@ -196,15 +208,14 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
196208
if (i != items.length -1) {
197209
scalaPath = scalaPath + " / ";
198210
}
199-
LOGGER.info("processing scalaPath: " + scalaPath);
200211
}
201212

202213
// add ? to indicate query/header/form parameter
203214
if (op.formParams.size() > 0 || op.queryParams.size() > 0 || op.headerParams.size() > 0) {
204215
scalaPath = scalaPath + " ?";
205216
}
206217

207-
op.vendorExtensions.put("x-scala-path", scalaPath);
218+
op.vendorExtensions.put("x-scalatra-path", scalaPath);
208219
}
209220
return objs;
210221
}
@@ -251,4 +262,8 @@ public String escapeUnsafeCharacters(String input) {
251262
return input.replace("*/", "*_/").replace("/*", "/_*");
252263
}
253264

265+
public void setPackageName(String packageName) {
266+
this.packageName = packageName;
267+
}
268+
254269
}

modules/swagger-codegen/src/main/resources/finch/api.mustache

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{{>licenseInfo}}
22

3-
package {{package}}
3+
package {{packageName}}
44

5-
{{#imports}}import {{import}}
5+
{{#imports}}//import {{import}}
66
{{/imports}}
7-
8-
import java.io.File
7+
//import java.io.File
98

109
import org.scalatra.{ TypedParamSupport, ScalatraServlet }
1110
import org.scalatra.swagger._

modules/swagger-codegen/src/main/resources/finch/model.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{{>licenseInfo}}
22

3-
package {{package}}
3+
package {{packageName}}
44

55
import argonaut.Argonaut._
66
import argonaut.CodecJson
7-
{{#imports}}import {{import}}
7+
{{#imports}}//import {{import}}
88
{{/imports}}
99

1010
{{#models}}
@@ -15,7 +15,7 @@ import argonaut.CodecJson
1515
* @param {{name}} {{{description}}}
1616
{{/vars}}
1717
*/
18-
case class {{classname}}({{#vars}}{{name}}: {{^required}}Option[{{{datatype}}}{{/required}}{{#required}}{{{datatype}}}{{/required}}){{^-last}},{{/-last}}
18+
case class {{classname}}({{#vars}}{{name}}: {{^required}}Option[{{{datatype}}}]{{/required}}{{#required}}{{{datatype}}}{{/required}}{{^-last}},{{/-last}}
1919
{{/vars}})
2020

2121
object {{classname}} {

modules/swagger-codegen/src/main/resources/finch/service.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{>licenseInfo}}
22

3-
package {{package}}
3+
package {{packageName}}
44

55
import com.twitter.finagle.Http
66
import com.twitter.util.{Await, Future}

samples/server/petstore/finch/src/main/scala/com/wordnik/client/model/ApiResponse.scala renamed to samples/server/petstore/finch/src/main/scala/ApiResponse.scala

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,20 @@
2222
* limitations under the License.
2323
*/
2424

25-
package com.wordnik.client.model
25+
package io.swagger.petstore
2626

2727
import argonaut.Argonaut._
2828
import argonaut.CodecJson
2929

3030
/**
31-
*
32-
* @param code
33-
* @param _type
34-
* @param message
31+
*
32+
* @param code
33+
* @param _type
34+
* @param message
3535
*/
36-
case class ApiResponse(code: Option[Int),
37-
_type: Option[String),
38-
message: Option[String)
39-
)
36+
case class ApiResponse(code: Option[Int],
37+
_type: Option[String],
38+
message: Option[String])
4039

4140
object ApiResponse {
4241
/**

samples/server/petstore/finch/src/main/scala/com/wordnik/client/model/Category.scala renamed to samples/server/petstore/finch/src/main/scala/Category.scala

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,18 @@
2222
* limitations under the License.
2323
*/
2424

25-
package com.wordnik.client.model
25+
package io.swagger.petstore
2626

2727
import argonaut.Argonaut._
2828
import argonaut.CodecJson
2929

3030
/**
31-
*
32-
* @param id
33-
* @param name
31+
*
32+
* @param id
33+
* @param name
3434
*/
35-
case class Category(id: Option[Long),
36-
name: Option[String)
37-
)
35+
case class Category(id: Option[Long],
36+
name: Option[String])
3837

3938
object Category {
4039
/**

samples/server/petstore/finch/src/main/scala/JettyMain.scala

Lines changed: 0 additions & 67 deletions
This file was deleted.

samples/server/petstore/finch/src/main/scala/com/wordnik/client/model/Order.scala renamed to samples/server/petstore/finch/src/main/scala/Order.scala

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,27 @@
2222
* limitations under the License.
2323
*/
2424

25-
package com.wordnik.client.model
25+
package io.swagger.petstore
2626

2727
import argonaut.Argonaut._
2828
import argonaut.CodecJson
29-
import java.util.Date
29+
//import java.util.Date
3030

3131
/**
32-
*
33-
* @param id
34-
* @param petId
35-
* @param quantity
36-
* @param shipDate
32+
*
33+
* @param id
34+
* @param petId
35+
* @param quantity
36+
* @param shipDate
3737
* @param status Order Status
38-
* @param complete
38+
* @param complete
3939
*/
40-
case class Order(id: Option[Long),
41-
petId: Option[Long),
42-
quantity: Option[Int),
43-
shipDate: Option[Date),
44-
status: Option[String),
45-
complete: Option[Boolean)
46-
)
40+
case class Order(id: Option[Long],
41+
petId: Option[Long],
42+
quantity: Option[Int],
43+
shipDate: Option[Date],
44+
status: Option[String],
45+
complete: Option[Boolean])
4746

4847
object Order {
4948
/**

samples/server/petstore/finch/src/main/scala/com/wordnik/client/model/Pet.scala renamed to samples/server/petstore/finch/src/main/scala/Pet.scala

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,28 @@
2222
* limitations under the License.
2323
*/
2424

25-
package com.wordnik.client.model
25+
package io.swagger.petstore
2626

2727
import argonaut.Argonaut._
2828
import argonaut.CodecJson
29-
import com.wordnik.client.model.Category
30-
import com.wordnik.client.model.Tag
29+
//import Category
30+
//import Tag
3131

3232
/**
33-
*
34-
* @param id
35-
* @param category
36-
* @param name
37-
* @param photoUrls
38-
* @param tags
33+
*
34+
* @param id
35+
* @param category
36+
* @param name
37+
* @param photoUrls
38+
* @param tags
3939
* @param status pet status in the store
4040
*/
41-
case class Pet(id: Option[Long),
42-
category: Option[Category),
43-
name: String),
44-
photoUrls: List[String]),
45-
tags: Option[List[Tag]),
46-
status: Option[String)
47-
)
41+
case class Pet(id: Option[Long],
42+
category: Option[Category],
43+
name: String,
44+
photoUrls: List[String],
45+
tags: Option[List[Tag]],
46+
status: Option[String])
4847

4948
object Pet {
5049
/**

0 commit comments

Comments
 (0)