Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions _examples/openapi.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ components:
paths:
/rpc/ExampleService/Ping:
post:
operationId: ExampleServicePing
tags: ["ExampleService"]
summary: "Deprecated."
deprecated: true
Expand Down Expand Up @@ -542,6 +543,7 @@ paths:
- $ref: '#/components/schemas/ErrorDatabaseDown'
/rpc/ExampleService/GetUser:
post:
operationId: ExampleServiceGetUser
tags: ["ExampleService"]
summary: "Deprecated: Use GetUserV2 instead."
deprecated: true
Expand Down Expand Up @@ -585,6 +587,7 @@ paths:
- $ref: '#/components/schemas/ErrorDatabaseDown'
/rpc/ExampleService/GetUserV2:
post:
operationId: ExampleServiceGetUserV2
tags: ["ExampleService"]
summary: "GetUserV2 returns user based on given userID."
security:
Expand Down Expand Up @@ -629,6 +632,7 @@ paths:
- $ref: '#/components/schemas/ErrorDatabaseDown'
/rpc/ExampleService/FindUser:
post:
operationId: ExampleServiceFindUser
tags: ["ExampleService"]
summary: "FindUser searches for a user using the given search filter."
security:
Expand Down Expand Up @@ -676,6 +680,7 @@ paths:
- $ref: '#/components/schemas/ErrorDatabaseDown'
/rpc/ExampleService/ListUsers:
post:
operationId: ExampleServiceListUsers
tags: ["ExampleService"]
summary: "ListUsers returns all users."
security:
Expand Down Expand Up @@ -718,6 +723,7 @@ paths:
- $ref: '#/components/schemas/ErrorDatabaseDown'
/rpc/ExampleService/GetComplex:
post:
operationId: ExampleServiceGetComplex
tags: ["ExampleService"]
summary: ""
requestBody:
Expand Down Expand Up @@ -758,6 +764,7 @@ paths:
- $ref: '#/components/schemas/ErrorDatabaseDown'
/rpc/ExampleService/GetAllOptional:
post:
operationId: ExampleServiceGetAllOptional
tags: ["ExampleService"]
summary: ""
requestBody:
Expand Down Expand Up @@ -798,6 +805,7 @@ paths:
- $ref: '#/components/schemas/ErrorDatabaseDown'
/rpc/AdminService/ListUsers:
post:
operationId: AdminServiceListUsers
tags: ["AdminService"]
summary: ""
security:
Expand Down
1 change: 1 addition & 0 deletions main.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ paths:
{{- $deprecated := index $method.Annotations "deprecated" }}
/rpc/{{$service.Name}}/{{$method.Name}}:
post:
operationId: {{$service.Name}}{{$method.Name}}
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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/

tags: ["{{$service.Name}}"]
summary: {{ if $deprecated }}{{ if $deprecated.Value }}{{printf "%q" (print "Deprecated: " $deprecated.Value)}}{{else}}"Deprecated."{{end}}{{else if gt (len $method.Comments) 0}}{{printf "%q" (index $method.Comments 0)}}{{else}}""{{end}}
{{- if $deprecated }}
Expand Down