-
Notifications
You must be signed in to change notification settings - Fork 9.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Meaning of the term API in the operationId context. #381
Comments
That's a fair question and needs to be clarified. The 'basic' limitation would be within the same Swagger description. The real challenge is how it would behave when referencing external files. |
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: Generated API definition (provided by Swagger Springfox): The generated code using Swagger Codegen then looks like this: 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: This solution is unsatisfying so far that it adds a scoping to methods that are already scoped: Wouldn't it be sufficient to demand that the operationId is unique per tag it is associated to (or per Request Path)? |
I wonder what use the OperationId has. I am struggling, as many are, with "Cannot have multiple operations with the same operationId ", and have seen all sorts of solutions like this one to generate OperationId's. So here's a thought... what if I simply get rid of the OperationId? Or what if I generate an SHA1 hash for the OperationId (based on some context so the Id is 'stable' across builds / versions). What if I simply assign an incrementing number ( |
No. And if present, they can be anything you wish, including unique integers, hashes etc. Some tooling, especially code-generation tools may make use of |
Exactly, that's what I gathered. But I guess my question is: is it used "in the field"? Is there tooling or whatever that's dependent on the OperationId? (Edit: apparently there is; you added another sentence to your post 😉 ) Is it better to provide an OperationId (be it a hash or integer or string like But so far I'm considering removing OperationID's alltogether from my swagger document. |
Yes, I would personally recommend providing a descriptive |
@MikeRalphson Operation IDs are primarily for use in Link Objects, right? |
I'd not say primarily, as they predate the presence of links in the spec., but that is another use as a shorthand for path + method. |
Tooling uses OperationId fairly extensively. Readable OperationIds are generally preferred as it makes it easier to hand edit documents. |
I personally think the One tool that is misusing it is the codegen. It uses the For codegen it would be nice if we could just specify what the classname and methodname should be, separate from the 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 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. |
Besides codegen and apigee SmartDocs, which tools actually use the operationId? We started with title case and spaces between words in the operationId for SmartDocs rendering which uses the operationId for titles. Now it seems the spaces may cause trouble in other tools. According to the OpenAPI Spec definition of the operationId ' .. it is RECOMMENDED to follow common programming naming conventions'. Now I am wondering if we should convert the operationId to Camel Case or hyphenated words? The operationId is being ignored by our current rendering. The summary and description are being used. What is the best practice for the operationId? |
What we are doing is create operationIds from classname and method name. For instance something like: This results in general use we have a valid specification. For codegen we have an invalid specification ( I wouldn't call it 'best practice', but it is how we're coping with this issue. |
In the context of an
operationId
. the spec says: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?
The text was updated successfully, but these errors were encountered: