Duplicate `operationId` with Multiclass API

Eric Simonton

When I try to deploy my Cloud Endpoints Framework api using gcloud service-management deploy openapi.json, I get many errors similar to:

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

Inspecting the generated openapi.json document, I see it has many duplicated operationIds. For example notice both of these use SdGet:

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

My backend is in Java. I have a multiclass API using inheritance, which seems to confrm to the recommendations in the docs. Here are the relevant parts for this example:

@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(...) { ... }

    ...
}

To generate openapi.json I modeled my config after Google's getting started guide. So in pom.xml I have something like this, which lets me generate it with the command 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>

What am I doing wrong? How can I define things differently so that the generated api specification does not use duplicate ids?

Eric Simonton

@saiyr informs me this is a bug in the framework (see comments on the question), so I filed a report here. For now I worked around it by renaming the API methods in all my endpoint classes to be unique, like this:

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

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

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related