diff --git a/pom.xml b/pom.xml
index 5278a45..c4e2bc3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,7 +29,7 @@
io.swagger
swagger-codegen
- 2.1.4
+ 2.1.6
diff --git a/src/main/java/org/wso2/maven/plugins/APIGenMojo.java b/src/main/java/org/wso2/maven/plugins/APIGenMojo.java
index d5a7c48..cdc3b0f 100644
--- a/src/main/java/org/wso2/maven/plugins/APIGenMojo.java
+++ b/src/main/java/org/wso2/maven/plugins/APIGenMojo.java
@@ -1,20 +1,22 @@
-package org.wso2.maven.plugins;
-
/*
- * Copyright WSO2 Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright (c) 2005-2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. licenses this file to you under the Apache License,
+* Version 2.0 (the "License"); you may not use this file except
+* in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.wso2.maven.plugins;
import io.swagger.codegen.ClientOptInput;
import io.swagger.codegen.ClientOpts;
diff --git a/src/main/java/org/wso2/maven/plugins/CxfCodeGen.java b/src/main/java/org/wso2/maven/plugins/CxfCodeGen.java
index 433006a..7297eb7 100644
--- a/src/main/java/org/wso2/maven/plugins/CxfCodeGen.java
+++ b/src/main/java/org/wso2/maven/plugins/CxfCodeGen.java
@@ -1,40 +1,44 @@
/*
- * Copyright WSO2 Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright (c) 2005-2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. licenses this file to you under the Apache License,
+* Version 2.0 (the "License"); you may not use this file except
+* in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
package org.wso2.maven.plugins;
+import io.swagger.codegen.CodegenOperation;
import io.swagger.codegen.SupportingFile;
-import io.swagger.codegen.languages.JaxRSServerCodegen;
+import io.swagger.codegen.languages.JavaCXFServerCodegen;
+import io.swagger.models.Operation;
import org.apache.commons.lang.WordUtils;
import java.io.File;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
-/**
- * Created by jo on 7/29/15.
- */
-public class CxfCodeGen extends JaxRSServerCodegen {
+public class CxfCodeGen extends JavaCXFServerCodegen {
Set reserveModelNames;
public CxfCodeGen(){
super();
- this.templateDir = "ApacheCXFJaxRS";
+ this.embeddedTemplateDir = this.templateDir = "ApacheCXFJaxRS";
reserveModelNames = new HashSet(
Arrays.asList(
@@ -53,6 +57,16 @@ public CxfCodeGen(){
);
}
+ @Override
+ public String getHelp() {
+ return "Generates a Java JAXRS Server application based on Apache CXF framework.";
+ }
+
+ @Override
+ public String getName() {
+ return "jaxrs";
+ }
+
@Override
public void processOpts() {
super.processOpts();
@@ -61,6 +75,12 @@ public void processOpts() {
modelTemplateFiles.clear();
modelTemplateFiles.put("dto.mustache", ".java");
+ apiTemplateFiles.clear();
+ apiTemplateFiles.put("api.mustache", ".java");
+ apiTemplateFiles.put("apiService.mustache", ".java");
+ apiTemplateFiles.put("apiServiceImpl.mustache", ".java");
+ apiTemplateFiles.put("apiServiceFactory.mustache", ".java");
+
supportingFiles.clear();
supportingFiles.add(new SupportingFile("ApiException.mustache",
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiException.java"));
@@ -78,14 +98,25 @@ public String apiFilename(String templateName, String tag) {
//generate the Impl in main directory
if (templateName.endsWith("Impl.mustache")) {
String split[] = result.split(File.separator);
- result = getMainDirectory()+ File.separator + "impl" + File.separator + split[split.length -1];
+ result = getMainDirectory() + File.separator + "impl" + File.separator + split[split.length -1];
+ }
+
+ if (templateName.endsWith("Factory.mustache")) {
+ String split[] = result.split(File.separator);
+ result = getGenDirectory() + File.separator + "factories" + File.separator + split[split.length -1];
}
return result;
}
- public String getMainDirectory(){
- return getOutputDir()+ File.separator + "main"+ File.separator +"java"+ File.separator + apiPackage.replace(".", File.separator);
+ public String getMainDirectory() {
+ return getOutputDir() + File.separator + "main" + File.separator + "java" + File.separator + apiPackage
+ .replace(".", File.separator);
+ }
+
+ public String getGenDirectory() {
+ return getOutputDir() + File.separator + "gen" + File.separator + "java" + File.separator + apiPackage
+ .replace(".", File.separator);
}
@Override
@@ -110,4 +141,33 @@ public String toModelName(String name) {
// phone_number => PhoneNumber
return camelize(name)+"DTO";
}
+
+ @Override
+ public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co,
+ Map> operations) {
+ String basePath = resourcePath;
+ if (basePath.startsWith("/")) {
+ basePath = basePath.substring(1);
+ }
+ int pos = basePath.indexOf("/");
+ if (pos > 0) {
+ basePath = basePath.substring(0, pos);
+ }
+
+ if (basePath.equals("")) {
+ basePath = "default";
+ } else {
+ if (co.path.startsWith("/" + basePath)) {
+ co.path = co.path.substring(("/" + basePath).length());
+ }
+ co.subresourceOperation = !co.path.isEmpty();
+ }
+ List opList = operations.get(basePath);
+ if (opList == null) {
+ opList = new ArrayList();
+ operations.put(basePath, opList);
+ }
+ opList.add(co);
+ co.baseName = basePath;
+ }
}