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

Added Schema validator specification #116

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ type = "apple"
apple = "yes"
```

Validate a toml file
----------

A **TOML** file can be created and validated thanks to a **TOLS** file.

For more specification see [tols.md](tols.md)


Seriously?
----------

Expand Down
38 changes: 38 additions & 0 deletions tests/cache/cache-1.0.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8" ?>

<xsd:schema xmlns="http://toml.com/tests/cache"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://toml.com/tests/cache"
elementFormDefault="qualified">

<xsd:element name="config" type="config" />

<xsd:complexType name="config">
<xsd:sequence>
<xsd:element name="client" type="client" minOccurs="1" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="client">
<xsd:sequence>
<xsd:element name="dsn" type="xsd:string" minOccurs="1" maxOccurs="unbounded" />
<xsd:element name="options" type="client-options" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="type" type="client-type" use="required"/>
<xsd:attribute name="alias" type="xsd:string" use="required"/>
<xsd:attribute name="logging" type="xsd:boolean" />
</xsd:complexType>

<xsd:simpleType name="client-type">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="redis" />
<xsd:enumeration value="memcache" />
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="client-options">
<xsd:attribute name="connection-persistent" type="xsd:boolean" />
<xsd:attribute name="connection-timeout" type="xsd:int" />
</xsd:complexType>

</xsd:schema>
36 changes: 36 additions & 0 deletions tests/cache/cache.tols
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[cache.clients]
primitive = "Hash" # could be omitted
[cache.clients.client] # defines a new prototype, its name is not important
primitive = "Hash"
[cache.clients.client.occurrence]
min = 0 # at least one occurrence, no maximum
# start the prototype
[cache.clients.client.type]
primitive = "String" # typing
required = true # default is false
[cache.clients.client.type.range]
in = ["redis", "memcache"]
notin = ["mysql"] #mysql as cache is not supported

[cache.clients.client.alias]
primitive = "String" # typing
required = true # default is false

[cache.clients.client.dsn]
primitive = "Array"
[cache.clients.client.dsn.content]
primitive = "String"
pattern = "^(?:[0-9]{1,3}\\.){3}[0-9]{1,3}$" # regex for ip address, this is an example is not working

[cache.clients.client.logging]
primitive = "Boolean"
default = true

[cache.clients.client.options]
primitive = "Hash"
[cache.clients.client.options.connection_persistent]
primitive = "Boolean"
default = true

[cache.clients.client.options.connection_timeout]
primitive = "Integer"
13 changes: 13 additions & 0 deletions tests/cache/cache.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[cache.clients.default]
type = "redis"
alias = "default"
dsn = ["127.0.0.1"]
logging = false

[cache.clients.secondary]
type = "memcache"
alias = "secondary"
dsn = ["127.0.0.2", "127.0.0.3"]
logging = false
[cache.clients.secondary.options]
connection_persistent = true
12 changes: 12 additions & 0 deletions tests/cache/cache.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<red:config xmlns:red="http://toml.com/tests/cache">

<red:client type="redis" alias="default" logging="true">
<red:dsn>127.0.0.1</red:dsn>
</red:client>

<red:client type="memcache" alias="secondary" logging="false">
<red:dsn>127.0.0.2</red:dsn>
<red:dsn>127.0.0.3</red:dsn>
<red:options connection-persistent="true"/>
</red:client>
</red:config>
14 changes: 14 additions & 0 deletions tests/cache/cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cache:
clients:
default:
type: redis
alias: default
dsn: 127.0.0.1
logging: true
secondary:
type: memcache
alias: secondary
dsn: [127.0.0.2, 127.0.0.3]
logging: false
options:
connection_persistent: true
59 changes: 59 additions & 0 deletions tests/example.tols
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This is a TOLS document. Boom.
# This is also a TOML document. Boooom.

[title]
primitive = "String"
required = true

[owner]
[owner.name]
primitive = "String"
required = true

[owner.organization]
primitive = "String"
required = false

[owner.dob]
primitive = "Datetime"
required = true
[owner.dob.range]
min = 1913-05-27T07:32:00Z
max = 2013-05-27T07:32:00Z

[database]
[database.server]
primitive = "String"
required = true

[database.ports]
primitive = "Array"
required = true
[database.ports.range]
min = 0

[database.ports.content]
primitive = "Integer"

[database.ports.content.range]
min = 1024
max = 49151

[database.connection_max]
primitive = "Integer"
required = false
default = 5000

[database.enabled]
primitive = "Boolean"
default = false

# the toml should have at least one server with ip
[servers.0.ip]
primitive = "String"
required = true

# having the following line doesn't change anything.
#[clients]
# primitive = "Array"
# required = false
Loading