我有来自swagger的这个WebService API胡子文件:
{{>generatedAnnotation}}
{{#operations}}
public class {{classname}}ServiceImpl extends {{classname}}Service {
{{#operation}}
@Override
public Response {{nickname}}({{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{>serviceFormParams}}{{#hasMore}},{{/hasMore}}{{/allParams}})
throws NotFoundException {
foo(...)
return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "foo")).build();
}
{{/operation}}
生成的是Restful API:
@Override
public Response findPets(List<String> tags,Integer limit) throws NotFoundException {
foo(...)
return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "foo")).build();
}
“&gt; serviceQueryParams”等是单独的胡子文件,如下所示:
{{#isQueryParam}}{{{dataType}}} {{paramName}}{{/isQueryParam}}
我想要的是调用一个函数(foo),该函数采用与生成的API方法相同的参数:
public Response findPets(List<String> tags,Integer limit) throws NotFoundException {
foo(tags, limit);
...
另一个例子:
@Override
public Response addPet(NewPet pet) throws NotFoundException {
foo(pet);
....
我已经在java中定义了foo函数,但我需要编辑胡子文件,以便正确生成代码。
答案 0 :(得分:2)
以api.mustache文件为例,您只需更新api.mustache
文件即可:
foo({{#allParams}}{{#isFile}}fileDetail{{/isFile}}{{^isFile}}{{paramName}}{{/isFile}}{{#hasMore}},{{/hasMore}}{{/allParams}});