[Scalatra] replace {} with : in scalatra path (#3694)

* replace {} with : in scalatra path

* remove unused var in scalatra code gen
This commit is contained in:
wing328
2016-09-02 00:25:07 +08:00
committed by GitHub
parent 5467c41dad
commit 11ae12b09d
13 changed files with 282 additions and 181 deletions

View File

@@ -4,6 +4,7 @@ import io.swagger.codegen.CliOption;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.CodegenOperation;
import io.swagger.codegen.CodegenParameter;
import io.swagger.codegen.CodegenType;
import io.swagger.codegen.DefaultCodegen;
import io.swagger.codegen.SupportingFile;
@@ -161,8 +162,29 @@ public class ScalatraServerCodegen extends DefaultCodegen implements CodegenConf
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
for (CodegenOperation op : operationList) {
// force http method to lower case
op.httpMethod = op.httpMethod.toLowerCase();
String[] items = op.path.split("/", -1);
String scalaPath = "";
int pathParamIndex = 0;
for (int i = 0; i < items.length; ++i) {
if (items[i].matches("^\\{(.*)\\}$")) { // wrap in {}
scalaPath = scalaPath + ":" + items[i].replace("{", "").replace("}", "");
pathParamIndex++;
} else {
scalaPath = scalaPath + items[i];
}
if (i != items.length -1) {
scalaPath = scalaPath + "/";
}
}
op.vendorExtensions.put("x-scalatra-path", scalaPath);
}
return objs;
}