我試圖從ReaderListener接口調用afterScan(...)方法,但它沒有被調用。這裏是我的代碼:Swagger ReaderListener Not Invued
@SwaggerDefinition(info = @Info(
description = "My API",
version = "V1.2.3",
title = "The only API you'll ever need",
termsOfService = "share and care",
contact = @Contact(name = "Test-Bob", email = "[email protected]", url = "http://swagger.io"),
license = @License(name = "Apache 2.0", url = "http://www.apache.org")))
@Api(tags = {"something", "else"})
@Path("/myUrl/swagger/{type:json|yaml}")
public class MyApiListingResource extends BaseApiListingResource implements ReaderListener {
private static final Logger logger = LoggerFactory.getLogger(MyApiListingResource.class);
@Context ServletContext context;
@GET
@Produces({MediaType.APPLICATION_JSON, "application/yaml"})
@ApiOperation(value = "The swagger definition in either JSON or YAML",
hidden = true)
public Response getListing(@Context Application app, @Context ServletConfig servletConfig, @Context HttpHeaders headers,
@Context UriInfo uriInfo, @PathParam("type") String type) throws JsonProcessingException {
if (isNotBlank(type) && type.trim().equalsIgnoreCase("yaml")) {
return getListingYamlResponse(app, context, servletConfig, headers, uriInfo);
} else {
System.out.println("I found json!");
logger.debug("I'm also before!!!");
return getListingJsonResponse(app, context, servletConfig, headers, uriInfo);
}
}
@Override
public void beforeScan(Reader reader, Swagger swagger) {
System.out.println("I'm before!!!");
logger.debug("I'm also before!!!");
}
@Override
public void afterScan(Reader reader, Swagger swagger) {
System.out.println("I'm after!!!");
logger.debug("I'm also after!!!");
}
}
現在,當我撥打以下服務:「我發現JSON」
http://localhost:9081/myApp/myUrl/swagger/json
我不接受在我的控制檯和日誌中......但在控制檯或日誌中沒有打印「之前」或「之後」註釋。
我正在使用Swagger 1.5.10和Java 7.我將提供任何其他需要的細節。
歡迎任何想法!謝謝!
更新:我嘗試添加了註解@SwaggerDefinition這個類如上圖所示,但它仍然無法正常工作。
任何想法我失蹤?