Skip to content

Comments

Add TOML parser and schema validator#7

Merged
heshanpadmasiri merged 8 commits intoballerina-platform:mainfrom
snelusha:toml-parser
Nov 17, 2025
Merged

Add TOML parser and schema validator#7
heshanpadmasiri merged 8 commits intoballerina-platform:mainfrom
snelusha:toml-parser

Conversation

@snelusha
Copy link
Contributor

This pull request introduces a new Go TOML parsing library with schema validation support, comprehensive diagnostics, and an extensive test suite. The implementation leverages third-party libraries for TOML parsing and JSON schema validation, and provides user-friendly APIs for reading, querying, and validating TOML files.

Core TOML parsing and querying functionality:

  • Added the initial implementation of the Toml struct and related types in tomlparser/toml.go, supporting reading TOML from files, streams, and strings, as well as querying values by dotted keys, extracting tables and arrays, and converting TOML data to Go structs. Diagnostics are recorded for parsing and mapping errors.

Schema validation support:

  • Introduced a generic Schema interface and implementation in tomlparser/schema.go using the jsonschema/v6 library, allowing validation of TOML data against JSON schemas loaded from files, strings, or file handles.
  • Added a Validator interface and implementation in tomlparser/validator.go to validate TOML documents against schemas and append diagnostics on validation errors.

Dependency management:

  • Updated go.mod to add dependencies on github.com/BurntSushi/toml for TOML parsing and github.com/santhosh-tekuri/jsonschema/v6 for schema validation.

Testing and sample data:

  • Added a comprehensive test suite in tomlparser/toml_test.go covering parsing, querying, diagnostics, and schema validation scenarios.
  • Provided sample TOML files and JSON schemas for testing in the testdata directory, including valid, invalid, and missing-required-field examples. [1] [2] [3] [4] [5] [6]

@heshanpadmasiri heshanpadmasiri merged commit cc2f2f1 into ballerina-platform:main Nov 17, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants