Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e0c1814
Improve the functionalities of handling XSD elements
Nuvindu Feb 1, 2025
e3ed03e
Update Gradle build files in the project
Nuvindu Feb 1, 2025
d498344
Improve XSD cli commands
Nuvindu Feb 1, 2025
bd4fd2d
Add necessary files to the package
Nuvindu Feb 1, 2025
01a0e60
Update docs in the package
Nuvindu Feb 1, 2025
370f7e6
Add module flag description in the XSD help text
Nuvindu Feb 1, 2025
92ed36f
Update spotbugs version
Nuvindu Feb 1, 2025
4f01e77
Encapsulate namespace field
Nuvindu Feb 1, 2025
8512090
Add doc comments to the Response class
Nuvindu Feb 1, 2025
50f4c49
Merge branch 'main' into improvements
Nuvindu Feb 1, 2025
ace48d4
Fix whitspace formatting issue
Nuvindu Feb 1, 2025
96ab08b
Update comments in native files
Nuvindu Feb 1, 2025
c91c65b
Improve XSD cli commands
Nuvindu Feb 3, 2025
d45494f
Update xsd help text
Nuvindu Feb 3, 2025
66de24f
Update docs in the project
Nuvindu Feb 3, 2025
c1ad1dc
Fix minor issues
Nuvindu Feb 7, 2025
1ae2a41
Remove unnecessary variable
Nuvindu Feb 7, 2025
6cd59f2
[Automated] Update the native jar versions
Nuvindu Feb 7, 2025
35c4619
Fix checkstyle build
Nuvindu Feb 7, 2025
080133f
Update the lang version to 2201.11.0
Nuvindu Feb 7, 2025
336eb82
Update license header
Nuvindu Feb 7, 2025
b26b17b
Update license header
Nuvindu Feb 7, 2025
60bc1e4
Remove unnecessary file
Nuvindu Feb 7, 2025
680eab0
Merge branch 'improvements' of https://github.com/Nuvindu/xsd-tools i…
Nuvindu Feb 7, 2025
edf243c
Fix test case path
Nuvindu Feb 7, 2025
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
149 changes: 147 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,147 @@
# xsd-tools
This is the source code of the XSD tool which converts XSD files into Ballerina records
# Ballerina XSD Tool

[![Build](https://github.com/ballerina-platform/xsd-tools/actions/workflows/build-timestamped-master.yml/badge.svg)](https://github.com/ballerina-platform/xsd-tools/actions/workflows/build-timestamped-master.yml)
[![codecov](https://codecov.io/gh/ballerina-platform/xsd-tools/branch/master/graph/badge.svg)](https://codecov.io/gh/ballerina-platform/xsd-tools)
[![GitHub Last Commit](https://img.shields.io/github/last-commit/ballerina-platform/xsd-tools.svg)](https://github.com/ballerina-platform/xsd-tools/commits/master)
[![GitHub issues](https://img.shields.io/github/issues/ballerina-platform/ballerina-standard-library/module/xsd-tools.svg?label=Open%20Issues)](https://github.com/ballerina-platform/ballerina-library/labels/module%2Fxsd-tools)

`XSD` (XML Schema Definition) is an approach to define the structure, elements, and constraints of XML documents. It is widely used for validating the content and structure of XML files.

The Ballerina XSD Tool simplifies the generation of Ballerina record types from an XSD specification, improving the user experience when integrating with XML-based operations in Ballerina.

### Installation

Execute the command below to pull the XSD tool from Ballerina Central.

```bash
$ bal tool pull xsd
```

### Usage

The XSD tool allows you to generate Ballerina record types from an XSD specification.

To generate Ballerina types, use the following command. It is mandatory to run the command inside a Ballerina project.

```bash
$ bal xsd <xsd-file-path>
[--module <output-module-name>]
```

#### Command options

| Option | Description | Mandatory/Optional |
|--------|-------------|--------------------|
| `<xsd-file-path>` | (Required) The path to the XSD file | Mandatory |
| `-m`, `--module` | The name of the module in which the Ballerina record types are generated | Optional |

### Generate types for the given XSD file

Use the following command to generate Ballerina record types for all elements defined in the specified XSD file. By default, the generated `types.bal` file will be placed in the default module of the current Ballerina project.

```bash
$ bal xsd <source-file-path>
```

For example,

```bash
$ bal xsd sample.xsd
```

If successful, you will see the following output.

```bash
The 'types.bal' file is written to the default module
```

#### Generate types in a specific module

To generate the Ballerina record types in a specific module, use the `--module` option.

```bash
$ bal xsd <source-file-path> --module <output-module-name>
```

For example,

```bash
$ bal xsd sample.xsd --module custom
```

This will generate a `types.bal` file inside the `custom` submodule within the Ballerina project.

The following output will be displayed.

```bash
The 'types.bal' file is written to 'modules/custom'
```

Upon successful execution, the generated files will include,

```bash
modules/
└── custom/
└── types.bal
```

## Building from the Source

### Setting Up the Prerequisites

1. OpenJDK 21 ([Adopt OpenJDK](https://adoptopenjdk.net/) or any other OpenJDK distribution)

>**Info:** You can also use [Oracle JDK](https://www.oracle.com/java/technologies/javase-downloads.html). Set the JAVA_HOME environment variable to the pathname of the directory into which you installed JDK.

2. Export GitHub Personal access token with read package permissions as follows,
```
export packageUser=<Username>
export packagePAT=<Personal access token>
```

### Building the Source

Execute the commands below to build from the source.

1. To build the library:

./gradlew clean build

2. To run the integration tests:

./gradlew clean test

3. To build the module without the tests:

./gradlew clean build -x test

4. To publish to maven local:

./gradlew clean build publishToMavenLocal

5. Publish the generated artifacts to the local Ballerina central repository:

./gradlew clean build -PpublishToLocalCentral=true

6. Publish the generated artifacts to the Ballerina central repository:

./gradlew clean build -PpublishToCentral=true

## Contributing to Ballerina

As an open-source project, Ballerina welcomes contributions from the community.

You can also check for [open issues](https://github.com/ballerina-platform/xsd-tools/issues) that
interest you. We look forward to receiving your contributions.

For more information, go to the [contribution guidelines](https://github.com/ballerina-platform/ballerina-lang/blob/master/CONTRIBUTING.md).

## Code of Conduct

All contributors are encouraged to read the [Ballerina Code of Conduct](https://ballerina.io/code-of-conduct).

## Useful Links

* Chat live with us via our [Discord server](https://discord.gg/ballerinalang).
* Post all technical questions on Stack Overflow with the [#ballerina](https://stackoverflow.com/questions/tagged/ballerina) tag.
* View the [Ballerina performance test results](https://github.com/ballerina-platform/ballerina-lang/blob/master/performance/benchmarks/summary.md).
6 changes: 6 additions & 0 deletions build-config/checkstyle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
* limitations under the License.
*
*/
import groovy.xml.XmlParser
import groovy.xml.XmlUtil

plugins {
id "de.undercouch.download"
}

apply plugin: 'java'

// Task to download the Checkstyle rule files
task downloadCheckstyleRuleFiles(type: Download) {
src([
'https://raw.githubusercontent.com/wso2/code-quality-tools/v1.4/checkstyle/jdk-17/checkstyle.xml',
Expand All @@ -31,14 +34,17 @@ task downloadCheckstyleRuleFiles(type: Download) {
dest buildDir
}

// Disable jar task
jar {
enabled = false
}

// Disable clean task
clean {
enabled = false
}

// Add modified checkstyle.xml and suppressions.xml as artifacts
artifacts.add('default', file("$project.buildDir/checkstyle.xml")) {
builtBy('downloadCheckstyleRuleFiles')
}
Expand Down
92 changes: 92 additions & 0 deletions build-config/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<!--
~ Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
~
~ 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.
-->
<FindBugsFilter>
<Match>
<Class name="io.ballerina.lib.avro.Utils" />
<Method name = "getMutableType" />
<Bug pattern="BC_UNCONFIRMED_CAST" />
</Match>
<Match>
<Class name="io.ballerina.xsd.core.XSDToRecord" />
<Bug pattern="EI_EXPOSE_REP" />
</Match>
<Match>
<Class name="io.ballerina.wsdl.core.handler.model.WsdlOperation$Builder" />
<Bug pattern="EI_EXPOSE_REP" />
</Match>
<Match>
<Class name="io.ballerina.wsdl.core.handler.model.WsdlOperation" />
<Bug pattern="EI_EXPOSE_REP" />
</Match>
<Match>
<Class name="io.ballerina.xsd.core.Response" />
<Bug pattern="EI_EXPOSE_REP" />
</Match>
<Match>
<Class name="io.ballerina.wsdl.core.WsdlToBallerina" />
<Bug pattern="EI_EXPOSE_REP" />
</Match>
<Match>
<Class name="io.ballerina.xsd.core.component.ComplexType" />
<Bug pattern="EI_EXPOSE_REP" />
</Match>
<Match>
<Class name="io.ballerina.xsd.core.component.Element" />
<Bug pattern="EI_EXPOSE_REP" />
</Match>
<Match>
<Class name="io.ballerina.xsd.core.component.SimpleType" />
<Bug pattern="EI_EXPOSE_REP" />
</Match>
<Match>
<Class name="io.ballerina.xsd.core.visitor.XSDVisitorImpl" />
<Bug pattern="EI_EXPOSE_REP" />
</Match>
<Match>
<Class name="io.ballerina.wsdl.core.WsdlToBallerina" />
<Bug pattern="EI_EXPOSE_REP2" />
</Match>
<Match>
<Class name="io.ballerina.wsdl.core.WsdlToBallerinaResponse" />
<Bug pattern="EI_EXPOSE_REP2" />
</Match>
<Match>
<Class name="io.ballerina.wsdl.core.handler.SchemaHandler" />
<Bug pattern="EI_EXPOSE_REP2" />
</Match>
<Match>
<Class name="io.ballerina.xsd.core.Response" />
<Bug pattern="EI_EXPOSE_REP2" />
</Match>
<Match>
<Class name="io.ballerina.wsdl.core.handler.model.WsdlOperation$Builder" />
<Bug pattern="EI_EXPOSE_REP2" />
</Match>
<Match>
<Class name="io.ballerina.xsd.core.component.ComplexType" />
<Bug pattern="EI_EXPOSE_REP2" />
</Match>
<Match>
<Class name="io.ballerina.xsd.core.component.Element" />
<Bug pattern="EI_EXPOSE_REP2" />
</Match>
<Match>
<Class name="io.ballerina.xsd.core.component.SimpleType" />
<Bug pattern="EI_EXPOSE_REP2" />
</Match>
</FindBugsFilter>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ tasks.register('clean') {
}

tasks.register('build') {
dependsOn(":module-ballerina-xsd:build")
dependsOn(":module-ballerina-xsd:build")
}

tasks.register('test') {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ group=io.ballerina
version=0.1.0-SNAPSHOT

# Dependencies
ballerinaLangVersion=2201.10.0
ballerinaLangVersion=2201.11.0
checkstylePluginVersion=10.12.0
spotbugsPluginVersion=5.0.14
spotbugsPluginVersion=6.0.18
shadowJarPluginVersion=8.1.1
downloadPluginVersion=5.4.0
releasePluginVersion=2.8.0
Expand Down
2 changes: 1 addition & 1 deletion module-ballerina-xsd/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.10.0"
distribution-version = "2201.11.0"

[[package]]
org = "ballerina"
Expand Down
82 changes: 81 additions & 1 deletion module-ballerina-xsd/Module.md
Original file line number Diff line number Diff line change
@@ -1 +1,81 @@
## Module Overview
## Overview

`XSD` (XML Schema Definition) is an approach to define the structure, elements, and constraints of XML documents. It is widely used for validating the content and structure of XML files.

The Ballerina XSD Tool simplifies the generation of Ballerina record types from an XSD specification, improving the user experience when integrating with XML-based operations in Ballerina.

### Installation

Execute the command below to pull the XSD tool from Ballerina Central.

```bash
$ bal tool pull xsd
```

### Usage

The XSD tool allows you to generate Ballerina record types from an XSD specification.

To generate Ballerina types, use the following command. It is mandatory to run the command inside a Ballerina project.

```bash
$ bal xsd <xsd-file-path>
[--module <output-module-name>]
```

#### Command options

| Option | Description | Mandatory/Optional |
|--------|-------------|--------------------|
| `<xsd-file-path>` | The path to the XSD file | Mandatory |
| `-m`, `--module` | The name of the module in which the Ballerina record types are generated | Optional |

### Generate types for the given XSD file

Use the following command to generate Ballerina record types for all elements defined in the specified XSD file. By default, the generated `types.bal` file will be placed in the default module of the current Ballerina project.

```bash
$ bal xsd <source-file-path>
```

For example,

```bash
$ bal xsd sample.xsd
```

If successful, you will see the following output.

```bash
The 'types.bal' file is written to the default module
```

#### Generate types in a specific module

To generate the Ballerina record types in a specific module, use the `--module` option.

```bash
$ bal xsd <source-file-path> --module <output-module-name>
```

For example,

```bash
$ bal xsd sample.xsd --module custom
```

This will generate a `types.bal` file inside the `custom` submodule within the Ballerina project.

The following output will be displayed.

```bash
The 'types.bal' file is written to 'modules/custom'
```

Upon successful execution, the generated files will include,

```bash
modules/
└── custom/
└── types.bal
```
Loading