Skip to content

Commit 74fedfc

Browse files
committed
Java: fix invalid imports when model name prefix/suffix is present
When generating Java clients with mode name prefix/suffix given, there are invalid imports on Date and File, e.g. for the Petstore sample (with model name prefix set to "My" and suffix set to "Model"): import io.swagger.client.model.MyfileModel; import io.swagger.client.model.MyDateModel; This commit fixes it to: import java.io.File; import java.util.Date;
1 parent 6657434 commit 74fedfc

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public JavaClientCodegen() {
8383
);
8484
instantiationTypes.put("array", "ArrayList");
8585
instantiationTypes.put("map", "HashMap");
86+
typeMapping.put("date", "Date");
87+
typeMapping.put("file", "File");
8688

8789
cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
8890
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
@@ -488,7 +490,8 @@ public String getSwaggerType(Property p) {
488490
if (typeMapping.containsKey(swaggerType)) {
489491
type = typeMapping.get(swaggerType);
490492
if (languageSpecificPrimitives.contains(type) || type.indexOf(".") >= 0 ||
491-
type.equals("Map") || type.equals("List")) {
493+
type.equals("Map") || type.equals("List") ||
494+
type.equals("File") || type.equals("Date")) {
492495
return type;
493496
}
494497
} else {

0 commit comments

Comments
 (0)