Skip to content

Commit

Permalink
upgrading swagger-code-gen to 2.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
malinthaprasan committed Jun 9, 2016
1 parent 94a41af commit 6eab753
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 40 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen</artifactId>
<version>2.1.4</version>
<version>2.1.6</version>
</dependency>
</dependencies>
<build>
Expand Down
34 changes: 18 additions & 16 deletions src/main/java/org/wso2/maven/plugins/APIGenMojo.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
106 changes: 83 additions & 23 deletions src/main/java/org/wso2/maven/plugins/CxfCodeGen.java
Original file line number Diff line number Diff line change
@@ -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<String>(
Arrays.asList(
Expand All @@ -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();
Expand All @@ -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"));
Expand All @@ -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
Expand All @@ -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<String, List<CodegenOperation>> 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<CodegenOperation> opList = operations.get(basePath);
if (opList == null) {
opList = new ArrayList<CodegenOperation>();
operations.put(basePath, opList);
}
opList.add(co);
co.baseName = basePath;
}
}

0 comments on commit 6eab753

Please sign in to comment.