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.
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.
I guess you're right. I thought it would be more readable this way, but on second thought, making the naming consistent is better.
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.
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.
| operationId: {{$service.Name}}{{$method.Name}} | |
| operationId: {{$service.Name}}-{{$method.Name}} |
There was a problem hiding this comment.
hope this is valid operationId :)
There was a problem hiding this comment.
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.
Tried generate it on this site: https://app.swaggerhub.com/
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: