Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTTP service contract type support #2037

Merged
merged 61 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
aae8a69
Add compiler support
TharmiganK Jun 6, 2024
98b410c
Add runtime support
TharmiganK Jun 12, 2024
aceee23
Fix test cases
TharmiganK Jun 12, 2024
d5dcdbd
Update license and docs
TharmiganK Jun 12, 2024
1fcc9c4
Merge branch 'master' into service-type-support
TharmiganK Jun 12, 2024
31140c9
Merge branch 'master' into service-type-support
TharmiganK Jun 17, 2024
3063fa4
Change package name pattern
TharmiganK Jun 17, 2024
880ee6b
Fix code modifier issues
TharmiganK Jun 17, 2024
9b93019
Update minor version
TharmiganK Jun 17, 2024
3e4fcc9
Make payload annotation non-constant
TharmiganK Jun 17, 2024
17292f1
[Automated] Update the native jar versions
TharmiganK Jun 17, 2024
e35337b
[Automated] Update the native jar versions
TharmiganK Jun 17, 2024
07923b4
Merge branch 'master' into service-type-support
TharmiganK Jun 17, 2024
ccbb692
Update jwt version
TharmiganK Jun 17, 2024
7f0af43
Merge remote-tracking branch 'origin/service-type-support' into servi…
TharmiganK Jun 17, 2024
1e5a89a
Fix compiler test failure
TharmiganK Jun 17, 2024
d71adab
Fix service type modifier
TharmiganK Jun 17, 2024
cd3d602
Refactor base path logic
TharmiganK Jun 17, 2024
c57777a
Address sonar cloud issues
TharmiganK Jun 17, 2024
90fa07d
Refactor resource function node
TharmiganK Jun 18, 2024
dd3343e
Merge branch 'master' into service-type-support
TharmiganK Jun 18, 2024
34b6564
Move OpenAPI embedding task from openapi-tool
TharmiganK Jun 24, 2024
27c9b4f
Fix code modifier executions
TharmiganK Jun 27, 2024
f2734bc
Fix openapi diagnostic filtering
TharmiganK Jul 1, 2024
e9adeab
Pack ballerina-to-openapi jar to compiler plugin bala
TharmiganK Jul 1, 2024
ad6784b
[Automated] Update the native jar versions
TharmiganK Jul 1, 2024
8137b99
Add compiler diagnostic tests
TharmiganK Jul 2, 2024
bb486dd
Fix compiler diagnostic issue
TharmiganK Jul 5, 2024
c120104
Update lang version
TharmiganK Jul 15, 2024
0891299
[Automated] Update the native jar versions
TharmiganK Jul 15, 2024
16258e9
[Automated] Update the native jar versions
TharmiganK Jul 15, 2024
bec7625
Refactor service contract implementation with static resource
TharmiganK Jul 15, 2024
b78bc22
Update jwt version
TharmiganK Jul 15, 2024
a851b54
Merge branch 'master' into service-type-support
TharmiganK Jul 15, 2024
54115e0
Move service contract type logic to start method
TharmiganK Jul 17, 2024
dbe8084
Remove parameter annotation restriction
TharmiganK Jul 17, 2024
707a5b2
Merge remote-tracking branch 'origin/master' into service-type-support
TharmiganK Jul 22, 2024
65c6e5f
Merge remote-tracking branch 'origin/master' into service-type-support
TharmiganK Jul 22, 2024
fd5b57f
Update introspection resource only if it is empty
TharmiganK Jul 25, 2024
57634cb
Merge branch 'master' into service-type-support
TharmiganK Jul 25, 2024
fa6644c
Update dependency versions
TharmiganK Jul 25, 2024
4dcf9ed
Merge remote-tracking branch 'origin/service-type-support' into servi…
TharmiganK Jul 25, 2024
865d42c
Update dependency versions
TharmiganK Jul 26, 2024
cad9e8b
Merge branch 'master' into service-type-support
TharmiganK Aug 1, 2024
d08e922
Add ballerina test case
TharmiganK Aug 1, 2024
2e9c16f
Update dependency versions
TharmiganK Aug 1, 2024
ef2dab8
Fix service contract annotation for test resources
TharmiganK Aug 1, 2024
524a117
Add code action test
TharmiganK Aug 1, 2024
9b45f1d
[Automated] Update the native jar versions
TharmiganK Aug 1, 2024
2db3f47
[Automated] Update the native jar versions
TharmiganK Aug 1, 2024
3f3d7ae
Change the diagnostic location
TharmiganK Aug 1, 2024
a9eece2
Add a positive compiler plugin test
TharmiganK Aug 1, 2024
f5fdf91
Restructure the oas related generators
TharmiganK Aug 1, 2024
8f09e27
Skip oas generator folder for code-coverage
TharmiganK Aug 1, 2024
976acb5
Update with generated resource directory API
TharmiganK Aug 2, 2024
2ac9be7
Remove unwanted comment
TharmiganK Aug 2, 2024
899e40f
Return ballerina exception as it is
TharmiganK Aug 2, 2024
2a10576
Merge branch 'master' into service-type-support
TharmiganK Aug 2, 2024
914220f
Update changelog
TharmiganK Aug 2, 2024
a519c62
Merge branch 'master' into service-type-support
TharmiganK Aug 3, 2024
020bad2
Merge branch 'master' into service-type-support
TharmiganK Aug 3, 2024
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
4 changes: 3 additions & 1 deletion ballerina-tests/http-advanced-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.9.0"
distribution-version = "2201.10.0-20240801-104200-87df251c"

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -128,7 +128,9 @@ name = "http_test_common"
version = "2.12.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "lang.string"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "mime"},
{org = "ballerina", name = "test"},
{org = "ballerina", name = "time"},
Expand Down
116 changes: 116 additions & 0 deletions ballerina-tests/http-advanced-tests/tests/service_contract_tests.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/crypto;
import ballerina/http;
import ballerina/http_test_common as common;
import ballerina/test;

final http:Client serviceContractClient = check new (string `localhost:${serviceContractTestPort}/socialMedia`);

service common:Service on new http:Listener(serviceContractTestPort) {

resource function get users() returns common:User[]|error {
return [{id: 1, name: "Alice", email: "[email protected]"}, {id: 2, name: "Bob", email: "[email protected]"}];
}

resource function get users/[int id]() returns common:User|common:UserNotFound|error {
return {id: 1, name: "Alice", email: "[email protected]"};
}

resource function post users(common:NewUser newUser) returns http:Created|error {
return {
body: {
message: "User created successfully"
}
};
}

resource function delete users/[int id]() returns http:NoContent|error {
return http:NO_CONTENT;
}

resource function get users/[int id]/posts() returns common:PostWithMeta[]|common:UserNotFound|error {
return [{id: 1, content: "Content 1", createdAt: "2020-01-01T10:00:00Z"}, {id: 2, content: "Content 2", createdAt: "2020-01-01T10:00:00Z"}];
}

resource function post users/[int id]/posts(common:NewPost newPost) returns http:Created|common:UserNotFound|common:PostForbidden|error {
return error("invalid post");
}

public function createInterceptors() returns common:ErrorInterceptor {
return new ();
}
}

@test:Config {}
function testCachingWithServiceContract() returns error? {
http:Response response = check serviceContractClient->/users;
json payload = [{id: 1, name: "Alice", email: "[email protected]"}, {id: 2, name: "Bob", email: "[email protected]"}];
test:assertTrue(response.hasHeader(common:LAST_MODIFIED));
common:assertHeaderValue(check response.getHeader(common:CACHE_CONTROL), "must-revalidate,public,max-age=10");
common:assertHeaderValue(check response.getHeader(common:ETAG), crypto:crc32b(payload.toString().toBytes()));
common:assertHeaderValue(check response.getHeader(common:CONTENT_TYPE), "application/vnd.socialMedia+json");
common:assertJsonPayload(response.getJsonPayload(), payload);
}

@test:Config {}
function testLinksInServiceContract() returns error? {
record{*http:Links; *common:User;} response = check serviceContractClient->/users/'2;
map<http:Link> expectedLinks = {
"delete-user": {
href: "/socialMedia/users/{id}",
types: ["application/vnd.socialMedia+json"],
methods: [http:DELETE]
},
"create-posts": {
href: "/socialMedia/users/{id}/posts",
types: ["text/vnd.socialMedia+plain"],
methods: [http:POST]
},
"get-posts": {
href: "/socialMedia/users/{id}/posts",
types: ["application/vnd.socialMedia+json", "text/vnd.socialMedia+plain"],
methods: [http:GET]
}
};
record{} payload = {"id": 1, "name": "Alice", "email": "[email protected]", "_links": expectedLinks};
test:assertEquals(response, payload);
}

@test:Config {}
function testPayloadAnnotationWithServiceContract() returns error? {
common:NewUser newUser = {name: "Alice", email: "[email protected]"};
http:Response response = check serviceContractClient->/users.post(newUser);
test:assertEquals(response.statusCode, 415);
common:assertTextPayload(response.getTextPayload(), "content-type : application/json is not supported");

record{string message;} result = check serviceContractClient->/users.post(newUser, mediaType = "application/vnd.socialMedia+json");
test:assertEquals(result.message, "User created successfully");
}

@test:Config {}
function testInterceptorWithServiceContract() returns error? {
common:NewPost newPost = {content: "sample content"};
http:Response response = check serviceContractClient->/users/'1/posts.post(newPost, mediaType = "application/vnd.socialMedia+json");
test:assertEquals(response.statusCode, 500);
common:assertJsonPayload(response.getTextPayload(), "invalid post");

json invalidPost = {message: "sample content"};
response = check serviceContractClient->/users/'1/posts.post(invalidPost, mediaType = "application/vnd.socialMedia+json");
test:assertEquals(response.statusCode, 400);
common:assertTrueTextPayload(response.getTextPayload(), "data binding failed");
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ const int cookieTestPort2 = 9254;

const int http1SsePort = 9094;
const int http2SsePort = 9095;

const int serviceContractTestPort = 9096;
4 changes: 3 additions & 1 deletion ballerina-tests/http-client-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.9.0"
distribution-version = "2201.10.0-20240801-104200-87df251c"

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -124,7 +124,9 @@ name = "http_test_common"
version = "2.12.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "lang.string"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "mime"},
{org = "ballerina", name = "test"},
{org = "ballerina", name = "time"},
Expand Down
4 changes: 3 additions & 1 deletion ballerina-tests/http-dispatching-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.9.0"
distribution-version = "2201.10.0-20240801-104200-87df251c"

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -127,7 +127,9 @@ name = "http_test_common"
version = "2.12.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "lang.string"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "mime"},
{org = "ballerina", name = "test"},
{org = "ballerina", name = "time"},
Expand Down
4 changes: 3 additions & 1 deletion ballerina-tests/http-interceptor-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.9.0"
distribution-version = "2201.10.0-20240801-104200-87df251c"

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -118,7 +118,9 @@ name = "http_test_common"
version = "2.12.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "lang.string"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "mime"},
{org = "ballerina", name = "test"},
{org = "ballerina", name = "time"},
Expand Down
4 changes: 3 additions & 1 deletion ballerina-tests/http-misc-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.9.0"
distribution-version = "2201.10.0-20240801-104200-87df251c"

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -121,7 +121,9 @@ name = "http_test_common"
version = "2.12.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "lang.string"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "mime"},
{org = "ballerina", name = "test"},
{org = "ballerina", name = "time"},
Expand Down
4 changes: 3 additions & 1 deletion ballerina-tests/http-resiliency-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.9.0"
distribution-version = "2201.10.0-20240801-104200-87df251c"

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -119,7 +119,9 @@ name = "http_test_common"
version = "2.12.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "lang.string"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "mime"},
{org = "ballerina", name = "test"},
{org = "ballerina", name = "time"},
Expand Down
4 changes: 3 additions & 1 deletion ballerina-tests/http-security-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.9.0"
distribution-version = "2201.10.0-20240801-104200-87df251c"

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -123,7 +123,9 @@ name = "http_test_common"
version = "2.12.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "lang.string"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "mime"},
{org = "ballerina", name = "test"},
{org = "ballerina", name = "time"},
Expand Down
4 changes: 3 additions & 1 deletion ballerina-tests/http-service-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.9.0"
distribution-version = "2201.10.0-20240801-104200-87df251c"

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -124,7 +124,9 @@ name = "http_test_common"
version = "2.12.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "lang.string"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "mime"},
{org = "ballerina", name = "test"},
{org = "ballerina", name = "time"},
Expand Down
Loading
Loading