項目中有個controller的方法的DTO中有個field的屬性是MultipartFilejava
@ApiModel(description = "材料上傳form") public class MeterialUploadForm { @ApiModelProperty(value = "工單id") private Long orderId; @ApiModelProperty(value = "公司id") private Long companyId; @ApiModelProperty("材料文件") private MultipartFile file; ... getter and setter... }
而後須要用@ApiImplicaitParam來轉一下,file才能在swagger上正常使用sql
@PostMapping("/fileUpload") @ApiImplicitParams({@ApiImplicitParam(paramType = "form", dataType="file", name = "file", value = "材料文件啊", required = false)}) public String fileUpload(MeterialUploadForm form) { return form.getFile() == null ? "file is null" : form.getFile().getOriginalFilename(); }
2.6.1頁面如圖所示app
而後升級到2.9.2後swagger的file框消失了ui
2.9.2出錯頁面如圖所示code
後來通過排查原來把 @ApiImplicitParam的dataType改下就行了變成了orm
@PostMapping("/fileUpload") @ApiImplicitParams({@ApiImplicitParam(paramType = "form", dataType="file", name = "file", value = "材料文件啊", required = false)}) public String fileUpload(MeterialUploadForm form) { return form.getFile() == null ? "file is null" : form.getFile().getOriginalFilename(); }
2.9.2修復後頁面若是所示ip
原來是swagger升級的時候作了些調整
將其中的"file"改爲了"__file"ci
2.6.1的Typesget
public class Types { private Types() { throw new UnsupportedOperationException(); } private static final Set<String> baseTypes = newHashSet( "int", "date", "string", "double", "float", "boolean", "byte", "object", "long", "date-time", "file", "biginteger", "bigdecimal"); private static final Map<Type, String> typeNameLookup = ImmutableMap.<Type, String>builder() .put(Long.TYPE, "long") .put(Short.TYPE, "int") .put(Integer.TYPE, "int") .put(Double.TYPE, "double") .put(Float.TYPE, "float") .put(Byte.TYPE, "byte") .put(Boolean.TYPE, "boolean") .put(Character.TYPE, "string") .put(Date.class, "date-time") .put(java.sql.Date.class, "date") .put(String.class, "string") .put(Object.class, "object") .put(Long.class, "long") .put(Integer.class, "int") .put(Short.class, "int") .put(Double.class, "double") .put(Float.class, "float") .put(Boolean.class, "boolean") .put(Byte.class, "byte") .put(BigDecimal.class, "bigdecimal") .put(BigInteger.class, "biginteger") .put(Currency.class, "string") .put(UUID.class, "string") .put(MultipartFile.class, "file") .build(); public static String typeNameFor(Type type) { return typeNameLookup.get(type); } public static boolean isBaseType(String typeName) { return baseTypes.contains(typeName); } public static boolean isBaseType(ResolvedType type) { return baseTypes.contains(typeNameFor(type.getErasedType())); } public static boolean isVoid(ResolvedType returnType) { return Void.class.equals(returnType.getErasedType()) || Void.TYPE.equals(returnType.getErasedType()); } }
2.9.2Typesstring
public class Types { private Types() { throw new UnsupportedOperationException(); } private static final Set<String> baseTypes = newHashSet( "int", "date", "string", "double", "float", "boolean", "byte", "object", "long", "date-time", "__file", "biginteger", "bigdecimal", "uuid"); private static final Map<Type, String> typeNameLookup = ImmutableMap.<Type, String>builder() .put(Long.TYPE, "long") .put(Short.TYPE, "int") .put(Integer.TYPE, "int") .put(Double.TYPE, "double") .put(Float.TYPE, "float") .put(Byte.TYPE, "byte") .put(Boolean.TYPE, "boolean") .put(Character.TYPE, "string") .put(Date.class, "date-time") .put(java.sql.Date.class, "date") .put(String.class, "string") .put(Object.class, "object") .put(Long.class, "long") .put(Integer.class, "int") .put(Short.class, "int") .put(Double.class, "double") .put(Float.class, "float") .put(Boolean.class, "boolean") .put(Byte.class, "byte") .put(BigDecimal.class, "bigdecimal") .put(BigInteger.class, "biginteger") .put(Currency.class, "string") .put(UUID.class, "uuid") .put(MultipartFile.class, "__file") .build(); public static String typeNameFor(Type type) { return typeNameLookup.get(type); } public static boolean isBaseType(String typeName) { return baseTypes.contains(typeName); } public static boolean isBaseType(ResolvedType type) { return baseTypes.contains(typeNameFor(type.getErasedType())); } public static boolean isVoid(ResolvedType returnType) { return Void.class.equals(returnType.getErasedType()) || Void.TYPE.equals(returnType.getErasedType()); } }