Java 来自 Restful API 的函数参数由 mustache 生成
Java function parameters from Restful API generated by mustache
我有来自 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}}
生成的是RestfulAPI:
@Override
public Response findPets(List<String> tags,Integer limit) throws NotFoundException {
foo(...)
return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "foo")).build();
}
“>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 函数,但我需要编辑 mustache 文件以便正确生成代码。
以 api.mustache 文件为例,您可以像这样简单地更新 api.mustache
文件:
foo({{#allParams}}{{#isFile}}fileDetail{{/isFile}}{{^isFile}}{{paramName}}{{/isFile}}{{#hasMore}},{{/hasMore}}{{/allParams}});
我有来自 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}}
生成的是RestfulAPI:
@Override
public Response findPets(List<String> tags,Integer limit) throws NotFoundException {
foo(...)
return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "foo")).build();
}
“>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 函数,但我需要编辑 mustache 文件以便正确生成代码。
以 api.mustache 文件为例,您可以像这样简单地更新 api.mustache
文件:
foo({{#allParams}}{{#isFile}}fileDetail{{/isFile}}{{^isFile}}{{paramName}}{{/isFile}}{{#hasMore}},{{/hasMore}}{{/allParams}});