Skip to content

Conversation

@LukasJenicek
Copy link
Contributor

  • operationId: method name or combination service name and method name to make it unique

operationId is an optional unique string used to identify an operation. If provided, these IDs must be unique among all operations described in your API

Reasons to add this:

  • Some code generators use this value to name the corresponding methods in code.
  • Links can refer to the linked operations by operationId.

@LukasJenicek LukasJenicek requested a review from VojtechVitek May 5, 2025 08:26
main.go.tmpl Outdated
Comment on lines 137 to 139
post: {{- if exists $operations $method.Name }}
operationId: {{$service.Name}}{{$method.Name}} {{ else }}
operationId: {{$method.Name}}{{ set $operations $method.Name 1 }} {{- end }}
Copy link
Contributor

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}}?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok done :)

@LukasJenicek LukasJenicek force-pushed the feature/operation-id branch 2 times, most recently from fe1fef7 to 84efc58 Compare May 5, 2025 12:45
- operationId: combination of service name and method name to make it unique
@LukasJenicek LukasJenicek force-pushed the feature/operation-id branch from 84efc58 to 2c8857e Compare May 5, 2025 12:45
main.go.tmpl Outdated
{{- $deprecated := index $method.Annotations "deprecated" }}
/rpc/{{$service.Name}}/{{$method.Name}}:
post:
operationId: {{$service.Name}}{{$method.Name}}
Copy link
Contributor

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

  1. more readable
  2. less prone to conflicts (e.g. if a service B method name overlaps with the name of service A)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
operationId: {{$service.Name}}{{$method.Name}}
operationId: {{$service.Name}}-{{$method.Name}}

Copy link
Contributor

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 :)

Copy link
Contributor Author

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
      );
    }
    ```

Copy link
Contributor Author

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/

Copy link
Contributor

@VojtechVitek VojtechVitek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you!

@VojtechVitek VojtechVitek merged commit de1742d into master May 6, 2025
1 check passed
@VojtechVitek VojtechVitek deleted the feature/operation-id branch May 6, 2025 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants