forked from loafle/openapi-generator-original
Swagr code-gen: Refactoring method names in mapper and generator interfaces
This commit is contained in:
parent
63c7932a67
commit
5ec7c8b40e
@ -333,20 +333,20 @@ public class DriverCodeGenerator {
|
||||
model.setFields(modelFields);
|
||||
for(String className : generatedClassNames){
|
||||
ModelField aParam = new ModelField();
|
||||
aParam.setName(config.getNameGenerator().convertToMethodNameFormat(className)+"List");
|
||||
aParam.setParamType(config.getDataTypeMapper().getListReturnType(className));
|
||||
aParam.setName(config.getNameGenerator().applyMethodNamingPolicy(className)+"List");
|
||||
aParam.setParamType(config.getDataTypeMapper().getListReturnTypeSignature(className));
|
||||
modelFields.add(aParam);
|
||||
}
|
||||
|
||||
//add missing class from models
|
||||
ModelField aParam = new ModelField();
|
||||
aParam.setName("StringValueList");
|
||||
aParam.setParamType(config.getDataTypeMapper().getListReturnType("StringValue"));
|
||||
aParam.setParamType(config.getDataTypeMapper().getListReturnTypeSignature("StringValue"));
|
||||
modelFields.add(aParam);
|
||||
|
||||
List<String> imports = new ArrayList<String>();
|
||||
imports.addAll(this.config.getDefaultModelImports());
|
||||
imports.addAll(this.config.getDataTypeMapper().getListImports());
|
||||
imports.addAll(this.config.getDataTypeMapper().getListImportPackages());
|
||||
for(ModelField param : model.getFields()){
|
||||
for(String importDef : param.getFieldDefinition(config.getDataTypeMapper()).getImportDefinitions()){
|
||||
if(!imports.contains(importDef)){
|
||||
|
@ -56,7 +56,7 @@ public class MethodArgument {
|
||||
}
|
||||
|
||||
public void setInputModelClassArgument(String inputModelClass, CodeGenConfig config) {
|
||||
this.inputModelClassArgument = config.getNameGenerator().convertToMethodNameFormat(inputModelClass);
|
||||
this.inputModelClassArgument = config.getNameGenerator().applyMethodNamingPolicy(inputModelClass);
|
||||
if(name != null) {
|
||||
methodNameFromModelClass = config.getNameGenerator().createGetterMethodName(inputModelClassArgument, name);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public interface DataTypeMapper {
|
||||
* @param typeClass of class that list object contains.
|
||||
* @return
|
||||
*/
|
||||
public String getListReturnType(String typeClass);
|
||||
public String getListReturnTypeSignature(String typeClass);
|
||||
|
||||
/**
|
||||
* Signature that should be used when returning map of given object type.
|
||||
@ -48,7 +48,7 @@ public interface DataTypeMapper {
|
||||
* @param typeClass of class that list object contains.
|
||||
* @return
|
||||
*/
|
||||
public String getMapReturnType(String typeClass);
|
||||
public String getMapReturnTypeSignature(String typeClass);
|
||||
|
||||
/**
|
||||
* Initialization need for list objects. Example. If it is java list the initialization will look as
|
||||
@ -60,7 +60,7 @@ public interface DataTypeMapper {
|
||||
* @param typeClass
|
||||
* @return
|
||||
*/
|
||||
public String getListInitialization(String typeClass);
|
||||
public String generateListInitialization(String typeClass);
|
||||
|
||||
/**
|
||||
* Initialization need for map objects. Example. If it is java list the initialization will look as
|
||||
@ -72,7 +72,7 @@ public interface DataTypeMapper {
|
||||
* @param typeClass
|
||||
* @return
|
||||
*/
|
||||
public String getMapInitialization(String typeClass);
|
||||
public String generateMapInitialization(String typeClass);
|
||||
|
||||
/**
|
||||
* Gets list of imports that needs to be included when used objects of type List.
|
||||
@ -86,7 +86,7 @@ public interface DataTypeMapper {
|
||||
* </Code>
|
||||
* @return
|
||||
*/
|
||||
public List<String> getListImports();
|
||||
public List<String> getListImportPackages();
|
||||
|
||||
/**
|
||||
* Gets list of imports that needs to be included when used objects of type Map.
|
||||
@ -100,7 +100,7 @@ public interface DataTypeMapper {
|
||||
* </Code>
|
||||
* @return
|
||||
*/
|
||||
public List<String> getMapImports();
|
||||
public List<String> getMapImportPackages();
|
||||
|
||||
/**
|
||||
* Gets list of imports that needs to be included when used objects of type Date.
|
||||
|
@ -29,7 +29,7 @@ public interface ServiceAndMethodNameGenerator {
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public String convertToClassNameFormat(String input);
|
||||
public String applyClassNamingPolicy(String input);
|
||||
|
||||
/**
|
||||
* Transform the input string into method naming convention format.
|
||||
@ -39,7 +39,7 @@ public interface ServiceAndMethodNameGenerator {
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public String convertToMethodNameFormat(String input);
|
||||
public String applyMethodNamingPolicy(String input);
|
||||
|
||||
/**
|
||||
* Generates the name of service based on resource path.
|
||||
|
@ -74,38 +74,38 @@ public class JavaDataTypeMapper implements DataTypeMapper {
|
||||
return primitiveValueMap.get(type);
|
||||
}
|
||||
}else{
|
||||
return nameGenerator.convertToClassNameFormat(type);
|
||||
return nameGenerator.applyClassNamingPolicy(type);
|
||||
}
|
||||
}
|
||||
|
||||
public String getListReturnType(String typeClass) {
|
||||
return "List<"+nameGenerator.convertToClassNameFormat(typeClass)+">";
|
||||
public String getListReturnTypeSignature(String typeClass) {
|
||||
return "List<"+nameGenerator.applyClassNamingPolicy(typeClass)+">";
|
||||
}
|
||||
|
||||
public String getReturnTypeForVoidMethods() {
|
||||
return "void";
|
||||
}
|
||||
|
||||
public String getMapReturnType(String typeClass) {
|
||||
return "Map<"+nameGenerator.convertToClassNameFormat(typeClass)+">";
|
||||
public String getMapReturnTypeSignature(String typeClass) {
|
||||
return "Map<"+nameGenerator.applyClassNamingPolicy(typeClass)+">";
|
||||
}
|
||||
|
||||
public String getListInitialization(String typeClass) {
|
||||
return " new ArrayList<"+nameGenerator.convertToClassNameFormat(typeClass)+">()";
|
||||
public String generateListInitialization(String typeClass) {
|
||||
return " new ArrayList<"+nameGenerator.applyClassNamingPolicy(typeClass)+">()";
|
||||
}
|
||||
|
||||
public String getMapInitialization(String typeClass) {
|
||||
return " new HashMap<"+nameGenerator.convertToClassNameFormat(typeClass)+">()";
|
||||
public String generateMapInitialization(String typeClass) {
|
||||
return " new HashMap<"+nameGenerator.applyClassNamingPolicy(typeClass)+">()";
|
||||
}
|
||||
|
||||
public List<String> getListImports() {
|
||||
public List<String> getListImportPackages() {
|
||||
List<String> imports = new ArrayList<String>();
|
||||
imports.add("java.util.List");
|
||||
imports.add("java.util.ArrayList");
|
||||
return imports;
|
||||
}
|
||||
|
||||
public List<String> getMapImports() {
|
||||
public List<String> getMapImportPackages() {
|
||||
List<String> imports = new ArrayList<String>();
|
||||
imports.add("java.util.Map");
|
||||
imports.add("java.util.HashMap");
|
||||
|
@ -25,7 +25,7 @@ public class JavaServiceAndMethodNameGenerator implements ServiceAndMethodNameGe
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public String convertToClassNameFormat(String input) {
|
||||
public String applyClassNamingPolicy(String input) {
|
||||
if(input != null && input.length() > 0) {
|
||||
return input.substring(0,1).toUpperCase() + input.substring(1);
|
||||
}else{
|
||||
@ -39,7 +39,7 @@ public class JavaServiceAndMethodNameGenerator implements ServiceAndMethodNameGe
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public String convertToMethodNameFormat(String input) {
|
||||
public String applyMethodNamingPolicy(String input) {
|
||||
if(input != null && input.length() > 0) {
|
||||
return input.substring(0,1).toLowerCase() + input.substring(1);
|
||||
}else{
|
||||
@ -52,12 +52,12 @@ public class JavaServiceAndMethodNameGenerator implements ServiceAndMethodNameGe
|
||||
int index = resourcePath.indexOf(".");
|
||||
if(index >= 0) {
|
||||
String resourceName = resourcePath.substring(1,index);
|
||||
className = convertToClassNameFormat(resourceName);
|
||||
className = applyClassNamingPolicy(resourceName);
|
||||
}else{
|
||||
String[] paths = resourcePath.split("/");
|
||||
for(String path : paths) {
|
||||
if(path != null && path.length() > 0) {
|
||||
className = convertToClassNameFormat(path);
|
||||
className = applyClassNamingPolicy(path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -92,7 +92,7 @@ public class JavaServiceAndMethodNameGenerator implements ServiceAndMethodNameGe
|
||||
if(pathElement != null && pathElement.length() > 0) {
|
||||
int position = pathElement.indexOf("{");
|
||||
if(position < 0) {
|
||||
inputobjectName = inputobjectName + convertToClassNameFormat(pathElement) + Model.INPUT_OBJECT_SUFFIX;
|
||||
inputobjectName = inputobjectName + applyClassNamingPolicy(pathElement) + Model.INPUT_OBJECT_SUFFIX;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -111,7 +111,7 @@ public class JavaServiceAndMethodNameGenerator implements ServiceAndMethodNameGe
|
||||
* @return
|
||||
*/
|
||||
public String createGetterMethodName(String className, String attributeName) {
|
||||
return className+".get"+convertToClassNameFormat(attributeName)+"()";
|
||||
return className+".get"+ applyClassNamingPolicy(attributeName)+"()";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class ApiPropertyListWrapper implements Serializable
|
||||
if(propertyDefn.getItems().getAdditionalProperties().get("$ref") != null) {
|
||||
arrayItemType = (String) propertyDefn.getItems().getAdditionalProperties().get("$ref");
|
||||
}
|
||||
field.setParamType("List[" + config.getNameGenerator().convertToClassNameFormat(arrayItemType) + "]");
|
||||
field.setParamType("List[" + config.getNameGenerator().applyClassNamingPolicy(arrayItemType) + "]");
|
||||
}
|
||||
field.setDefaultValue(propertyDefn.getDefaultValue());
|
||||
field.setInternalDescription(propertyDefn.getNotes());
|
||||
|
@ -271,7 +271,7 @@ public class EndpointOperation {
|
||||
|
||||
MethodArgument anArgument = new MethodArgument();
|
||||
anArgument.setDataType(inputobjectName);
|
||||
anArgument.setName(config.getNameGenerator().convertToMethodNameFormat(inputobjectName));
|
||||
anArgument.setName(config.getNameGenerator().applyMethodNamingPolicy(inputobjectName));
|
||||
arguments.add(anArgument);
|
||||
method.setArguments(arguments);
|
||||
method.setInputModel(modelforMethodInput);
|
||||
|
@ -148,12 +148,12 @@ public class ModelField {
|
||||
fieldDefinition.getImportDefinitions().add("java.util.Date");
|
||||
}
|
||||
if(type.startsWith("List[")){
|
||||
fieldDefinition.getImportDefinitions().addAll(dataTypeMapper.getListImports());
|
||||
fieldDefinition.getImportDefinitions().addAll(dataTypeMapper.getListImportPackages());
|
||||
String entryType = type.substring(5, type.length()-1);
|
||||
entryType = dataTypeMapper.getObjectType(entryType, true);
|
||||
String returnType = dataTypeMapper.getListReturnType(entryType);
|
||||
String returnType = dataTypeMapper.getListReturnTypeSignature(entryType);
|
||||
fieldDefinition.setReturnType(returnType);
|
||||
fieldDefinition.setInitialization(" = " + dataTypeMapper.getListInitialization(entryType));
|
||||
fieldDefinition.setInitialization(" = " + dataTypeMapper.generateListInitialization(entryType));
|
||||
if(this.getWrapperName() != null){
|
||||
fieldDefinition.setName(this.getWrapperName());
|
||||
}else{
|
||||
@ -161,16 +161,16 @@ public class ModelField {
|
||||
}
|
||||
|
||||
}else if (type.startsWith("Map[")) {
|
||||
fieldDefinition.getImportDefinitions().addAll(dataTypeMapper.getMapImports());
|
||||
fieldDefinition.getImportDefinitions().addAll(dataTypeMapper.getMapImportPackages());
|
||||
String keyClass, entryClass = "";
|
||||
String entryType = type.substring(4, type.length()-1);
|
||||
keyClass = entryType.substring(0, entryType.indexOf(",") );
|
||||
entryClass = entryType.substring(entryType.indexOf(",") + 1, entryType.length());
|
||||
//entryType = dataTypeMapper.getObjectType(entryType, true);
|
||||
entryType = dataTypeMapper.getObjectType(keyClass, true) + "," + dataTypeMapper.getObjectType(entryClass, true);
|
||||
String returnType = dataTypeMapper.getMapReturnType(entryType);
|
||||
String returnType = dataTypeMapper.getMapReturnTypeSignature(entryType);
|
||||
fieldDefinition.setReturnType(returnType);
|
||||
fieldDefinition.setInitialization("= " + dataTypeMapper.getMapInitialization(entryType));
|
||||
fieldDefinition.setInitialization("= " + dataTypeMapper.generateMapInitialization(entryType));
|
||||
if(this.getWrapperName() != null){
|
||||
fieldDefinition.setName(this.getWrapperName());
|
||||
}else{
|
||||
|
@ -195,7 +195,7 @@ public class TestCaseExecutor {
|
||||
if(method.getName().startsWith("get")){
|
||||
String methodName = method.getName();
|
||||
String fieldName = methodName.substring(3);
|
||||
fieldName = config.getNameGenerator().convertToMethodNameFormat(fieldName);
|
||||
fieldName = config.getNameGenerator().applyMethodNamingPolicy(fieldName);
|
||||
Object value = inputDefinitions.get(fieldName);
|
||||
BeanUtils.setProperty(object, fieldName, value);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user