Swagr code-gen: Changes to ignore methods that do not have model apis supplied and CodeGenConfig value added for models to be ignored

This commit is contained in:
Deepak Michael 2011-07-20 22:59:30 +05:30
parent e2e830235e
commit 7adc4e32fd
6 changed files with 50 additions and 14 deletions

View File

@ -105,6 +105,14 @@ public class DriverCodeGenerator {
}
/**
* Deserializes the response and returns a Response object
* @param response
* @param mapper
* @param newApi
* @return
* @throws IOException
*/
private Resource deserializeResource(String response, ObjectMapper mapper, Boolean newApi) throws IOException {
Resource resource;
if(!newApi) {
@ -115,12 +123,9 @@ public class DriverCodeGenerator {
//convert apiResource to resource
resource = new Resource();
Model model;
List<Parameter> fields;
List<Model> models = new ArrayList<Model>();
Parameter field;
String modelName, propertyName;
String modelName;
ApiModelDefn modelDefn;
ApiPropertyDefn propertyDefn;
if (apiResource.getModels() != null) {
for (Map.Entry<String, ApiModelDefn> entry : apiResource.getModels().getModelList().entrySet()) {
modelName = entry.getKey();
@ -128,10 +133,8 @@ public class DriverCodeGenerator {
model = new Model();
model.setName(modelName);
model.setDescription(modelDefn.getDescription());
model.setFields( modelDefn.getProperties().toFieldList( this.config ) );
models.add( model );
// ...
}
}
resource.setModels( models );
@ -162,7 +165,7 @@ public class DriverCodeGenerator {
for(Resource resource: resources) {
for(Model model : resource.getModels()){
if(!generatedClassNames.contains(model.getName())){
if(!generatedClassNames.contains(model.getName()) && !config.getCodeGenOverridingRules().isModelIgnored(model.getName())){
List<String> imports = new ArrayList<String>();
imports.addAll(this.config.getDefaultModelImports());
for(Parameter param : model.getFields()){

View File

@ -20,4 +20,6 @@ public interface CodeGenOverridingRules {
public String getServiceExtendingClass(String serviceName);
public boolean isMethodIgnored(String serviceName, String methodName);
public boolean isModelIgnored(String modelName);
}

View File

@ -16,11 +16,14 @@ public class JavaCodeGenPverridingRules implements CodeGenOverridingRules {
private Map<String, String> extendedClassNames = new HashMap<String, String>();
private List<String> ignoreMethods = new ArrayList<String>();
private List<String> ignoreModels = new ArrayList<String>();
public JavaCodeGenPverridingRules() {
extendedClassNames.put("WordAPI","AbstractWordAPI");
ignoreMethods.add("WordAPI.getWordFrequency");
ignoreMethods.add("WordAPI.getAudio");
ignoreMethods.add("WordAPI.getWordStats");
ignoreModels.add("wordStats");
}
public String getServiceExtendingClass(String serviceName) {
@ -34,4 +37,8 @@ public class JavaCodeGenPverridingRules implements CodeGenOverridingRules {
return (ignoreMethods.contains(serviceName+"."+methodName));
}
public boolean isModelIgnored(String modelName) {
return ignoreModels.contains(modelName);
}
}

View File

@ -86,12 +86,36 @@ public class Endpoint {
methods = new ArrayList<Method>();
if(getOperations() != null) {
for(EndpointOperation operation: getOperations()) {
if(!operation.isDeprecated()) {
if(!operation.isDeprecated() && areModelsAvailable(operation.getParameters(), resource, config)) {
methods.add(operation.generateMethod(this, resource, config));
}
}
}
}
return methods;
}
}
private boolean areModelsAvailable(List<Parameter> parameters, Resource resource, CodeGenConfig config) {
Boolean isParamSetAvailable = true;
if(parameters == null) return true;
for(Parameter parameter: parameters){
if (parameter.getParamType().equalsIgnoreCase(EndpointOperation.PARAM_TYPE_BODY) ){
isParamSetAvailable = false;
for(Model model : resource.getModels()){
if(config.getDataTypeMapper().isPrimitiveType(parameter.getDataType())){
isParamSetAvailable = true;
break;
}
if(model.getName().equalsIgnoreCase(parameter.getDataType())){
isParamSetAvailable = true;
break;
}
}
if(!isParamSetAvailable){
return false;
}
}
}
return isParamSetAvailable;
}
}

View File

@ -15,10 +15,10 @@ import java.util.StringTokenizer;
*/
public class EndpointOperation {
private static String PARAM_TYPE_QUERY = "query";
private static String PARAM_TYPE_PATH = "path";
private static String PARAM_TYPE_BODY = "body";
private static String PARAM_TYPE_HEADER = "header";
public static String PARAM_TYPE_QUERY = "query";
public static String PARAM_TYPE_PATH = "path";
public static String PARAM_TYPE_BODY = "body";
public static String PARAM_TYPE_HEADER = "header";
private static String AUTH_TOKEN_PARAM_NAME = "auth_token";
private static String API_KEY_PARAM_NAME = "api_key";
private static String FORMAT_PARAM_NAME = "format";

View File

@ -1,7 +1,7 @@
package com.wordnik.test;
import com.wordnik.api.WordAPI;
import com.wordnik.api.WordListAPI;
//import com.wordnik.api.WordListAPI;
import com.wordnik.exception.WordnikAPIException;
import com.wordnik.model.WordList;
import org.codehaus.jackson.JsonParser;