-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for constraint record types
- Loading branch information
1 parent
4c924c3
commit c3a756d
Showing
13 changed files
with
753 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
openapi-cli/src/test/resources/ballerina-to-openapi/constraint/arrayRec.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. | ||
// | ||
// 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/http; | ||
import ballerina/constraint; | ||
|
||
@constraint:String {maxLength: 23} | ||
public type HobbyItemsString string; | ||
|
||
@constraint:String {minLength: 7} | ||
public type PersonDetailsItemsString string; | ||
|
||
@constraint:Float {maxValue: 445.4} | ||
public type PersonFeeItemsNumber float; | ||
|
||
@constraint:Int {maxValue: 67 } | ||
public type PersonLimitItemsInteger int; | ||
|
||
@constraint:Array {maxLength: 5, minLength: { value: 2, message: "Min Length Exceeded!"}} | ||
public type Hobby HobbyItemsString[]; | ||
|
||
public type Person record { | ||
Hobby hobby?; | ||
@constraint:Array {maxLength: 5} | ||
PersonDetailsItemsString[] Details?; | ||
int id; | ||
PersonFeeItemsNumber[] fee?; | ||
# The maximum number of items in the response (as set in the query or by default). | ||
PersonLimitItemsInteger[] 'limit?; | ||
}; | ||
|
||
service /payloadV on new http:Listener(9090) { | ||
resource function post pet(@http:Payload Person body) returns error? { | ||
return; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
openapi-cli/src/test/resources/ballerina-to-openapi/constraint/decimalRec.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. | ||
// | ||
// 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/http; | ||
import ballerina/constraint; | ||
|
||
@constraint:Number { | ||
minValueExclusive: { | ||
value: 2.55, | ||
message: "Min Value Exceeded!" | ||
}, | ||
maxValue: 5.55 | ||
} | ||
public type Marks decimal; | ||
|
||
public type School record { | ||
Marks marks; | ||
}; | ||
|
||
service /payloadV on new http:Listener(9090) { | ||
resource function post pet(@http:Payload School body) returns error? { | ||
return; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
openapi-cli/src/test/resources/ballerina-to-openapi/constraint/floatRec.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. | ||
// | ||
// 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/http; | ||
import ballerina/constraint; | ||
|
||
@constraint:Float { | ||
maxValueExclusive: { | ||
value: 10.5, | ||
message: "Max Value Exceeded!" | ||
}, | ||
minValue: 2.5 | ||
} | ||
public type Rating float; | ||
|
||
public type Hotel record { | ||
Rating rate; | ||
}; | ||
|
||
service /payloadV on new http:Listener(9090) { | ||
resource function post pet(@http:Payload Hotel body) returns error? { | ||
return; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
openapi-cli/src/test/resources/ballerina-to-openapi/constraint/integerRec.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. | ||
// | ||
// 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/http; | ||
import ballerina/constraint; | ||
|
||
@constraint:Int{ | ||
minValueExclusive: 0, | ||
maxValue: { | ||
value: 50, | ||
message: "Max Value Exceeded!" | ||
} | ||
} | ||
public type Position int; | ||
|
||
public type Child record { | ||
Position position; | ||
}; | ||
|
||
service /payloadV on new http:Listener(9090) { | ||
resource function post pet(@http:Payload Child body) returns error? { | ||
return; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
openapi-cli/src/test/resources/ballerina-to-openapi/constraint/record_fieldRec.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. | ||
// | ||
// 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/http; | ||
import ballerina/constraint; | ||
|
||
@constraint:String {minLength: 5} | ||
public type Address string; | ||
|
||
public type Person record { | ||
@constraint:String { | ||
maxLength: { | ||
value: 14, | ||
message: "Max Length Exceeded!" | ||
} | ||
} | ||
string name?; | ||
@constraint:Array { | ||
maxLength: 5, | ||
minLength: { | ||
value: 2, | ||
message: "Min Length Exceeded!" | ||
} | ||
} | ||
string[] hobby?; | ||
@constraint:Int { | ||
maxValueExclusive: { | ||
value: 5, | ||
message: "Max Value Exceeded!" | ||
}, | ||
minValue: 0 | ||
} | ||
int id; | ||
Address address?; | ||
@constraint:Float { | ||
maxValueExclusive: { | ||
value: 100000, | ||
message: "Min Value Exceeded!" | ||
}, | ||
minValue: 1000 | ||
} | ||
float salary?; | ||
@constraint:Number { | ||
minValueExclusive: 500000, | ||
maxValue: { | ||
value: 1000000, | ||
message: "Max Value Exceeded!" | ||
} | ||
} | ||
decimal net?; | ||
}; | ||
|
||
service /payloadV on new http:Listener(9090) { | ||
resource function post pet(@http:Payload Person body) returns error? { | ||
return; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
openapi-cli/src/test/resources/ballerina-to-openapi/constraint/stringRec.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. | ||
// | ||
// 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/http; | ||
import ballerina/constraint; | ||
|
||
@constraint:String { | ||
length: { | ||
value: 10, | ||
message: "Length Exceeded!" | ||
}, | ||
pattern: re `^[a-zA-Z0-9_]+$` | ||
} | ||
public type St_ID string; | ||
|
||
public type StudentRecord record { | ||
St_ID id; | ||
@constraint:String { pattern: re `^[a-zA-Z]+$`} | ||
string name?; | ||
}; | ||
|
||
service /payloadV on new http:Listener(9090) { | ||
resource function post pet(@http:Payload StudentRecord body) returns error? { | ||
return; | ||
} | ||
} |
Oops, something went wrong.