首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用多类API重复“OperationId”

使用多类API重复“OperationId”
EN

Stack Overflow用户
提问于 2017-06-03 14:52:16
回答 1查看 1.5K关注 0票数 3

当我试图使用gcloud service-management deploy openapi.json部署我的时,我会得到许多类似于以下内容的错误:

代码语言:javascript
复制
ERROR: openapi.json: Operation 'get' in path '/sd/v1/groups/{id}': operationId 'SdGet' has duplicate entry

检查生成的openapi.json文档,我看到它有许多重复的operationId

代码语言:javascript
复制
{
  ...
  "paths": {
      "/sd/v1/feeds/{id}": {
      "get": {
        "operationId": "SdGet",
        ...
      }
    },
    "/sd/v1/groups/{id}": {
      "get": {
        "operationId": "SdGet",
        ...
      }
    }
  }
}

我的后端是Java。我有一个使用继承的多类API,它似乎符合医生们中的建议。下面是这个示例的相关部分:

代码语言:javascript
复制
@Api(name = "sd", ...)
public class Endpoints { ... }

public class FeedEndpoints extends Endpoints {
    @ApiMethod(
        path = "feeds/{id}",
        name = "feeds.get",
        httpMethod = HttpMethod.GET)
    public Feed get(...) { ... }

    ...
}

public class GroupEndpoints extends Endpoints {
    @ApiMethod(
        path = "groups/{id}",
        name = "groups.get",
        httpMethod = HttpMethod.GET)
    public Group get(...) { ... }

    ...
}

为了生成openapi.json,我根据谷歌的开始指南建立了配置模型。所以在pom.xml中我有这样的东西,它允许我用命令mvn exec:java -DGetSwaggerDoc生成它

代码语言:javascript
复制
<profiles>
    <profile>
        <id>GetSwaggerDoc</id>
        ...
        <build>
            <plugins>
                <plugin>
                    ...
                    <configuration>
                        ...
                        <arguments>
                            <argument>get-swagger-doc</argument>
                            <argument>--hostname=echo-api.endpoints.${endpoints.project.id}.cloud.goog</argument>
                            <argument>--war=target/blah-1.0-SNAPSHOT</argument>
                            <argument>blah.FeedEndpoints</argument>
                            <argument>blah.GroupEndpoints</argument>
                            ...
                        </arguments>
                    </configuration>
                    ...
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

我做错了什么?如何以不同的方式定义事物,使生成的api规范不使用重复的ids?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-13 11:05:17

@saiyr告诉我这是框架中的一个bug (见关于这个问题的评论),所以我提交了一个报告这里。现在,我将所有端点类中的API方法重命名为唯一的,如下所示:

代码语言:javascript
复制
@Api(...)
public class Endpoints { ... }

public class FeedEndpoints extends Endpoints {
    @ApiMethod(...)
    public Feed getFeed(...) { ... }
    ...
}

public class GroupEndpoints extends Endpoints {
    @ApiMethod(...)
    public Group getGroup(...) { ... }
    ...
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44345177

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档