forked from loafle/openapi-generator-original
Swagr codegen: Included tests for a couple of the invoked apis and moved test package under com.wordnik.swagger
This commit is contained in:
parent
b2f7f69ec5
commit
fe4a29ca7a
18
build.xml
18
build.xml
@ -9,6 +9,8 @@
|
||||
<mkdir dir="lib/ext"/>
|
||||
<mkdir dir="build"/>
|
||||
<mkdir dir="src/main/scala"/>
|
||||
<mkdir dir="src/test/java"/>
|
||||
<mkdir dir="src/test/scala"/>
|
||||
|
||||
<echo message="using build common dir: ${build.common.dir}"/>
|
||||
<import file="${build.common.dir}/ant/ant-common.xml" />
|
||||
@ -17,7 +19,7 @@
|
||||
|
||||
<condition property="outputPath.set">
|
||||
<and>
|
||||
<isset property="outputPath"/>
|
||||
<isset property="outputDir"/>
|
||||
<isset property="apiServerRootDir"/>
|
||||
</and>
|
||||
</condition>
|
||||
@ -25,20 +27,20 @@
|
||||
<!-- generates the classes -->
|
||||
<target name="generate-java" depends="compile" description="generates APIs and model classes for java language">
|
||||
<fail unless="outputPath.set">
|
||||
Must specify the parameters: outputPath and apiServerRootDir eg. -DoutputPath=../../api-server-lib/java/src/main/java/com/wordnik/
|
||||
Must specify the parameters: outputPath and apiServerRootDir eg. -DoutputDir=../../api-server-lib/java/src/main/java/com/wordnik/swagger
|
||||
-DapiServerRootDir=../../api-server-lib/java/
|
||||
These are the output path of the Apis and the root directory that will be created for the api server (directory where structure is created)
|
||||
</fail>
|
||||
<mkdir dir="${outputPath}/api"/>
|
||||
<mkdir dir="${outputPath}/model"/>
|
||||
<mkdir dir="${outputDir}/api"/>
|
||||
<mkdir dir="${outputDir}/model"/>
|
||||
<echo>
|
||||
outputPath for Api = ${outputPath}
|
||||
outputDir for Api = ${outputDir}
|
||||
</echo>
|
||||
<echo>
|
||||
apiServerRootDir = ${apiServerRootDir}
|
||||
</echo>
|
||||
<delete>
|
||||
<fileset dir="${outputPath}" includes="*.java"/>
|
||||
<fileset dir="${outputDir}" includes="*.java"/>
|
||||
</delete>
|
||||
<java classname="com.wordnik.swagger.codegen.config.java.JavaLibCodeGen">
|
||||
<classpath>
|
||||
@ -47,7 +49,9 @@
|
||||
<include name="**/*.jar"/>
|
||||
</fileset>
|
||||
</classpath>
|
||||
<arg value="${outputPath}"/>
|
||||
<arg value="${outputDir}"/>
|
||||
<arg value="${apiServerRootDir}/config/apiConfiguration.json"/>
|
||||
<arg value="${apiServerRootDir}/config/rulesProvider.json"/>
|
||||
</java>
|
||||
<copy todir="${apiServerRootDir}" overwrite="true">
|
||||
<fileset dir="conf/java/structure"/>
|
||||
|
@ -41,6 +41,24 @@ public class ApiConfiguration {
|
||||
|
||||
}
|
||||
|
||||
public String getDefaultServiceBaseClass() {
|
||||
return defaultServiceBaseClass;
|
||||
}
|
||||
|
||||
public void setDefaultServiceBaseClass(String defaultServiceBaseClass) {
|
||||
this.defaultServiceBaseClass = defaultServiceBaseClass;
|
||||
}
|
||||
|
||||
public Map<String, String> getBaseClassNames() {
|
||||
|
||||
return baseClassNames;
|
||||
}
|
||||
|
||||
public void setBaseClassNames(Map<String, String> baseClassNames) {
|
||||
this.baseClassNames = baseClassNames;
|
||||
}
|
||||
|
||||
|
||||
public void setServiceBaseClass(String defaultServiceBaseClass) {
|
||||
this.defaultServiceBaseClass = defaultServiceBaseClass;
|
||||
}
|
||||
|
@ -30,4 +30,20 @@ public class JavaCodeGenRulesProvider implements RulesProvider {
|
||||
return ignoreModels.contains(modelName);
|
||||
}
|
||||
|
||||
public List<String> getIgnoreMethods() {
|
||||
return ignoreMethods;
|
||||
}
|
||||
|
||||
public void setIgnoreMethods(List<String> ignoreMethods) {
|
||||
this.ignoreMethods = ignoreMethods;
|
||||
}
|
||||
|
||||
public List<String> getIgnoreModels() {
|
||||
return ignoreModels;
|
||||
}
|
||||
|
||||
public void setIgnoreModels(List<String> ignoreModels) {
|
||||
this.ignoreModels = ignoreModels;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,10 @@ import com.wordnik.swagger.codegen.config.ApiConfiguration;
|
||||
import com.wordnik.swagger.codegen.config.LanguageConfiguration;
|
||||
import com.wordnik.swagger.codegen.config.common.CamelCaseNamingPolicyProvider;
|
||||
import com.wordnik.swagger.exception.CodeGenerationException;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -17,54 +20,51 @@ import java.util.List;
|
||||
public class JavaLibCodeGen extends LibraryCodeGenerator {
|
||||
|
||||
public static void main(String[] args) {
|
||||
if(args.length < 1){
|
||||
if(args.length < 3){
|
||||
throw new CodeGenerationException("Invalid number of arguments passed: No command line argument was passed to the program for output path");
|
||||
}
|
||||
|
||||
String outputPath = args[0];
|
||||
JavaLibCodeGen codeGenerator = new JavaLibCodeGen(outputPath);
|
||||
String configPath = args[1];
|
||||
String rulesConfigPath = args[2];
|
||||
JavaLibCodeGen codeGenerator = new JavaLibCodeGen(outputPath, configPath, rulesConfigPath);
|
||||
codeGenerator.generateCode();
|
||||
}
|
||||
|
||||
public JavaLibCodeGen(String outputPath){
|
||||
public JavaLibCodeGen(String outputPath, String configPath, String rulesConfigPath){
|
||||
|
||||
this.setApiConfig(initializeApiConfig());
|
||||
this.setApiConfig(readApiConfiguration(configPath));
|
||||
this.setCodeGenRulesProvider(readRulesProviderConfig(rulesConfigPath));
|
||||
this.setLanguageConfig(initializeLangConfig(outputPath));
|
||||
|
||||
this.setDataTypeMappingProvider(new JavaDataTypeMappingProvider());
|
||||
this.setCodeGenRulesProvider(new JavaCodeGenRulesProvider());
|
||||
this.setNameGenerator(new CamelCaseNamingPolicyProvider());
|
||||
}
|
||||
|
||||
private ApiConfiguration initializeApiConfig() {
|
||||
ApiConfiguration apiConfiguration = new ApiConfiguration();
|
||||
apiConfiguration.setServiceBaseClass("WordAPI","AbstractWordAPI");
|
||||
//default base class for services if not specified for a service
|
||||
apiConfiguration.setServiceBaseClass("WordnikAPI");
|
||||
apiConfiguration.setModelBaseClass("WordnikObject");
|
||||
private JavaCodeGenRulesProvider readRulesProviderConfig(String rulesProviderLocation) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JavaCodeGenRulesProvider javaCodeGenRules = null;
|
||||
try {
|
||||
javaCodeGenRules = mapper.readValue(new File(rulesProviderLocation), JavaCodeGenRulesProvider.class);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new CodeGenerationException("Java codegen rules configuration could not be read from the location : " + rulesProviderLocation);
|
||||
}
|
||||
|
||||
List<String> defaultModelImports = new ArrayList<String>();
|
||||
defaultModelImports.add("com.wordnik.swagger.common.WordListType");
|
||||
defaultModelImports.add("com.wordnik.swagger.common.StringValue");
|
||||
defaultModelImports.add("com.wordnik.swagger.common.Size");
|
||||
defaultModelImports.add("com.wordnik.swagger.common.WordnikObject");
|
||||
return javaCodeGenRules;
|
||||
}
|
||||
|
||||
List<String> defaultServiceImports = new ArrayList<String>();
|
||||
defaultServiceImports.add("com.wordnik.swagger.model.Long");
|
||||
defaultServiceImports.add("com.wordnik.swagger.common.*");
|
||||
defaultServiceImports.add("com.wordnik.swagger.common.ext.*");
|
||||
private ApiConfiguration readApiConfiguration(String apiConfigLocation) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
ApiConfiguration configuration = null;
|
||||
try {
|
||||
configuration = mapper.readValue(new File(apiConfigLocation), ApiConfiguration.class);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new CodeGenerationException("Api configuration could not be read from the location : " + apiConfigLocation);
|
||||
}
|
||||
|
||||
apiConfiguration.setDefaultModelImports(defaultModelImports);
|
||||
apiConfiguration.setDefaultServiceImports(defaultServiceImports);
|
||||
|
||||
apiConfiguration.setModelPackageName("com.wordnik.swagger.model");
|
||||
apiConfiguration.setApiPackageName("com.wordnik.swagger.api");
|
||||
|
||||
apiConfiguration.setApiKey("myKey");
|
||||
apiConfiguration.setApiUrl("http://swagr.api.wordnik.com/v4/");
|
||||
apiConfiguration.setApiListResource("/list");
|
||||
|
||||
return apiConfiguration;
|
||||
return configuration;
|
||||
}
|
||||
|
||||
private LanguageConfiguration initializeLangConfig(String outputPath) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user