[kotlin-spring] use spring resource for file handling (#2455)

* [kotlin-spring] use org.springframework.core.io.Resource for file handling

* run ./bin/kotlin-springboot-petstore-server.sh

* run ./bin/kotlin-springboot-petstore-server.sh after building the CLI

* use MultipartFile for file in form and the specified type otherwise

* remplace tab with space

* [kotlin-springboot] replace all instance of MultipartFile by Resource

* run ./bin/kotlin-springboot-petstore-server.sh
This commit is contained in:
sylvainmoindron
2019-03-27 14:44:24 +01:00
committed by William Cheng
parent 46e8ccbd1e
commit 74fbd3454b
12 changed files with 50 additions and 25 deletions

View File

@@ -44,7 +44,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
LoggerFactory.getLogger(KotlinSpringServerCodegen.class);
private static final HashSet<String> VARIABLE_RESERVED_WORDS =
new HashSet<String>(Arrays.asList(
new HashSet<>(Arrays.asList(
"ApiClient",
"ApiException",
"ApiResponse"
@@ -109,6 +109,10 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
importMapping.put("Date", "java.time.LocalDate");
importMapping.put("DateTime", "java.time.OffsetDateTime");
// use resource for file handling
typeMapping.put("file", "org.springframework.core.io.Resource");
languageSpecificPrimitives.addAll(Arrays.asList(
"Any",
"Byte",
@@ -562,4 +566,33 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
return m;
}
/**
* Output the proper model name (capitalized).
* In case the name belongs to the TypeSystem it won't be renamed.
*
* @param name the name of the model
* @return capitalized model name
*/
@Override
public String toModelName(final String name) {
// Allow for explicitly configured spring.*
if (name.startsWith("org.springframework.") ) {
return name;
}
return super.toModelName(name);
}
/**
* Check the type to see if it needs import the library/module/package
*
* @param type name of the type
* @return true if the library/module/package of the corresponding type needs to be imported
*/
@Override
protected boolean needToImport(String type) {
// provides extra protection against improperly trying to import language primitives and java types
boolean imports = !type.startsWith("org.springframework.") && super.needToImport(type);
return imports;
}
}