Closed
Description
springfox-swagger2 version 2.6.1
I create two controllers:
@Controller
@RequestMapping("controller1")
public class Controller1 {
@RequestMapping(
value = "/endpoint1",
method = RequestMethod.GET)
@ResponseBody
public MyClass getMyClass() {
return ImmutableMyClass.of("abc");
}
}
@Controller
@RequestMapping("controller2")
public class Controller2 {
@RequestMapping(
value = "/endpoint2",
method = RequestMethod.GET)
@ResponseBody
public void getMyClass(@RequestBody MyClass request) {
}
}
@Value.Immutable
@Value.Style(allParameters = true)
@JsonSerialize(as = ImmutableMyClass.class)
@JsonDeserialize(as = ImmutableMyClass.class)
public interface MyClass {
String getFoo();
}
The swagger generated for MyClass from Controller1 looks like:
"MyClass" : {
"type" : "object",
"required" : [ "foo" ],
"properties" : {
"foo" : {
"type" : "string"
}
}
}
The swagger generated for MyClass from Controller2 looks like:
"FrontendExternalDataCallConfiguration" : {
"type" : "object",
"properties" : {
}
},
I understand why each controller generates different swagger, and that is not what this ticket is about. The issue is that the version of generated swagger used is not deterministic.
In ModelMapper#modelsFromApiListings, the Model for MyClass comes up twice. Depending on the order the ApiListings
are visited, the swagger could either contain the output from Controller1 or Controller2. The ApiListings
are not visited in a deterministic order, because they are visited by iterating through the keys in a Multimap.