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="lib/ext"/>
|
||||||
<mkdir dir="build"/>
|
<mkdir dir="build"/>
|
||||||
<mkdir dir="src/main/scala"/>
|
<mkdir dir="src/main/scala"/>
|
||||||
|
<mkdir dir="src/test/java"/>
|
||||||
|
<mkdir dir="src/test/scala"/>
|
||||||
|
|
||||||
<echo message="using build common dir: ${build.common.dir}"/>
|
<echo message="using build common dir: ${build.common.dir}"/>
|
||||||
<import file="${build.common.dir}/ant/ant-common.xml" />
|
<import file="${build.common.dir}/ant/ant-common.xml" />
|
||||||
@ -17,7 +19,7 @@
|
|||||||
|
|
||||||
<condition property="outputPath.set">
|
<condition property="outputPath.set">
|
||||||
<and>
|
<and>
|
||||||
<isset property="outputPath"/>
|
<isset property="outputDir"/>
|
||||||
<isset property="apiServerRootDir"/>
|
<isset property="apiServerRootDir"/>
|
||||||
</and>
|
</and>
|
||||||
</condition>
|
</condition>
|
||||||
@ -25,20 +27,20 @@
|
|||||||
<!-- generates the classes -->
|
<!-- generates the classes -->
|
||||||
<target name="generate-java" depends="compile" description="generates APIs and model classes for java language">
|
<target name="generate-java" depends="compile" description="generates APIs and model classes for java language">
|
||||||
<fail unless="outputPath.set">
|
<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/
|
-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)
|
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>
|
</fail>
|
||||||
<mkdir dir="${outputPath}/api"/>
|
<mkdir dir="${outputDir}/api"/>
|
||||||
<mkdir dir="${outputPath}/model"/>
|
<mkdir dir="${outputDir}/model"/>
|
||||||
<echo>
|
<echo>
|
||||||
outputPath for Api = ${outputPath}
|
outputDir for Api = ${outputDir}
|
||||||
</echo>
|
</echo>
|
||||||
<echo>
|
<echo>
|
||||||
apiServerRootDir = ${apiServerRootDir}
|
apiServerRootDir = ${apiServerRootDir}
|
||||||
</echo>
|
</echo>
|
||||||
<delete>
|
<delete>
|
||||||
<fileset dir="${outputPath}" includes="*.java"/>
|
<fileset dir="${outputDir}" includes="*.java"/>
|
||||||
</delete>
|
</delete>
|
||||||
<java classname="com.wordnik.swagger.codegen.config.java.JavaLibCodeGen">
|
<java classname="com.wordnik.swagger.codegen.config.java.JavaLibCodeGen">
|
||||||
<classpath>
|
<classpath>
|
||||||
@ -47,7 +49,9 @@
|
|||||||
<include name="**/*.jar"/>
|
<include name="**/*.jar"/>
|
||||||
</fileset>
|
</fileset>
|
||||||
</classpath>
|
</classpath>
|
||||||
<arg value="${outputPath}"/>
|
<arg value="${outputDir}"/>
|
||||||
|
<arg value="${apiServerRootDir}/config/apiConfiguration.json"/>
|
||||||
|
<arg value="${apiServerRootDir}/config/rulesProvider.json"/>
|
||||||
</java>
|
</java>
|
||||||
<copy todir="${apiServerRootDir}" overwrite="true">
|
<copy todir="${apiServerRootDir}" overwrite="true">
|
||||||
<fileset dir="conf/java/structure"/>
|
<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) {
|
public void setServiceBaseClass(String defaultServiceBaseClass) {
|
||||||
this.defaultServiceBaseClass = defaultServiceBaseClass;
|
this.defaultServiceBaseClass = defaultServiceBaseClass;
|
||||||
}
|
}
|
||||||
|
@ -30,4 +30,20 @@ public class JavaCodeGenRulesProvider implements RulesProvider {
|
|||||||
return ignoreModels.contains(modelName);
|
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.LanguageConfiguration;
|
||||||
import com.wordnik.swagger.codegen.config.common.CamelCaseNamingPolicyProvider;
|
import com.wordnik.swagger.codegen.config.common.CamelCaseNamingPolicyProvider;
|
||||||
import com.wordnik.swagger.exception.CodeGenerationException;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -17,54 +20,51 @@ import java.util.List;
|
|||||||
public class JavaLibCodeGen extends LibraryCodeGenerator {
|
public class JavaLibCodeGen extends LibraryCodeGenerator {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
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");
|
throw new CodeGenerationException("Invalid number of arguments passed: No command line argument was passed to the program for output path");
|
||||||
}
|
}
|
||||||
|
|
||||||
String outputPath = args[0];
|
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();
|
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.setLanguageConfig(initializeLangConfig(outputPath));
|
||||||
|
|
||||||
this.setDataTypeMappingProvider(new JavaDataTypeMappingProvider());
|
this.setDataTypeMappingProvider(new JavaDataTypeMappingProvider());
|
||||||
this.setCodeGenRulesProvider(new JavaCodeGenRulesProvider());
|
|
||||||
this.setNameGenerator(new CamelCaseNamingPolicyProvider());
|
this.setNameGenerator(new CamelCaseNamingPolicyProvider());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApiConfiguration initializeApiConfig() {
|
private JavaCodeGenRulesProvider readRulesProviderConfig(String rulesProviderLocation) {
|
||||||
ApiConfiguration apiConfiguration = new ApiConfiguration();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
apiConfiguration.setServiceBaseClass("WordAPI","AbstractWordAPI");
|
JavaCodeGenRulesProvider javaCodeGenRules = null;
|
||||||
//default base class for services if not specified for a service
|
try {
|
||||||
apiConfiguration.setServiceBaseClass("WordnikAPI");
|
javaCodeGenRules = mapper.readValue(new File(rulesProviderLocation), JavaCodeGenRulesProvider.class);
|
||||||
apiConfiguration.setModelBaseClass("WordnikObject");
|
} 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>();
|
return javaCodeGenRules;
|
||||||
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");
|
|
||||||
|
|
||||||
List<String> defaultServiceImports = new ArrayList<String>();
|
private ApiConfiguration readApiConfiguration(String apiConfigLocation) {
|
||||||
defaultServiceImports.add("com.wordnik.swagger.model.Long");
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
defaultServiceImports.add("com.wordnik.swagger.common.*");
|
ApiConfiguration configuration = null;
|
||||||
defaultServiceImports.add("com.wordnik.swagger.common.ext.*");
|
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);
|
return configuration;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private LanguageConfiguration initializeLangConfig(String outputPath) {
|
private LanguageConfiguration initializeLangConfig(String outputPath) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user