我有来自 swagger 的 WebService API mustache 文件:
{{>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();
}
“serviceQueryParams”等是单独的 mustache 文件,如下所示:
{{#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 函数,但我需要编辑 Mustache 文件以便正确生成代码。
最佳答案
看看api.mustache以文件为例,您只需更新您的 api.mustache
文件,如下所示:
foo({{#allParams}}{{#isFile}}fileDetail{{/isFile}}{{^isFile}}{{paramName}}{{/isFile}}{{#hasMore}},{{/hasMore}}{{/allParams}});
关于Mustache 生成的 Restful API 中的 Java 函数参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33477882/