do not drop examples when merging ResponseMessages
@@ -21,6 +21,7 @@ package springfox.documentation.builders;
import org.springframework.http.HttpMethod;
import springfox.documentation.OperationNameGenerator;
import springfox.documentation.annotations.Incubating;
+import springfox.documentation.schema.Example;
import springfox.documentation.schema.ModelReference;
import springfox.documentation.service.Operation;
import springfox.documentation.service.Parameter;
@@ -28,15 +29,11 @@ import springfox.documentation.service.ResponseMessage;
import springfox.documentation.service.SecurityReference;
import springfox.documentation.service.VendorExtension;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import java.util.function.Predicate;
+import java.util.stream.Stream;
+import static java.util.Collections.emptyList;
import static java.util.Optional.*;
import static java.util.function.Function.*;
import static java.util.stream.Collectors.*;
@@ -298,7 +295,8 @@ public class OperationBuilder {
private String uniqueOperationIdStem() {
String defaultStem = String.format("%sUsing%s", uniqueId, method);
- return ofNullable(codeGenMethodNameStem).filter(((Predicate<String>)String::isEmpty).negate()).orElse(defaultStem);
+ return ofNullable(codeGenMethodNameStem).filter(((Predicate<String>) String::isEmpty).negate())
+ .orElse(defaultStem);
}
private Set<ResponseMessage> mergeResponseMessages(Set<ResponseMessage> responseMessages) {
@@ -310,13 +308,22 @@ public class OperationBuilder {
if (responsesByCode.containsKey(each.getCode())) {
ResponseMessage responseMessage = responsesByCode.get(each.getCode());
String message = defaultIfAbsent(ofNullable(each.getMessage())
- .filter(((Predicate<String>)String::isEmpty).negate()).orElse(null), responseMessage.getMessage());
- ModelReference responseWithModel = defaultIfAbsent(each.getResponseModel(), responseMessage.getResponseModel());
+ .filter(((Predicate<String>) String::isEmpty).negate())
+ .orElse(null), responseMessage.getMessage());
+ List<Example> examples = Stream.concat(
+ ofNullable(responseMessage.getExamples()).orElse(emptyList())
+ .stream(),
+ ofNullable(each.getExamples()).orElse(emptyList())
+ .stream())
+ .collect(toList());
+ ModelReference responseWithModel = defaultIfAbsent(each.getResponseModel(),
+ responseMessage.getResponseModel());
merged.remove(responseMessage);
merged.add(new ResponseMessageBuilder()
.code(each.getCode())
.message(message)
.responseModel(responseWithModel)
+ .examples(examples)
.headersWithDescription(responseMessage.getHeaders())
.headersWithDescription(each.getHeaders())
.build());
