-
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 #31 from DimuthuMadushan/example
Add Copybook Example
- Loading branch information
Showing
11 changed files
with
675 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
org = "ballerina" | ||
name = "EmployeeDetails" | ||
version = "0.1.0" | ||
distribution = "2201.8.0" | ||
|
||
[build-options] | ||
observabilityIncluded = true |
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,341 @@ | ||
# AUTO-GENERATED FILE. DO NOT MODIFY. | ||
|
||
# This file is auto-generated by Ballerina for managing dependency versions. | ||
# It should not be modified by hand. | ||
|
||
[ballerina] | ||
dependencies-toml-version = "2" | ||
distribution-version = "2201.8.0" | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "EmployeeDetails" | ||
version = "0.1.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "constraint"}, | ||
{org = "ballerina", name = "http"}, | ||
{org = "ballerina", name = "io"}, | ||
{org = "ballerina", name = "test"}, | ||
{org = "ballerinai", name = "observe"}, | ||
{org = "ballerinax", name = "copybook"} | ||
] | ||
modules = [ | ||
{org = "ballerina", packageName = "EmployeeDetails", moduleName = "EmployeeDetails"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "auth" | ||
version = "2.10.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "crypto"}, | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.array"}, | ||
{org = "ballerina", name = "lang.string"}, | ||
{org = "ballerina", name = "log"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "cache" | ||
version = "3.7.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "constraint"}, | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "task"}, | ||
{org = "ballerina", name = "time"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "constraint" | ||
version = "1.5.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
modules = [ | ||
{org = "ballerina", packageName = "constraint", moduleName = "constraint"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "crypto" | ||
version = "2.5.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "time"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "file" | ||
version = "1.9.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "io"}, | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "os"}, | ||
{org = "ballerina", name = "time"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "http" | ||
version = "2.10.3" | ||
dependencies = [ | ||
{org = "ballerina", name = "auth"}, | ||
{org = "ballerina", name = "cache"}, | ||
{org = "ballerina", name = "constraint"}, | ||
{org = "ballerina", name = "crypto"}, | ||
{org = "ballerina", name = "file"}, | ||
{org = "ballerina", name = "io"}, | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "jwt"}, | ||
{org = "ballerina", name = "lang.array"}, | ||
{org = "ballerina", name = "lang.decimal"}, | ||
{org = "ballerina", name = "lang.int"}, | ||
{org = "ballerina", name = "lang.regexp"}, | ||
{org = "ballerina", name = "lang.runtime"}, | ||
{org = "ballerina", name = "lang.string"}, | ||
{org = "ballerina", name = "lang.value"}, | ||
{org = "ballerina", name = "log"}, | ||
{org = "ballerina", name = "mime"}, | ||
{org = "ballerina", name = "oauth2"}, | ||
{org = "ballerina", name = "observe"}, | ||
{org = "ballerina", name = "time"}, | ||
{org = "ballerina", name = "url"} | ||
] | ||
modules = [ | ||
{org = "ballerina", packageName = "http", moduleName = "http"}, | ||
{org = "ballerina", packageName = "http", moduleName = "http.httpscerr"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "io" | ||
version = "1.6.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.value"} | ||
] | ||
modules = [ | ||
{org = "ballerina", packageName = "io", moduleName = "io"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "jballerina.java" | ||
version = "0.0.0" | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "jwt" | ||
version = "2.10.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "cache"}, | ||
{org = "ballerina", name = "crypto"}, | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.int"}, | ||
{org = "ballerina", name = "lang.string"}, | ||
{org = "ballerina", name = "log"}, | ||
{org = "ballerina", name = "time"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "lang.__internal" | ||
version = "0.0.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.object"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "lang.array" | ||
version = "0.0.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.__internal"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "lang.decimal" | ||
version = "0.0.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "lang.error" | ||
version = "0.0.0" | ||
scope = "testOnly" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "lang.int" | ||
version = "0.0.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.__internal"}, | ||
{org = "ballerina", name = "lang.object"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "lang.object" | ||
version = "0.0.0" | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "lang.regexp" | ||
version = "0.0.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "lang.runtime" | ||
version = "0.0.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "lang.string" | ||
version = "0.0.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.regexp"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "lang.value" | ||
version = "0.0.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "log" | ||
version = "2.9.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "io"}, | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.value"}, | ||
{org = "ballerina", name = "observe"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "mime" | ||
version = "2.9.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "io"}, | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.int"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "oauth2" | ||
version = "2.10.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "cache"}, | ||
{org = "ballerina", name = "crypto"}, | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "log"}, | ||
{org = "ballerina", name = "time"}, | ||
{org = "ballerina", name = "url"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "observe" | ||
version = "1.2.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "os" | ||
version = "1.8.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "io"}, | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "task" | ||
version = "2.5.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "time"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "test" | ||
version = "0.0.0" | ||
scope = "testOnly" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.error"} | ||
] | ||
modules = [ | ||
{org = "ballerina", packageName = "test", moduleName = "test"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "time" | ||
version = "2.4.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "url" | ||
version = "2.4.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerinai" | ||
name = "observe" | ||
version = "0.0.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "observe"} | ||
] | ||
modules = [ | ||
{org = "ballerinai", packageName = "observe", moduleName = "observe"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerinax" | ||
name = "copybook" | ||
version = "0.1.2" | ||
dependencies = [ | ||
{org = "ballerina", name = "constraint"}, | ||
{org = "ballerina", name = "file"}, | ||
{org = "ballerina", name = "io"}, | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.regexp"} | ||
] | ||
modules = [ | ||
{org = "ballerinax", packageName = "copybook", moduleName = "copybook"} | ||
] | ||
|
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,41 @@ | ||
# Copybook To Ballerina Conversion Example | ||
|
||
[![Star on Github](https://img.shields.io/badge/-Star%20on%20Github-blue?style=social&logo=github)](https://github.com/ballerina-platform/module-ballerinax-copybook) | ||
|
||
_Authors_: @MohamedSabthar @DimuthuMadushan \ | ||
_Reviewers_: @ThisaruGuruge \ | ||
_Created_: 2023/11/15 \ | ||
_Updated_: 2023/11/15 | ||
|
||
## Overview | ||
|
||
This example illustrates the process of converting values between Copybook and JSON formats using Ballerina. Additionally, it offers convenient APIs for validating and accessing fields within the Copybook. | ||
|
||
## Implementation | ||
|
||
Implementation is purely done using the Ballerina. The implementation utilizes its Copybook package for seamless bidirectional conversion between Copybook and JSON data formats. | ||
|
||
## Generate Ballerina Record Types | ||
The Copybook CLI tool simplifies converting Copybook definitions into Ballerina code. When implementing the `getEmployeeSalary` and `validateJsonData` APIs, the CLI tool can be used to generate the record types. To generate the records, use the below command. | ||
|
||
```shell | ||
bal copybook -i <path-to-copybook-definition> | ||
``` | ||
|
||
## Starting the Service | ||
|
||
To start the service, move into the copybook folder and execute the below command. | ||
|
||
```shell | ||
bal run | ||
``` | ||
|
||
It will build the Copybook Ballerina project and then run it. | ||
|
||
## Sample Curl Command | ||
|
||
```shell | ||
curl -X POST 'http://localhost:9090/convertToJson' \ | ||
--header 'Content-Type: text/plain' \ | ||
--data-raw '0001Mahroof Sabthar 01500.00A+99.820901R&D 29041Ballerina Vijya RoadKolonnawa 0100.00 09.2' | ||
``` |
Oops, something went wrong.