-
Notifications
You must be signed in to change notification settings - Fork 3
generate operation id #25
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
Conversation
main.go.tmpl
Outdated
| post: {{- if exists $operations $method.Name }} | ||
| operationId: {{$service.Name}}{{$method.Name}} {{ else }} | ||
| operationId: {{$method.Name}}{{ set $operations $method.Name 1 }} {{- end }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The id MUST be unique among all operations described in the API. The operationId value is case-sensitive.
Why not use service+method name right away, e.g. {{$service.Name}}-{{$method.Name}}?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you're right. I thought it would be more readable this way, but on second thought, making the naming consistent is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok done :)
fe1fef7 to
84efc58
Compare
- operationId: combination of service name and method name to make it unique
84efc58 to
2c8857e
Compare
main.go.tmpl
Outdated
| {{- $deprecated := index $method.Annotations "deprecated" }} | ||
| /rpc/{{$service.Name}}/{{$method.Name}}: | ||
| post: | ||
| operationId: {{$service.Name}}{{$method.Name}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks OK, but can we add a separator between the two variables? I suggest going for -, which is unlikely to be in method name, but will work fine in URL links.
It will make the links
- more readable
- less prone to conflicts (e.g. if a service B method name overlaps with the name of service A)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| operationId: {{$service.Name}}{{$method.Name}} | |
| operationId: {{$service.Name}}-{{$method.Name}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hope this is valid operationId :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I've tried generate code from the generated openapi.yml and this was the result when using dash as separator:
/**
* FindUser searches for a user using the given search filter.
* The filters are q (string) and active (bool). The minimal length of the \"q\" filter is 3 characters.
* @param {Object} opts Optional parameters
* @param {module:model/ExampleServiceFindUserRequest} opts.body
* @param {module:api/ExampleServiceApi~exampleServiceFindUserCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link <&vendorExtensions.x-jsdoc-type>}
*/
exampleServiceFindUser(opts, callback) {
opts = opts || {};
let postBody = opts['body'];
let pathParams = {
};
let queryParams = {
};
let headerParams = {
};
let formParams = {
};
let authNames = [];
let contentTypes = ['application/json'];
let accepts = ['application/json'];
let returnType = ExampleServiceFindUserResponse;
return this.apiClient.callApi(
'/rpc/ExampleService/FindUser', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried generate it on this site: https://app.swaggerhub.com/
VojtechVitek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you!
operationIdis an optional unique string used to identify an operation. If provided, these IDs must be unique among all operations described in your APIReasons to add this: