question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Meaning of the term API in the operationId context.

See original GitHub issue

In the context of an operationId. the spec says:

The id [operationId] MUST be unique among all operations described in the API

What is the definition of API in this context? Does it mean all operations defined in the same file? All operations used by an application?

Did I just miss the definition or should this be clarified?

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
jfialacommented, Mar 18, 2016

If I understand this correctly, the operationId currently has to be unique for each API endpoint an application provides. If it provides multiple API endpoints, the operationId is only required to be unique per API endpoint.

Currently I use Swagger Springfox/Swagger Codegen to generate code and I get one API class for each controller class (tag). IMHO in fact, it would be totally sufficient to demand that the operationId is unique per RequestMapping path/tag/controller/API class.

What the current interpretation of the specification leads to is that the operationId is suffixed with numbers to guarantee its uniqueness.

Request Paths: /pet/find /category/find /person/find

Generated API definition (provided by Swagger Springfox): “/pet/find”: operationId: findUsingGET “/category/find”: operationId: findUsingGET_1 “/person/find”: operationId: findUsingGET_2

The generated code using Swagger Codegen then looks like this: PetAPI.findUsingGET() CategoryAPI.findUsingGET_1() PersonAPI.findUsingGET_2()

So in fact, although IMHO it would be totally sufficient to scope the uniqueness of the operationId per tag/API class, it is now suffixed and generates hardly understandable client code with lots of suffixes.

The current solution to this is to use nicknames for the operations and name them uniquely: “/pet/find”: operationId: pet_findUsingGET “/category/find”: operationId: category_findUsingGET “/person/find”: operationId: person_findUsingGET

This solution is unsatisfying so far that it adds a scoping to methods that are already scoped: PetAPI.pet_findUsingGET() CategoryAPI.category_findUsingGET() PersonAPI.person_findUsingGET()

Wouldn’t it be sufficient to demand that the operationId is unique per tag it is associated to (or per Request Path)?

5reactions
bobvanderlindencommented, Feb 8, 2019

I personally think the operationId has its use (unique identifier for operations). However, I think it is being misused in many cases.

One tool that is misusing it is the codegen. It uses the operationId for method name and uses the tag(s) for classname. The method names do not need to be unique across all classes for all languages I know of. This becomes especially awkward when the operationId is generated from existing code (like Java) where methods do not need to be unique across all classes. Perfectly reasonable looking Java code is incorrect because methods names are now suddenly unique across classes.

For codegen it would be nice if we could just specify what the classname and methodname should be, separate from the operationId.

For Swagger-UI the operationId is correctly used IMO. It isn’t being shown as a kind of ‘short name’. It is actually a unique identifier just to reference a specific operation. The operation can be referenced using the # in the URL and (from what I gathered) is used internally to reference JS/HTML elements.

A UUID in this case makes perfect sense and seems more stable than a user-defined Id that needs to look good in order to use it as a method name.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenAPI Specification - Version 3.0.3 - Swagger
A document (or set of documents) that defines or describes an API. An OpenAPI definition uses and conforms to the OpenAPI Specification. Path...
Read more >
ApiOperations Interface | Microsoft Learn
Begins definition for a new OperationContract resource. abstract void, delete(String resourceGroupName, String serviceName, String apiId, String operationId, ...
Read more >
OpenAPI Specification v3.1.0 | Introduction, Definitions, & More
The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs.
Read more >
API context variables - IBM
Name Description Permission api.catalog.name The name of the catalog that the API belongs to. Read/write api.catalog.path The path of the catalog that the API belongs...
Read more >
How to customize the value of operationId generated in api ...
I know this can be done per api using @ApiOperation but is there a more generic way to define this format for all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found