我正在尝试从readerListener接口中调用afterscan(...(方法,但没有被调用。这是我的代码:
@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 = "test-bob@tester.io", 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!!!");
}
}
现在,当我调用以下服务时:
http://localhost:9081/myApp/myUrl/swagger/json
我确实收到了"我找到了JSON!"在我的控制台和日志中...但是在控制台或日志中都没有"之前"或"之后"的注释。
我正在使用Swagger 1.5.10和Java 7.我将提供其他需要的其他细节。
欢迎任何想法!谢谢!
update :我尝试在此类中添加@swaggerdefinition注释,如上所示,但它仍然不起作用。
有什么想法我缺少什么?
我终于在这里弄清楚了问题。显然,原始设计的问题是我正在尝试实现ReaderListener的同一类中BaseApiListingResource
。无论出于何种原因,每当我扩展BaseApiListingResource
时,ReaderListener
都不起作用。如果我在不扩展BaseApiListingResource
的类上实现ReaderListener
,则 beforeScan
和 afterScan
工作正常。
希望这对某人有帮助...