diff --git a/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/lib.bal b/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/lib.bal index 7a0681e5344c..ae6ddb6448cb 100644 --- a/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/lib.bal +++ b/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/lib.bal @@ -1,10 +1,10 @@ # Returns the string `Hello` with the input string name. # -# + name - name as a string +# + name - name as a string or nil # + return - "Hello, " with the input string name -public function hello(string name) returns string { - if !(name is "") { - return "Hello, " + name; +public function hello(string? name) returns string { + if name !is () { + return string `Hello, ${name}`; } return "Hello, World!"; } diff --git a/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/tests/lib_test.bal b/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/tests/lib_test.bal index 31ce10dfbb64..4b725d91de93 100644 --- a/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/tests/lib_test.bal +++ b/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/tests/lib_test.bal @@ -21,8 +21,7 @@ function testFunction() { @test:Config {} function negativeTestFunction() { - string name = ""; - string welcomeMsg = hello(name); + string welcomeMsg = hello(()); test:assertEquals("Hello, World!", welcomeMsg); } diff --git a/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/service.bal b/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/service.bal index 90f6a0cc7979..597a58d2d1fa 100644 --- a/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/service.bal +++ b/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/service.bal @@ -5,13 +5,13 @@ import ballerina/http; service / on new http:Listener(9090) { # A resource for generating greetings - # + name - the input string name + # + name - name as a string or nil # + return - string name with hello message or error - resource function get greeting(string name) returns string|error { + resource function get greeting(string? name) returns string|error { // Send a response back to the caller. - if name is "" { + if name is () { return error("name should not be empty!"); } - return "Hello, " + name; + return string `Hello, ${name}`; } } diff --git a/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/tests/service_test.bal b/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/tests/service_test.bal index 1e2c013c0280..0d85eb25166e 100644 --- a/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/tests/service_test.bal +++ b/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/tests/service_test.bal @@ -23,7 +23,7 @@ function testServiceWithProperName() { @test:Config {} function testServiceWithEmptyName() returns error? { - http:Response response = check testClient->get("/greeting/?name="); + http:Response response = check testClient->get("/greeting/"); test:assertEquals(response.statusCode, 500); json errorPayload = check response.getJsonPayload(); test:assertEquals(errorPayload.message, "name should not be empty!");