forked from loafle/openapi-generator-original
added default values, required flags
This commit is contained in:
parent
66214a3dfd
commit
1f96222a9a
@ -24,15 +24,29 @@ public class MethodArgument {
|
|||||||
public static String ARGUMENT_OBJECT = "Object";
|
public static String ARGUMENT_OBJECT = "Object";
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
private String dataType;
|
private String dataType;
|
||||||
|
|
||||||
private String allowedValues;
|
private String allowedValues;
|
||||||
|
|
||||||
private String inputModelClassArgument;
|
private String inputModelClassArgument;
|
||||||
private String methodNameFromModelClass;
|
private String methodNameFromModelClass;
|
||||||
|
private String defaultValue;
|
||||||
|
private boolean required;
|
||||||
|
|
||||||
|
public String getDefaultValue(){
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultValue(String defaultValue){
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRequired() {
|
||||||
|
return required;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequired(boolean required){
|
||||||
|
this.required = required;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
|
@ -52,17 +52,32 @@ public class LanguageConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setOutputDirectory(String outputDirectory) {
|
public void setOutputDirectory(String outputDirectory) {
|
||||||
|
|
||||||
if(outputDirectory == null || outputDirectory.length() == 0){
|
if(outputDirectory == null || outputDirectory.length() == 0){
|
||||||
throw new CodeGenerationException("Error creating output path : Output path was null ");
|
throw new CodeGenerationException("Error creating output path : Output path was null ");
|
||||||
}
|
}
|
||||||
outputDirectory = outputDirectory.endsWith("/") ? outputDirectory.substring(0, outputDirectory.lastIndexOf("/")) : outputDirectory;
|
outputDirectory = outputDirectory.endsWith("/") ? outputDirectory.substring(0, outputDirectory.lastIndexOf("/")) : outputDirectory;
|
||||||
|
|
||||||
|
|
||||||
this.modelClassLocation = outputDirectory + "/model/";
|
this.modelClassLocation = outputDirectory + "/model/";
|
||||||
this.resourceClassLocation = outputDirectory + "/api/";
|
this.resourceClassLocation = outputDirectory + "/api/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setOutputDirectory(String outputDirectory, String modelDirectory, String resourceDirectory){
|
||||||
|
if(outputDirectory == null || outputDirectory.length() == 0){
|
||||||
|
throw new CodeGenerationException("Error creating output path : Output path was null ");
|
||||||
|
}
|
||||||
|
outputDirectory = outputDirectory.endsWith("/") ? outputDirectory.substring(0, outputDirectory.lastIndexOf("/")) : outputDirectory;
|
||||||
|
|
||||||
|
// add leading + trailing slashes
|
||||||
|
if(!modelDirectory.startsWith("/")) modelDirectory = "/" + modelDirectory;
|
||||||
|
if(!modelDirectory.endsWith("/")) modelDirectory = modelDirectory + "/";
|
||||||
|
|
||||||
|
if(!resourceDirectory.startsWith("/")) resourceDirectory = "/" + resourceDirectory;
|
||||||
|
if(!resourceDirectory.endsWith("/")) resourceDirectory = resourceDirectory + "/";
|
||||||
|
|
||||||
|
this.modelClassLocation = outputDirectory + modelDirectory;
|
||||||
|
this.resourceClassLocation = outputDirectory + resourceDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
public String getModelClassLocation() {
|
public String getModelClassLocation() {
|
||||||
return modelClassLocation;
|
return modelClassLocation;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ import java.util.List;
|
|||||||
* Time: 7:54 AM
|
* Time: 7:54 AM
|
||||||
*/
|
*/
|
||||||
public class EndpointOperation {
|
public class EndpointOperation {
|
||||||
|
|
||||||
public static String PARAM_TYPE_QUERY = "query";
|
public static String PARAM_TYPE_QUERY = "query";
|
||||||
public static String PARAM_TYPE_PATH = "path";
|
public static String PARAM_TYPE_PATH = "path";
|
||||||
public static String PARAM_TYPE_BODY = "body";
|
public static String PARAM_TYPE_BODY = "body";
|
||||||
@ -43,6 +42,8 @@ public class EndpointOperation {
|
|||||||
|
|
||||||
private static String AUTH_TOKEN_ARGUMENT_NAME = "authToken";
|
private static String AUTH_TOKEN_ARGUMENT_NAME = "authToken";
|
||||||
|
|
||||||
|
private static int ARG_COUNT_FOR_INPUT_MODEL = 4;
|
||||||
|
|
||||||
private String httpMethod;
|
private String httpMethod;
|
||||||
|
|
||||||
private String summary = "";
|
private String summary = "";
|
||||||
@ -65,6 +66,14 @@ public class EndpointOperation {
|
|||||||
|
|
||||||
private List<ErrorResponse> errorResponses;
|
private List<ErrorResponse> errorResponses;
|
||||||
|
|
||||||
|
public static int getArgCountForInputModel(){
|
||||||
|
return ARG_COUNT_FOR_INPUT_MODEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setArgCountForInputModel(int argCount){
|
||||||
|
ARG_COUNT_FOR_INPUT_MODEL = argCount;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ErrorResponse> getErrorResponses() {
|
public List<ErrorResponse> getErrorResponses() {
|
||||||
return errorResponses;
|
return errorResponses;
|
||||||
}
|
}
|
||||||
@ -221,6 +230,8 @@ public class EndpointOperation {
|
|||||||
anArgument.setName(AUTH_TOKEN_ARGUMENT_NAME);
|
anArgument.setName(AUTH_TOKEN_ARGUMENT_NAME);
|
||||||
anArgument.setDataType(MethodArgument.ARGUMENT_STRING);
|
anArgument.setDataType(MethodArgument.ARGUMENT_STRING);
|
||||||
anArgument.setDescription(modelField.getDescription());
|
anArgument.setDescription(modelField.getDescription());
|
||||||
|
anArgument.setRequired(modelField.isRequired());
|
||||||
|
anArgument.setDefaultValue(modelField.getDefaultValue());
|
||||||
arguments.add(anArgument);
|
arguments.add(anArgument);
|
||||||
}else if(modelField.getParamType().equalsIgnoreCase(PARAM_TYPE_HEADER) &&
|
}else if(modelField.getParamType().equalsIgnoreCase(PARAM_TYPE_HEADER) &&
|
||||||
modelField.getName().equals(API_KEY_PARAM_NAME)){
|
modelField.getName().equals(API_KEY_PARAM_NAME)){
|
||||||
@ -230,12 +241,16 @@ public class EndpointOperation {
|
|||||||
anArgument.setName(modelField.getName());
|
anArgument.setName(modelField.getName());
|
||||||
anArgument.setDataType(MethodArgument.ARGUMENT_STRING);
|
anArgument.setDataType(MethodArgument.ARGUMENT_STRING);
|
||||||
anArgument.setDescription(modelField.getDescription());
|
anArgument.setDescription(modelField.getDescription());
|
||||||
|
anArgument.setRequired(true); // always true
|
||||||
|
anArgument.setDefaultValue(modelField.getDefaultValue());
|
||||||
arguments.add(anArgument);
|
arguments.add(anArgument);
|
||||||
pathParams.add(anArgument);
|
pathParams.add(anArgument);
|
||||||
}else if (modelField.getParamType().equalsIgnoreCase(PARAM_TYPE_QUERY)) {
|
}else if (modelField.getParamType().equalsIgnoreCase(PARAM_TYPE_QUERY)) {
|
||||||
anArgument.setName(modelField.getName());
|
anArgument.setName(modelField.getName());
|
||||||
anArgument.setDataType(MethodArgument.ARGUMENT_STRING);
|
anArgument.setDataType(MethodArgument.ARGUMENT_STRING);
|
||||||
anArgument.setDescription(modelField.getDescription());
|
anArgument.setDescription(modelField.getDescription());
|
||||||
|
anArgument.setRequired(modelField.isRequired());
|
||||||
|
anArgument.setDefaultValue(modelField.getDefaultValue());
|
||||||
queryParams.add(anArgument);
|
queryParams.add(anArgument);
|
||||||
arguments.add(anArgument);
|
arguments.add(anArgument);
|
||||||
}else if (modelField.getParamType().equalsIgnoreCase(PARAM_TYPE_BODY)) {
|
}else if (modelField.getParamType().equalsIgnoreCase(PARAM_TYPE_BODY)) {
|
||||||
@ -245,6 +260,8 @@ public class EndpointOperation {
|
|||||||
anArgument.setName(modelField.getName());
|
anArgument.setName(modelField.getName());
|
||||||
anArgument.setDataType(dataTypeMapper.getClassType(modelField.getDataType(), false));
|
anArgument.setDataType(dataTypeMapper.getClassType(modelField.getDataType(), false));
|
||||||
anArgument.setDescription(modelField.getDescription());
|
anArgument.setDescription(modelField.getDescription());
|
||||||
|
anArgument.setRequired(modelField.isRequired());
|
||||||
|
anArgument.setDefaultValue(modelField.getDefaultValue());
|
||||||
arguments.add(anArgument);
|
arguments.add(anArgument);
|
||||||
method.setPostObject(true);
|
method.setPostObject(true);
|
||||||
}
|
}
|
||||||
@ -259,7 +276,7 @@ public class EndpointOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//check for number of arguments, if we have more than 4 then send the arguments as input object
|
//check for number of arguments, if we have more than 4 then send the arguments as input object
|
||||||
if(method.getArguments() != null && method.getArguments().size() > 4){
|
if(method.getArguments() != null && method.getArguments().size() > ARG_COUNT_FOR_INPUT_MODEL){
|
||||||
List<MethodArgument> arguments = new ArrayList<MethodArgument>();
|
List<MethodArgument> arguments = new ArrayList<MethodArgument>();
|
||||||
Model modelforMethodInput = new Model();
|
Model modelforMethodInput = new Model();
|
||||||
modelforMethodInput.setName(inputobjectName);
|
modelforMethodInput.setName(inputobjectName);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user