forked from loafle/openapi-generator-original
Add File support + some fixes to Play generator (#5263)
* First commit of the Java Play Framework server generator. It is highly based on Spring so there might me a couple of things that don't make sense (like options or parameters) for the Play Framework. * Fix suggestions in the PR discussion + add .bat and .sh file as requested. * Updated Readme.md file * Remove unused mustache file + fix baseName vs paramName in all the mustache files. * Fix the compilation error when we have a body which is a list or map. Doesn't fix the problem with the annotation itself. * Fix the problem with the Http.MultipartFormData.FilePart * Return a FileInputStream when the returnType is "file" + Fix a couple of other bugs with boolean + updated sample * Return an InputStream instead of FileInputStream (except in the instantiation) * A little cleanup for the form param of type file.
This commit is contained in:
committed by
wing328
parent
aef98f464e
commit
2e46bb9b9f
@@ -12,9 +12,6 @@ public class CodegenParameter {
|
||||
public String baseName, paramName, dataType, datatypeWithEnum, dataFormat,
|
||||
collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName;
|
||||
|
||||
//This was added for javaPlayFramework specifically to get around a bug in swagger-play. See generator for more info on the bug.
|
||||
public String dataTypeForImplicitParam;
|
||||
|
||||
public String example; // example value (x-example)
|
||||
public String jsonSchema;
|
||||
public boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime;
|
||||
|
||||
@@ -188,6 +188,9 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea
|
||||
typeMapping.put("DateTime", "OffsetDateTime");
|
||||
importMapping.put("LocalDate", "java.time.LocalDate");
|
||||
importMapping.put("OffsetDateTime", "java.time.OffsetDateTime");
|
||||
|
||||
importMapping.put("InputStream", "java.io.InputStream");
|
||||
typeMapping.put("file", "InputStream");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -249,17 +252,15 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||
for (CodegenOperation operation : ops) {
|
||||
|
||||
//This is to fix this bug in the swagger-play project: https://github.com/swagger-api/swagger-play/issues/131
|
||||
//We need to explicitly add the model package name in front of the dataType because if we don't, the
|
||||
//implicitParam is not valid and show error when loading the documentation
|
||||
//This can be removed safely after the bug has been fixed
|
||||
for (CodegenParameter param : operation.allParams) {
|
||||
if (!param.isPathParam ) {
|
||||
if (!param.isPrimitiveType && !param.isListContainer && !param.isMapContainer) {
|
||||
param.dataTypeForImplicitParam = String.format("%s.%s", modelPackage, param.dataType);
|
||||
} else {
|
||||
param.dataTypeForImplicitParam = param.dataType;
|
||||
}
|
||||
if (param.isFormParam && param.isFile) {
|
||||
param.dataType = "Http.MultipartFormData.FilePart";
|
||||
}
|
||||
}
|
||||
|
||||
for (CodegenParameter param : operation.formParams) {
|
||||
if (param.isFile) {
|
||||
param.dataType = "Http.MultipartFormData.FilePart";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user