ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
136 stars 58 forks source link

Typo issue in generated path param leads to compile error #5521

Closed SkNuwanTissera closed 2 years ago

SkNuwanTissera commented 3 years ago

Description: Typo issue in generated path param leads to compile error. Ex : Refer to function param followUserId. It's not correctly appearing on the path.

    remote isolated function unfollowUser(decimal followUserId, decimal userId) returns http:Response|error {
        string  path = string `/users/${userId}/following/${follow_userId}`;
        http:Request request = new;
        //TODO: Update the request as needed;
        http:Response response = check self.clientEp-> delete(path, request, targetType = http:Response);
        return response;
    }

Refer to the piece of code from openApi.yml

"/users/{user_id}/following/{follow_user_id}":
    delete:
      operationId: unfollow_user
      parameters:
        - description: The ID of the following user.
          in: path
          name: follow_user_id
          required: true
          schema:
            example: 3766357
            type: number
        - description: The ID of the user.
          in: path
          name: user_id
          required: true
          schema:
            example: 152184
            type: number

OS, DB, other environment details and versions:

JDK 11 Ballerina Beta 2 Ubuntu 20.04

Steps to reproduce:

  1. Generate the code using this OpenApi YAML file.
  2. You the following command on generating the code (with tags)
    bal openapi -i openapi.yml --mode client --tags "API Information","Albums\Album videos","Albums\Custom album logos","Albums\Custom album thumbnails","Albums\Essentials","Authentication Extras\Essentials","Categories\Channels","Categories\Groups","Categories\Subscriptions","Categories\Videos","Channels\Categories","Channels\Essentials","Channels\Moderators","Channels\Private channel members","Channels\Subscriptions and subscribers","Channels\Tags","Channels\Videos","Likes\Essentials","Portfolios\Essentials","Portfolios\Videos","Projects\Essentials","Projects\Videos","Tags\Essentials","Users\Essentials","Users\Feed","Users\Follows","Users\Internal","Users\Pictures","Users\Watch History","Videos\Comments","Videos\Content Ratings","Videos\Creative Commons","Videos\Credits","Videos\Embed Privacy","Videos\Essentials","Videos\Languages","Videos\Recommendations","Videos\Tags","Videos\Text Tracks","Videos\Thumbnails","Videos\Upload","Videos\Versions","Watch Later Queue\Essentials" 
  3. Run the ballerina project using bal run

NOTE: This issue is existing in 3 functions in the generated client.bal. Refer below functions.

    # Check if a user is following another user
    #
    # + followUserId - The ID of the following user. 
    # + userId - The ID of the user. 
    # + return - The authenticated user follows the user in question. 
    remote isolated function checkIfUserIsFollowing(decimal followUserId, decimal userId) returns http:Response|error {
        string  path = string `/users/${userId}/following/${follow_userId}`;
        http:Response response = check self.clientEp-> get(path, targetType = http:Response);
        return response;
    }
    # Follow a specific user
    #
    # + followUserId - The ID of the following user. 
    # + userId - The ID of the user. 
    # + return - The user was followed. 
    remote isolated function followUser(decimal followUserId, decimal userId) returns http:Response|error {
        string  path = string `/users/${userId}/following/${follow_userId}`;
        http:Request request = new;
        //TODO: Update the request as needed;
        http:Response response = check self.clientEp-> put(path, request, targetType = http:Response);
        return response;
    }
    # Unfollow a user
    #
    # + followUserId - The ID of the following user. 
    # + userId - The ID of the user. 
    # + return - The user was unfollowed. 
    remote isolated function unfollowUser(decimal followUserId, decimal userId) returns http:Response|error {
        string  path = string `/users/${userId}/following/${follow_userId}`;
        http:Request request = new;
        //TODO: Update the request as needed;
        http:Response response = check self.clientEp-> delete(path, request, targetType = http:Response);
        return response;
    }
SanduDS commented 2 years ago

Not able to regenerate the error mentioned using Ballerina Swan Lake Beta3. However, The code was generated as expected.