-
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.
Merge pull request #1559 from SachinAkash01/constraint_s
Add negative tests for constraint mapper
- Loading branch information
Showing
11 changed files
with
429 additions
and
3 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
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
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
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
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
33 changes: 33 additions & 0 deletions
33
openapi-cli/src/test/resources/ballerina-to-openapi/constraint-negative/invalidInteger.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,33 @@ | ||
// Copyright (c) 2023, 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/http; | ||
import ballerina/constraint; | ||
|
||
@constraint:Int{ | ||
minValueExclusive: 10.5 | ||
} | ||
public type Distance int; | ||
|
||
public type City record{ | ||
Distance distance; | ||
}; | ||
|
||
service /payloadV on new http:Listener(9090) { | ||
resource function post pet(@http:Payload City body) returns error? { | ||
return; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...i-cli/src/test/resources/ballerina-to-openapi/constraint-negative/invalidRegexPattern.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,33 @@ | ||
// Copyright (c) 2023, 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/http; | ||
import ballerina/constraint; | ||
|
||
@constraint:String { | ||
pattern: re `^\${1,2}[a-z]+$` | ||
} | ||
public type Position string; | ||
|
||
public type Child record { | ||
Position position; | ||
}; | ||
|
||
service /payloadV on new http:Listener(9090) { | ||
resource function post pet(@http:Payload Child body) returns error? { | ||
return; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...cli/src/test/resources/ballerina-to-openapi/constraint-negative/negative_constNameRef.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,42 @@ | ||
// Copyright (c) 2023, 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/http; | ||
import ballerina/constraint; | ||
|
||
int maxVal = 100; | ||
int minVal = 5; | ||
const float Value = 10.5; | ||
@constraint:Int { | ||
maxValueExclusive: maxVal, | ||
minValue: { | ||
value: 5 + minVal, | ||
message: "Min value exceeded!" | ||
} | ||
} | ||
public type St_ID int; | ||
|
||
public type StudentRecord record { | ||
St_ID id; | ||
@constraint:Float { minValue: Value} | ||
float num?; | ||
}; | ||
|
||
service /payloadV on new http:Listener(9090) { | ||
resource function post pet(@http:Payload StudentRecord body) returns error? { | ||
return; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
openapi-cli/src/test/resources/ballerina-to-openapi/constraint-negative/negative_date.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,43 @@ | ||
// Copyright (c) 2023, 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/http; | ||
import ballerina/constraint; | ||
import ballerina/time; | ||
|
||
@constraint:Date { | ||
option: constraint:FUTURE, | ||
message: "Event date cannot be past!" | ||
} | ||
public type MyDate time:Date; | ||
|
||
type RegDate record { | ||
MyDate date; | ||
@constraint:Date { | ||
option: { | ||
value: constraint:PAST, | ||
message: "Last login should be past!" | ||
}, | ||
message: "Invalid date found for last login!" | ||
} | ||
time:Date lastLogin?; | ||
}; | ||
|
||
service /payloadV on new http:Listener(9090) { | ||
resource function post pet(RegDate body) returns error? { | ||
return; | ||
} | ||
} |
Oops, something went wrong.