我有一个较旧的JAX-RS Web服务,该文件记录在Swagger 1.5.12
中。
为了保持Web服务的向后兼容性,我复制了控制器和模型,并将其放在两个不同的程序包中。
de.kembytes.webservice.rest.v1_0
de.kembytes.webservice.rest.v1_0.model
de.kembytes.webservice.rest.v2_0
de.kembytes.webservice.rest.v2_0.model
控制器看起来像这样:
1.0版:
package de.kembytes.webservice.rest.v1_0;
import de.kembytes.webservice.rest.v1_0.model.WebserviceRequest;
import de.kembytes.webservice.rest.v1_0.model.WebserviceResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@Api(value = "Webservice")
@Path("/webservice")
public class WebserviceController {
@POST
@Path("/calculate")
@ApiOperation(value = "Version 1.0")
public WebserviceResponse calculate(WebserviceRequest request){
WebserviceResponse response = new WebserviceResponse();
// do logic
return response;
}
}
2.0版:
package de.kembytes.webservice.rest.v2_0;
import de.kembytes.webservice.rest.v2_0.model.WebserviceRequest;
import de.kembytes.webservice.rest.v2_0.model.WebserviceResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@Api(value = "Webservice")
@Path("/webservice/2.0")
public class WebserviceController {
@POST
@Path("/calculate")
@ApiOperation(value = "Version 2.0")
public WebserviceResponse calculate(WebserviceRequest request){
WebserviceResponse response = new WebserviceResponse();
// do logic
return response;
}
}
问题在于Swagger UI中的示例值始终是从版本2.0的WebserviceRequest
生成的。
如何配置要根据相应版本的请求生成的示例值?
Swagger-Config看起来像这样:
beanConfig = new BeanConfig();
beanConfig.setSchemes(new String[] {"http", "https"});
beanConfig.setBasePath(contextPath);
beanConfig.setResourcePackage("de.kembytes.webservice.rest");
beanConfig.setScan(true);