gpt4 book ai didi

来自 mustache 生成的 Restful API 的 Java 函数参数

转载 作者:行者123 更新时间:2023-11-30 08:45:03 25 4
gpt4 key购买 nike

我有来自 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com