当我尝试使用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?
答案 0 :(得分:2)
@Api(...)
public class Endpoints { ... }
public class FeedEndpoints extends Endpoints {
@ApiMethod(...)
public Feed getFeed(...) { ... }
...
}
public class GroupEndpoints extends Endpoints {
@ApiMethod(...)
public Group getGroup(...) { ... }
...
}