google-app-engine - 使用多类 API 重复 `operationId`

标签 google-app-engine google-cloud-endpoints

当我尝试使用 gcloud service-management deploy openapi.json 部署我的 Cloud Endpoints Framework api 时,我收到许多类似于以下内容的错误:

ERROR: openapi.json: Operation 'get' in path '/sd/v1/groups/{id}': operationId 'SdGet' has duplicate entry

检查生成的 openapi.json 文件,我发现它有很多重复的 operationId。例如,注意这两个都使用 SdGet:

{
  ...
  "paths": {
      "/sd/v1/feeds/{id}": {
      "get": {
        "operationId": "SdGet",
        ...
      }
    },
    "/sd/v1/groups/{id}": {
      "get": {
        "operationId": "SdGet",
        ...
      }
    }
  }
}

我的后端是用 Java 编写的。我有一个使用继承的多类 API,这似乎符合 the docs 中的建议。 .以下是此示例的相关部分:

@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,我在 Google 的 getting started 之后对我的配置进行了建模。指导。所以在 pom.xml 中我有这样的东西,它让我用命令 mvn exec:java -DGetSwaggerDoc 生成它:

<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 规范不使用重复的 id?

最佳答案

@saiyr 告诉我这是框架中的一个错误(请参阅问题的评论),所以我提交了一份报告 here .现在我通过将所有端点类中的 API 方法重命名为唯一来解决这个问题,如下所示:

@Api(...)
public class Endpoints { ... }

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

public class GroupEndpoints extends Endpoints {
    @ApiMethod(...)
    public Group getGroup(...) { ... }
    ...
}

关于google-app-engine - 使用多类 API 重复 `operationId`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44345177/

相关文章:

google-app-engine - 云端点 HTTP Cookie

python - memcache.Client 未在 GAE python 上设置缓存值

javascript - 从 gapi.client.load 捕获错误

java - 在 Polygot 架构中将 Google Cloud Endpoints 与 Cloud SQL 和 Cloud DataStore 结合使用

java - Google Cloud Endpoints 自定义异常

Python库路径

java - Appengine API 方法返回模型集合

jquery - 最好的Python库来清理标签(不安全),并保留我认为安全的标签

google-app-engine - 如果 GAE 仅支持 Python 2.7.x,我可以使用 Endpoints Frameworks 吗?它不支持 Python 3.x?

python - 在 Google Cloud Endpoints 中返回自定义 HTTP 错误原因