forked from loafle/openapi-generator-original
Better control on setter, getter (for boolean, non-boolean) (#6177)
* better control on setter, boolean getter * improve test casees for getter and setter
This commit is contained in:
@@ -14,13 +14,13 @@ import com.samskivert.mustache.Mustache.Compiler;
|
||||
|
||||
public interface CodegenConfig {
|
||||
CodegenType getTag();
|
||||
|
||||
|
||||
String getName();
|
||||
|
||||
String getHelp();
|
||||
|
||||
Map<String, Object> additionalProperties();
|
||||
|
||||
|
||||
Map<String, Object> vendorExtensions();
|
||||
|
||||
String testPackage();
|
||||
@@ -92,7 +92,7 @@ public interface CodegenConfig {
|
||||
CodegenModel fromModel(String name, Model model, Map<String, Model> allDefinitions);
|
||||
|
||||
CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map<String, Model> definitions, Swagger swagger);
|
||||
|
||||
|
||||
CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map<String, Model> definitions);
|
||||
|
||||
List<CodegenSecurity> fromSecurity(Map<String, SecuritySchemeDefinition> schemes);
|
||||
@@ -118,7 +118,7 @@ public interface CodegenConfig {
|
||||
Map<String, String> modelDocTemplateFiles();
|
||||
|
||||
Set<String> languageSpecificPrimitives();
|
||||
|
||||
|
||||
Map<String, String> reservedWordsMappings();
|
||||
|
||||
void preprocessSwagger(Swagger swagger);
|
||||
@@ -136,11 +136,11 @@ public interface CodegenConfig {
|
||||
String toApiTestFilename(String name);
|
||||
|
||||
String toModelTestFilename(String name);
|
||||
|
||||
|
||||
String toApiDocFilename(String name);
|
||||
|
||||
String toModelDocFilename(String name);
|
||||
|
||||
|
||||
String toModelImport(String name);
|
||||
|
||||
String toApiImport(String name);
|
||||
@@ -148,7 +148,7 @@ public interface CodegenConfig {
|
||||
void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations);
|
||||
|
||||
Map<String, Object> postProcessAllModels(Map<String, Object> objs);
|
||||
|
||||
|
||||
Map<String, Object> postProcessModels(Map<String, Object> objs);
|
||||
|
||||
Map<String, Object> postProcessOperations(Map<String, Object> objs);
|
||||
@@ -207,4 +207,11 @@ public interface CodegenConfig {
|
||||
void setIgnoreFilePathOverride(String ignoreFileOverride);
|
||||
|
||||
String getIgnoreFilePathOverride();
|
||||
|
||||
String toBooleanGetter(String name);
|
||||
|
||||
String toSetter(String name);
|
||||
|
||||
String toGetter(String name);
|
||||
|
||||
}
|
||||
|
||||
@@ -1230,6 +1230,36 @@ public class DefaultCodegen {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the Getter name for boolean property, e.g. getActive
|
||||
*
|
||||
* @param name the name of the property
|
||||
* @return getter name based on naming convention
|
||||
*/
|
||||
public String toBooleanGetter(String name) {
|
||||
return "get" + getterAndSetterCapitalize(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the Getter name, e.g. getSize
|
||||
*
|
||||
* @param name the name of the property
|
||||
* @return getter name based on naming convention
|
||||
*/
|
||||
public String toGetter(String name) {
|
||||
return "get" + getterAndSetterCapitalize(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the Getter name, e.g. getSize
|
||||
*
|
||||
* @param name the name of the property
|
||||
* @return setter name based on naming convention
|
||||
*/
|
||||
public String toSetter(String name) {
|
||||
return "set" + getterAndSetterCapitalize(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the API (class) name (capitalized) ending with "Api"
|
||||
* Return DefaultApi if name is empty
|
||||
@@ -1518,8 +1548,8 @@ public class DefaultCodegen {
|
||||
property.description = escapeText(p.getDescription());
|
||||
property.unescapedDescription = p.getDescription();
|
||||
property.title = p.getTitle();
|
||||
property.getter = "get" + getterAndSetterCapitalize(name);
|
||||
property.setter = "set" + getterAndSetterCapitalize(name);
|
||||
property.getter = toGetter(name);
|
||||
property.setter = toSetter(name);
|
||||
String example = toExampleValue(p);
|
||||
if(!"null".equals(example)) {
|
||||
property.example = example;
|
||||
@@ -1660,7 +1690,7 @@ public class DefaultCodegen {
|
||||
}
|
||||
if (p instanceof BooleanProperty) {
|
||||
property.isBoolean = true;
|
||||
property.getter = "is" + getterAndSetterCapitalize(name);
|
||||
property.getter = toBooleanGetter(name);
|
||||
}
|
||||
if (p instanceof BinaryProperty) {
|
||||
property.isBinary = true;
|
||||
|
||||
@@ -1228,4 +1228,14 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
return camelize(sanitizeName(tag));
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the Getter name for boolean property, e.g. isActive
|
||||
*
|
||||
* @param name the name of the property
|
||||
* @return getter name based on naming convention
|
||||
*/
|
||||
public String toBooleanGetter(String name) {
|
||||
return "is" + getterAndSetterCapitalize(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user