-
Notifications
You must be signed in to change notification settings - Fork 6
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 #39 from MohamedSabthar/enum-validation
Add support for default value and enum validation
- Loading branch information
Showing
45 changed files
with
7,842 additions
and
5,755 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
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,65 @@ | ||
// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com) 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. | ||
|
||
class DefaultValueCreator { | ||
*Visitor; | ||
private string[] defaultValueFragments = []; | ||
|
||
isolated function visitSchema(Schema schema, anydata data = ()) { | ||
} | ||
|
||
isolated function visitGroupItem(GroupItem groupItem, anydata data = ()) { | ||
if groupItem.getRedefinedItemName() is string { | ||
return; | ||
} | ||
string[] defaultValues = self.defaultValueFragments; | ||
self.defaultValueFragments = []; | ||
foreach Node node in groupItem.getChildren() { | ||
node.accept(self); | ||
} | ||
string groupItemDefaultValue = string:'join("", ...self.defaultValueFragments); | ||
defaultValues.push(self.generateRepeatedString(groupItemDefaultValue, groupItem.getElementCount())); | ||
self.defaultValueFragments = defaultValues; | ||
} | ||
|
||
isolated function visitDataItem(DataItem dataItem, anydata data = ()) { | ||
if dataItem.getRedefinedItemName() is string { | ||
return; | ||
} | ||
string dataItemDefaultValue = dataItem.getDefaultValue() ?: ""; | ||
if (dataItem.isNumeric() && !dataItem.isDecimal()) || (dataItem.isDecimal() && dataItemDefaultValue != "") { | ||
dataItemDefaultValue = dataItemDefaultValue.padZero(dataItem.getReadLength()); | ||
} else { | ||
dataItemDefaultValue = dataItemDefaultValue.padEnd(dataItem.getReadLength()); | ||
} | ||
self.defaultValueFragments.push(self.generateRepeatedString(dataItemDefaultValue, dataItem.getElementCount())); | ||
} | ||
|
||
private isolated function generateRepeatedString(string value, int count) returns string { | ||
if count < 0 { | ||
return value; | ||
} | ||
string[] values = []; | ||
foreach int i in 1 ... count { | ||
values.push(value); | ||
} | ||
return string:'join("", ...values); | ||
} | ||
|
||
isolated function getDefaultValue() returns string { | ||
return string:'join("", ...self.defaultValueFragments); | ||
} | ||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 @@ | ||
Y |
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 @@ | ||
1 |
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 @@ | ||
200404202500 |
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 @@ | ||
0000 000 000000000 |
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 @@ | ||
25SABTHAR 179.900 |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
-02004 | ||
99004 | ||
02-004 | ||
-02-004 | ||
01-004 |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
-02004 | ||
01004 | ||
02-004 | ||
-02-004 | ||
99-004 |
Oops, something went wrong.