Skip to content

Commit

Permalink
Merge branch 'bug/3364-fix-flux-request-part'
Browse files Browse the repository at this point in the history
fixes #3364
fixes #3311
  • Loading branch information
dilipkrish committed Jul 13, 2020
2 parents cb587db + 0d6f6c1 commit acaaf3e
Show file tree
Hide file tree
Showing 21 changed files with 548 additions and 255 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package springfox.test.contract.oas.bugs;

import java.time.LocalDateTime;

public class Bug1965 {
private LocalDateTime value;

public LocalDateTime getValue() {
return value;
}

public void setValue(LocalDateTime value) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package springfox.test.contract.oas.bugs;

public class Bug3311 {
private String value;

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import reactor.core.publisher.Mono;
import springfox.documentation.annotations.ApiIgnore;
import springfox.test.contract.oas.model.Pet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

Expand Down Expand Up @@ -148,4 +152,23 @@ public String bug3380(@ApiIgnore ModelAndView modelAndView) {
public Iterable<String> bug3371() {
return new ArrayList<>();
}

@PostMapping(path = "/3311",
consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Void> bug3311(
@RequestPart Bug3311 ticket,
@RequestPart(required = false) MultipartFile[] attachments) {
return ResponseEntity.ok(null);
}

@PostMapping(path = "/1965", consumes = "multipart/form-data")
public ResponseEntity<Bug1965> bug1965(
@Valid @RequestPart(name = "sfParamMap") @RequestParam Map<String, String> paramMap,
@Valid @RequestPart(name = "sfId") @RequestParam Integer sfId,
@Valid @RequestPart(name = "sfData") Bug1965 sfData,
@RequestPart(name = "file", required = false) MultipartFile supportFile) {
return ResponseEntity.ok(null);
}

}
122 changes: 122 additions & 0 deletions oas-contract-tests/src/test/resources/contracts/bugs.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,69 @@
}
],
"paths": {
"/bugs/1965": {
"post": {
"tags": [
"bugs-controller"
],
"summary": "bug1965",
"operationId": "bug1965UsingPOST",
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"required": [
"paramMap",
"sfData",
"sfId"
],
"type": "object",
"properties": {
"file": {
"type": "string",
"description": "file",
"format": "binary"
},
"paramMap": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"description": "paramMap"
},
"sfData": {
"description": "sfData",
"$ref": "#/components/schemas/Bug1965"
},
"sfId": {
"type": "integer",
"description": "sfId",
"format": "int32"
}
}
},
"encoding": {
"paramMap": {
"contentType": "text/plain"
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/Bug1965"
}
}
}
}
}
}
},
"/bugs/2767/swagger15": {
"get": {
"tags": [
Expand Down Expand Up @@ -166,6 +229,46 @@
}
}
},
"/bugs/3311": {
"post": {
"tags": [
"bugs-controller"
],
"summary": "bug3311",
"operationId": "bug3311UsingPOST",
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"required": [
"ticket"
],
"type": "object",
"properties": {
"attachments": {
"type": "array",
"description": "attachments",
"items": {
"type": "string",
"format": "binary"
}
},
"ticket": {
"description": "ticket",
"$ref": "#/components/schemas/Bug3311"
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/bugs/3321": {
"get": {
"tags": [
Expand Down Expand Up @@ -430,6 +533,25 @@
},
"components": {
"schemas": {
"Bug1965": {
"title": "Bug1965",
"type": "object",
"properties": {
"value": {
"type": "string",
"format": "date-time"
}
}
},
"Bug3311": {
"title": "Bug3311",
"type": "object",
"properties": {
"value": {
"type": "string"
}
}
},
"Category": {
"title": "Category",
"type": "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.classmate.ResolvedType;
import com.fasterxml.classmate.types.ResolvedArrayType;
import org.springframework.http.codec.multipart.FilePart;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
Expand Down Expand Up @@ -45,6 +46,7 @@ public class ScalarTypes {
SCALAR_TYPE_LOOKUP.put(Currency.class, ScalarType.BIGDECIMAL);
SCALAR_TYPE_LOOKUP.put(UUID.class, ScalarType.UUID);
SCALAR_TYPE_LOOKUP.put(MultipartFile.class, ScalarType.BINARY);
SCALAR_TYPE_LOOKUP.put(FilePart.class, ScalarType.BINARY);
SCALAR_TYPE_LOOKUP.put(File.class, ScalarType.BINARY);
SCALAR_TYPE_LOOKUP.put(URL.class, ScalarType.URL);
SCALAR_TYPE_LOOKUP.put(URI.class, ScalarType.URI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.fasterxml.classmate.ResolvedType;
import com.fasterxml.classmate.types.ResolvedPrimitiveType;
import org.springframework.http.codec.multipart.FilePart;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.spi.schema.EnumTypeDeterminer;
import springfox.documentation.spi.schema.contexts.ModelContext;
Expand Down Expand Up @@ -68,6 +69,9 @@ private ModelReference modelReference(ResolvedType type) {
if (MultipartFile.class.isAssignableFrom(type.getErasedType())) {
return new ModelRef("__file");
}
if (FilePart.class.isAssignableFrom(type.getErasedType())) {
return new ModelRef("__file");
}
String typeName = typeName(type);
return new ModelRef(
typeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package springfox.documentation.schema;

import com.fasterxml.classmate.ResolvedType;
import org.springframework.http.codec.multipart.FilePart;
import org.springframework.web.multipart.MultipartFile;

import java.lang.reflect.Type;
Expand Down Expand Up @@ -83,7 +84,8 @@ public class Types {
new AbstractMap.SimpleEntry<>(BigInteger.class, "biginteger"),
new AbstractMap.SimpleEntry<>(Currency.class, "string"),
new AbstractMap.SimpleEntry<>(UUID.class, "uuid"),
new AbstractMap.SimpleEntry<>(MultipartFile.class, "__file"))
new AbstractMap.SimpleEntry<>(MultipartFile.class, "__file"),
new AbstractMap.SimpleEntry<>(FilePart.class, "__file"))
.collect(toMap(
Map.Entry::getKey,
Map.Entry::getValue)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.codec.multipart.FilePart;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -124,7 +125,8 @@ private static boolean isListOfFiles(ResolvedType parameterType) {
}

private static boolean isFileType(ResolvedType parameterType) {
return MultipartFile.class.isAssignableFrom(parameterType.getErasedType());
return MultipartFile.class.isAssignableFrom(parameterType.getErasedType()) ||
FilePart.class.isAssignableFrom(parameterType.getErasedType());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public DocumentationContextBuilder apply(DocumentationContextBuilder builder) {
rules.add(newRule(resolver.resolve(Mono.class, resolver.resolve(ResponseEntity.class, WildcardType.class)),
resolver.resolve(WildcardType.class), Ordered.HIGHEST_PRECEDENCE + 20));
rules.add(newRule(resolver.resolve(Flux.class, WildcardType.class),
resolver.resolve(WildcardType.class), Ordered.HIGHEST_PRECEDENCE + 20));
resolver.resolve(List.class, WildcardType.class), Ordered.HIGHEST_PRECEDENCE + 20));
rules.add(newRule(resolver.resolve(Mono.class, WildcardType.class),
resolver.resolve(WildcardType.class), Ordered.HIGHEST_PRECEDENCE + 20));
return builder.rules(rules);
Expand Down

0 comments on commit acaaf3e

Please sign in to comment.