ballerina-platform / ballerina-library

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

Refactoring generated `operationId` in Ballerina to OpenAPI tool #5374

Closed lnash94 closed 2 years ago

lnash94 commented 2 years ago

Description: $Subject Currently, we are using the resource function name as the operation name. Ballerina to OpenAPI tool we are unable to generate human-readable operationId, since we can’t capture enough details by looking at the resource and make it unique. Therefore to avoid duplicate behaviour we followed some action rules for generating the operations Id. But the generated operationId has some issues with

  1. not user friendly
  2. some scenarios have lengthy operationId ex: post_passenger_passport_no_bookings_booking_id_response
  3. path parameter and special characters with patch operation has operationId with unreadable ex: "operationget/say-hello/{path-param}"

The purpose of this task is to improve the operationId generation process to increase human readability.

Describe your task(s)

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

lnash94 commented 2 years ago

As per having an offline discussion with @shafreenAnfar , we came up with the below outcome for current operation id generation. please refer to this ballerina service example :

service on new http:Listener(9090) {
    resource function get passenger/[string passportNo]/bookings() {
    }
}

for the above example, we currently generated operationId in below way

get:
      operationId: "operation_get_/passenger/{passportNo}/bookings"
      parameters:
...

during the discussion, suggested removing the operation from id and making it normalizing id removing special characters and capitalising variable names.

Suggested operationId : getPassengerPassportNoBookings

Service: GET /passenger/[string passportNo]/bookings Generated operationId: "operation_get_/passenger/{passportNo}/bookings" Suggested operationId : getPassengerPassportNoBookings

This approach will address the mentioned issue points 2, 3 and partial from 1. @hevayo we are pleased to have input for this improvement approach for the code generations process?

At the same time, we received suggestions to use have some approach for overriding the auto-generated operation id with user given value. Please refer to this https://ballerina-platform.slack.com/archives/C47EAELR1/p1648721879663829