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

Implement XSD validation for Ballerina data.xmldata module #50

Merged
merged 58 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
d95e3f6
Add xsd validation for xsd file paths
SasinduDilshara Oct 26, 2024
43b9711
Add initial sequence
SasinduDilshara Nov 6, 2024
4dd8b45
Add implementation for single sequences without order alidation
SasinduDilshara Nov 7, 2024
ca7997b
Implement same level sequence without order
SasinduDilshara Nov 7, 2024
66255b4
Add tests for simple sequence in the nested scope
SasinduDilshara Nov 7, 2024
0ff1274
Add implementation for sequences with xml child elements
SasinduDilshara Nov 7, 2024
d3ab720
Add implementation for medium complex sequences without order hierachy
SasinduDilshara Nov 7, 2024
a6d91f0
Update sequence tests
SasinduDilshara Nov 7, 2024
1f89eed
Add negative tests for medium complex sequences
SasinduDilshara Nov 7, 2024
c6161d1
Implement sequence order validation
SasinduDilshara Nov 7, 2024
2ab553e
Add element annotation details for xsd validation
SasinduDilshara Nov 8, 2024
e501cbd
Improve seq implementation for validate element occurences
SasinduDilshara Nov 8, 2024
16805b2
Add element occurs implementation in xsd sequences
SasinduDilshara Nov 8, 2024
885fb64
Add complex tests with sequences with element annotation
SasinduDilshara Nov 8, 2024
9f5384c
Add array of sequences
SasinduDilshara Nov 9, 2024
64e85ad
Add tests for sequences with namespaces
SasinduDilshara Nov 9, 2024
9574656
Add xsd sequence iumplementation with name attribute
SasinduDilshara Nov 10, 2024
2b07986
Add initial implementation for XSD choice tags
SasinduDilshara Nov 10, 2024
abceef5
Refactor the sequence implementation
SasinduDilshara Nov 10, 2024
20a7935
Add basic tests for choice element
SasinduDilshara Nov 10, 2024
51420e1
Add basic tests for XSD choice
SasinduDilshara Nov 11, 2024
a199c56
Add xsd choice array tests
SasinduDilshara Nov 11, 2024
9618656
Add tests for choice with element annotations
SasinduDilshara Nov 11, 2024
1e9cbea
Add tests for xsd choice with name annotations
SasinduDilshara Nov 11, 2024
33ee4fd
Add initial implementation for XSD with xml values
SasinduDilshara Nov 11, 2024
54d1621
Add tests for xsd with element info for parse type API
SasinduDilshara Nov 12, 2024
3ed008c
Add tests for xsd choice and sequences arrays with parse type API
SasinduDilshara Nov 12, 2024
1a9b6b0
Refactor model group interface
SasinduDilshara Nov 12, 2024
4cea19f
[Automated] Update the native jar versions
SasinduDilshara Nov 13, 2024
535a2eb
[Automated] Update the native jar versions
SasinduDilshara Nov 14, 2024
ed128fd
[Automated] Update the native jar versions
SasinduDilshara Nov 14, 2024
f402244
[Automated] Update the native jar versions
SasinduDilshara Nov 14, 2024
02849f9
Add toXml logic in java
SasinduDilshara Nov 14, 2024
5f887b3
Add toxml implementatio without sequence order validation
SasinduDilshara Nov 15, 2024
a0a783a
Add toxml implementation for sequence arrays
SasinduDilshara Nov 15, 2024
e600ee7
Add proper error messages for xsd validation errors
SasinduDilshara Nov 16, 2024
e206653
Add tests for invalid xsd annotations
SasinduDilshara Nov 16, 2024
f0c7210
Add toXml implementation for sequence arrays
SasinduDilshara Nov 16, 2024
52de9ed
Add toXml implementation for sequence with elements
SasinduDilshara Nov 16, 2024
798bdcf
Add toXML API test for sequences
SasinduDilshara Nov 16, 2024
927adf8
Add toXml tests for choice arrays
SasinduDilshara Nov 17, 2024
ed31533
Add toxml test for choice with element annotations
SasinduDilshara Nov 17, 2024
25170dc
Add license headers for xsd related files
SasinduDilshara Nov 18, 2024
2ba6216
Add tests for validate and fromJson APIs
SasinduDilshara Nov 18, 2024
0cd9631
Fix issues related to java 21
SasinduDilshara Nov 18, 2024
3c2e4e7
Add tests for compiler plugin tests with invalid xsd annotations
SasinduDilshara Nov 18, 2024
98412af
Add compiler validation for sequence annotation
SasinduDilshara Nov 18, 2024
b7bb210
Add testcases for toxml validations
SasinduDilshara Nov 20, 2024
8269d3d
Add xsd sequence toXml tests with namespace annotations
SasinduDilshara Nov 20, 2024
414b636
Add documentations for xsd related public types
SasinduDilshara Nov 20, 2024
50beed2
Add tests for xsd with namespaces
SasinduDilshara Nov 20, 2024
4d37474
Add validation for choice tags in toXml function
SasinduDilshara Nov 21, 2024
0f3e4f4
Refactor sequence order compile time validation
SasinduDilshara Nov 21, 2024
395b399
Refactor the API docs in the validate API
SasinduDilshara Nov 22, 2024
4272d14
Update the validate API doc parameters
SasinduDilshara Nov 22, 2024
85891cf
Refactor the sequence order annotation in compiler plugin
SasinduDilshara Nov 22, 2024
0044bf0
Refactor data utils to make function early returns
SasinduDilshara Nov 22, 2024
cb0f04f
Update ballerina/tests/xsd_choice_array_test.bal
gimantha Nov 22, 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
3 changes: 3 additions & 0 deletions ballerina/tests/resources/xsd_tests/schemas/schema_1.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Book" type="xs:string"/>
</xs:schema>
16 changes: 16 additions & 0 deletions ballerina/tests/resources/xsd_tests/schemas/schema_2.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Library">
<xs:complexType>
<xs:sequence>
<xs:element name="Book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Title" type="xs:string"/>
<xs:element name="Author" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
11 changes: 11 additions & 0 deletions ballerina/tests/resources/xsd_tests/schemas/schema_3.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Person">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Age" type="xs:int"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
10 changes: 10 additions & 0 deletions ballerina/tests/resources/xsd_tests/schemas/schema_4.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Vehicle">
<xs:complexType>
<xs:choice>
<xs:element name="Car" type="xs:string"/>
<xs:element name="Bike" type="xs:string"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
10 changes: 10 additions & 0 deletions ballerina/tests/resources/xsd_tests/schemas/schema_5.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Order">
<xs:complexType>
<xs:all>
<xs:element name="OrderID" type="xs:int"/>
<xs:element name="Product" type="xs:string"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Book><Title>Sample</Title></Book>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Book>Sample</Book>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Library>
<Book>
<Title>Sample Title</Title>
</Book>
</Library>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Library>
<Book>
<Title>Sample Title</Title>
<Author>Sample Author</Author>
</Book>
</Library>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Person>
<Name>John Doe</Name>
<Age>30</Age>
</Person>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Person id="123">
<Name>John Doe</Name>
<Age>30</Age>
</Person>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Vehicle>
<Car>Toyota</Car>
<Bike>Yamaha</Bike>
</Vehicle>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Vehicle>
<Car>Toyota</Car>
</Vehicle>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Order>
<OrderID>12345</OrderID>
</Order>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Order>
<OrderID>12345</OrderID>
<Product>Laptop</Product>
</Order>
38 changes: 38 additions & 0 deletions ballerina/tests/test_from_json.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import ballerina/test;

@test:Config {groups: ["xsd", "to_xml"], dataProvider: fromJsonDataProvider}
function testFromJson(json value, xml expected) returns error?{
xml|Error xmlResult = fromJson(value);
test:assertEquals(xmlResult, expected);
}

function fromJsonDataProvider() returns [json, xml][] {
return [
[{a: {b: 2, c: 3}}, xml `<a><b>2</b><c>3</c></a>`],
[{a: {a: 1}}, xml `<a><a>1</a></a>`],
[{a: {d: 4, e: {f: 5, g: "text"}}}, xml `<a><d>4</d><e><f>5</f><g>text</g></e></a>`],
[{root: {nested: {value1: "example", value2: 10}}}, xml `<root><nested><value1>example</value1><value2>10</value2></nested></root>`],
[{book: {title: "XML Guide", author: "John Doe", year: 2024}}, xml `<book><title>XML Guide</title><author>John Doe</author><year>2024</year></book>`],
[{library: {section: {book1: "Book A", book2: "Book B"}}}, xml `<library><section><book1>Book A</book1><book2>Book B</book2></section></library>`],
[{person: {name: "Alice", details: {age: 30, city: "Wonderland"}}}, xml `<person><name>Alice</name><details><age>30</age><city>Wonderland</city></details></person>`],
[{catalog: {item: [{id: 1, name: "Item 1"}, {id: 2, name: "Item 2"}]}}, xml `<catalog><item><id>1</id><name>Item 1</name></item><item><id>2</id><name>Item 2</name></item></catalog>`],
[{company: {employee: {id: 1001, name: "Bob", department: "Engineering"}}}, xml `<company><employee><id>1001</id><name>Bob</name><department>Engineering</department></employee></company>`],
[{'order: {orderId: 5001, items: {item1: "Widget", item2: "Gadget"}}}, xml `<order><orderId>5001</orderId><items><item1>Widget</item1><item2>Gadget</item2></items></order>`],
[{menu: {dish: [{name: "Pasta", price: 12.5}, {name: "Salad", price: 8.0}]}}, xml `<menu><dish><name>Pasta</name><price>12.5</price></dish><dish><name>Salad</name><price>8.0</price></dish></menu>`],
[{report: {entries: [{date: "2024-10-01", detail: "Entry 1"}, {date: "2024-10-02", detail: "Entry 2"}]}}, xml `<report><entries><date>2024-10-01</date><detail>Entry 1</detail></entries><entries><date>2024-10-02</date><detail>Entry 2</detail></entries></report>`],
[{shoppingList: {items: [{item: "Apples", quantity: 5}, {item: "Bananas", quantity: 3}]}}, xml `<shoppingList><items><item>Apples</item><quantity>5</quantity></items><items><item>Bananas</item><quantity>3</quantity></items></shoppingList>`],
[{conference: {session: [{topic: "AI Trends", speaker: "Dr. Smith"}, {topic: "Web 3.0", speaker: "Jane Doe"}]}}, xml `<conference><session><topic>AI Trends</topic><speaker>Dr. Smith</speaker></session><session><topic>Web 3.0</topic><speaker>Jane Doe</speaker></session></conference>`],
[{project: {tasks: [{title: "Setup Environment", status: "Completed"}, {title: "Develop Module", status: "In Progress"}]}}, xml `<project><tasks><title>Setup Environment</title><status>Completed</status></tasks><tasks><title>Develop Module</title><status>In Progress</status></tasks></project>`],
[{school: {students: [{name: "Emily", grade: "A"}, {name: "Michael", grade: "B"}]}}, xml `<school><students><name>Emily</name><grade>A</grade></students><students><name>Michael</name><grade>B</grade></students></school>`],
[{portfolio: {stocks: [{symbol: "AAPL", shares: 50}, {symbol: "TSLA", shares: 30}]}}, xml `<portfolio><stocks><symbol>AAPL</symbol><shares>50</shares></stocks><stocks><symbol>TSLA</symbol><shares>30</shares></stocks></portfolio>`],
[{university: {course: [{name: "Mathematics", credits: 4}, {name: "History", credits: 3}]}}, xml `<university><course><name>Mathematics</name><credits>4</credits></course><course><name>History</name><credits>3</credits></course></university>`],
[{research: {papers: [{title: "Quantum Computing", author: "Alice Cooper"}, {title: "Blockchain Advances", author: "John Smith"}]}}, xml `<research><papers><title>Quantum Computing</title><author>Alice Cooper</author></papers><papers><title>Blockchain Advances</title><author>John Smith</author></papers></research>`],
[{movieCollection: {movies: [{title: "Inception", director: "Nolan"}, {title: "Interstellar", director: "Nolan"}]}}, xml `<movieCollection><movies><title>Inception</title><director>Nolan</director></movies><movies><title>Interstellar</title><director>Nolan</director></movies></movieCollection>`],
[{library: {books: [{title: "XML Guide", author: "John Doe", year: 2024}, {title: "JSON Primer", author: "Jane Smith", year: 2023}]}}, xml `<library><books><title>XML Guide</title><author>John Doe</author><year>2024</year></books><books><title>JSON Primer</title><author>Jane Smith</author><year>2023</year></books></library>`],
[{shoppingList: {items: [{item: "Apples", quantity: 5}, {item: "Bananas", quantity: 3}]}}, xml `<shoppingList><items><item>Apples</item><quantity>5</quantity></items><items><item>Bananas</item><quantity>3</quantity></items></shoppingList>`],
[{project: {tasks: [{title: "Setup Environment", status: "Completed"}, {title: "Develop Module", status: "In Progress"}]}}, xml `<project><tasks><title>Setup Environment</title><status>Completed</status></tasks><tasks><title>Develop Module</title><status>In Progress</status></tasks></project>`],
[{school: {students: [{name: "Emily", grade: "A"}, {name: "Michael", grade: "B"}]}}, xml `<school><students><name>Emily</name><grade>A</grade></students><students><name>Michael</name><grade>B</grade></students></school>`],
[{conference: {sessions: [{topic: "AI Trends", speaker: "Dr. Smith"}, {topic: "Web 3.0", speaker: "Jane Doe"}]}}, xml `<conference><sessions><topic>AI Trends</topic><speaker>Dr. Smith</speaker></sessions><sessions><topic>Web 3.0</topic><speaker>Jane Doe</speaker></sessions></conference>`],
[{catalog: {items: [{id: 1, name: "Item 1"}, {id: 2, name: "Item 2"}]}}, xml `<catalog><items><id>1</id><name>Item 1</name></items><items><id>2</id><name>Item 2</name></items></catalog>`]
];
}
2 changes: 1 addition & 1 deletion ballerina/tests/toXml_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function testToXmlWithNameAnnotation() returns error? {
xml xmlVal1 = xml `<Data8><A><D><C><D>1</D><D>2</D></C><C><D>3</D><D>4</D></C></D></A></Data8>`;
Rec2 rec1 = check parseAsType(xmlVal1);
xml result = check toXml(rec1);
test:assertTrue(result == xmlVal1);
test:assertEquals(result, xmlVal1);
}

@test:Config {
Expand Down
Loading
Loading