ballerina-platform / ballerina-library

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

service_1 is displayed as the Service Name for a Ballerina Service in ICP #7051

Open isudana opened 2 months ago

isudana commented 2 months ago

Description: Currently, service_1 is displayed as the Service Name for a Ballerina Service in ICP. Please see the attached screenshot.

![Uploading icp-ballerina.png…]()

We need to show the correct service name here.

Steps to reproduce:

Affected Versions:

OS, DB, other environment details and versions:

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

gabilang commented 1 month ago

Ballerina services do not have user provided names unless they have been defined as service classes. To display names for the Ballerina services in ICP, following naming patterns can be considered

Case 1: Services with base path specified

Derive a name directly from the base path by capitalizing the first letters of each path argument.

service /covid/status on new http:Listener(9000) {
    resource function get countries() returns CovidEntry[] {
        return covidEntriesTable.toArray();
    }
}

Display Name: Covid Status

Case 2: Services without specified base paths

Provide a default name if the service base path is / (default path) or the service path is not specified.

service / on new http:Listener(9090) {
    resource function get greetings() returns string {
        return “Hello World!”;
    }
}

OR

service on new http:Listener(9090) {
    resource function get greetings() returns string {
        return “Hello World!”;
    }
}

Display Name: Service at /

Following names also can be considered for these default base path cases: Root or Root Service or Default Service

Case 3: Inline service objects

Inline service objects also have / as the base path

listener http:Listener httpListener = new (8080);

http:Service obj = service object {
    remote function get hello() {
        io:println("hello!");
    }
};

function init() returns error? {
    check httpListener.attach(obj);
}

Display Name: Service at /

Case 4: Service class definition

Starting a service from the service class definition also uses / as the service base path.

public service class HelloService {
    *http:Service;

    resource function get hello() returns string {
        return “Hello World!”;
    }
}

So the name Service at / can be used to display the service in the dashboard. (Although the service class definition contains a user specified name, it can’t be used as the display name for the service since its base path is identical to inline and default base path service cases)

gabilang commented 1 month ago

Related issue https://github.com/ballerina-platform/ballerina-library/issues/6523