Value constraints
The Message Model Wizard supports value constraints (also known as datatype restrictions or facets) that restrict the allowed values for an element beyond its base datatype. For example, a string field might be constrained to a specific pattern, or a numeric field to a minimum and maximum range.
This page provides a comprehensive overview of how value constraints flow through the wizard: from input (OWL, SHACL, or JSON Schema) through the internal model to output schemas (XML Schema, JSON Schema, and SHACL).
Constraint mapping overview
The following tables show how each constraint type maps across all supported input and output formats.
String constraints
| Format | pattern | minLength | maxLength | length |
|---|---|---|---|---|
| SHACL input | sh:pattern | sh:minLength | sh:maxLength | X |
| OWL input | xsd:pattern | xsd:minLength | xsd:maxLength | xsd:length |
| JSON Schema input | pattern | minLength | maxLength | X |
| XML Schema output | xs:pattern | xs:minLength | xs:maxLength | xs:length |
| JSON Schema output | pattern | minLength | maxLength | minLength + maxLength |
| SHACL output | sh:pattern | sh:minLength | sh:maxLength | sh:minLength + sh:maxLength |
Numeric constraints
| Format | minInclusive | maxInclusive | minExclusive | maxExclusive | totalDigits | fractionDigits |
|---|---|---|---|---|---|---|
| SHACL input | sh:minInclusive | sh:maxInclusive | sh:minExclusive | sh:maxExclusive | X | X |
| OWL input | xsd:minInclusive | xsd:maxInclusive | xsd:minExclusive | xsd:maxExclusive | xsd:totalDigits | xsd:fractionDigits |
| JSON Schema input | minimum | maximum | exclusiveMinimum | exclusiveMaximum | X | X |
| XML Schema output | xs:minInclusive | xs:maxInclusive | xs:minExclusive | xs:maxExclusive | xs:totalDigits | xs:fractionDigits |
| JSON Schema output | minimum | maximum | exclusiveMinimum | exclusiveMaximum | X | X |
| SHACL output | sh:minInclusive | sh:maxInclusive | sh:minExclusive | sh:maxExclusive | X | X |
Enumeration constraints
| Format | fixedValue | allowedValues |
|---|---|---|
| SHACL input | X | X |
| OWL input | sth:fixedValue | OWL individuals |
| JSON Schema input | X | enum |
| XML Schema output | xs:enumeration (single) | xs:enumeration (multiple) |
| JSON Schema output | const | enum |
| SHACL output | sh:defaultValue + sh:in | sh:in |
An X means the constraint is not parsed from that input or not emitted to that output. See Limitations for details.
Running examples
The examples below use a Person shape with a password property (string constraints) and an age property (numeric constraints) to demonstrate each constraint category. Each section shows the same constraint in all supported input and output formats.
String constraints
Pattern
A regular expression that values must match.
SHACL input:
ex:PersonShape a sh:NodeShape ;
sh:targetClass ex:Person ;
sh:property [
sh:path ex:password ;
sh:datatype xsd:string ;
sh:pattern "[A-Za-z0-9!@#$%]{8,}" ;
] .
OWL input:
ex:password a owl:DatatypeProperty ;
rdfs:range [
a rdfs:Datatype ;
owl:onDatatype xsd:string ;
owl:withRestrictions (
[ xsd:pattern "[A-Za-z0-9!@#$%]{8,}" ]
)
] .
JSON Schema input:
{
"password": {
"type": "string",
"pattern": "^[A-Za-z0-9!@#$%]{8,}$"
}
}
XML Schema output:
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Za-z0-9!@#$%]{8,}"/>
</xs:restriction>
</xs:simpleType>
JSON Schema output:
{
"type": "string",
"pattern": "^[A-Za-z0-9!@#$%]{8,}$"
}
JSON Schema requires patterns to be anchored with ^ and $. The wizard adds these automatically when generating JSON Schema output and strips them when parsing JSON Schema input.
Min and max length
Restrict the number of characters in a string value.
SHACL input:
ex:PersonShape a sh:NodeShape ;
sh:targetClass ex:Person ;
sh:property [
sh:path ex:password ;
sh:datatype xsd:string ;
sh:minLength 8 ;
sh:maxLength 64 ;
] .
OWL input:
ex:password a owl:DatatypeProperty ;
rdfs:range [
a rdfs:Datatype ;
owl:onDatatype xsd:string ;
owl:withRestrictions (
[ xsd:minLength 8 ; xsd:maxLength 64 ]
)
] .
JSON Schema input:
{
"password": {
"type": "string",
"minLength": 8,
"maxLength": 64
}
}
XML Schema output:
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="8"/>
<xs:maxLength value="64"/>
</xs:restriction>
</xs:simpleType>
JSON Schema output:
{
"type": "string",
"minLength": 8,
"maxLength": 64
}
Exact length
When an exact length is specified (OWL only), it is emitted as a single xs:length facet in XML Schema. In JSON Schema and SHACL output, it is expressed as equal minLength and maxLength values.
OWL input:
ex:ibanCode a owl:DatatypeProperty ;
rdfs:range [
a rdfs:Datatype ;
owl:onDatatype xsd:string ;
owl:withRestrictions (
[ xsd:length 18 ]
)
] .
XML Schema output:
<xs:restriction base="xs:string">
<xs:length value="18"/>
</xs:restriction>
JSON Schema output:
{ "type": "string", "minLength": 18, "maxLength": 18 }
Numeric constraints
Inclusive bounds
Define a closed range where the boundary values are included.
SHACL input:
ex:PersonShape a sh:NodeShape ;
sh:targetClass ex:Person ;
sh:property [
sh:path ex:age ;
sh:datatype xsd:integer ;
sh:minInclusive 0 ;
sh:maxInclusive 150 ;
] .
OWL input:
ex:age a owl:DatatypeProperty ;
rdfs:range [
a rdfs:Datatype ;
owl:onDatatype xsd:integer ;
owl:withRestrictions (
[ xsd:minInclusive 0 ; xsd:maxInclusive 150 ]
)
] .
JSON Schema input:
{
"age": {
"type": "integer",
"minimum": 0,
"maximum": 150
}
}
XML Schema output:
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="150"/>
</xs:restriction>
</xs:simpleType>
JSON Schema output:
{
"type": "integer",
"minimum": 0,
"maximum": 150
}
Exclusive bounds
Define an open range where the boundary values are excluded.
SHACL input:
ex:PersonShape a sh:NodeShape ;
sh:targetClass ex:Person ;
sh:property [
sh:path ex:age ;
sh:datatype xsd:decimal ;
sh:minExclusive 0 ;
sh:maxExclusive 150 ;
] .
OWL input:
ex:age a owl:DatatypeProperty ;
rdfs:range [
a rdfs:Datatype ;
owl:onDatatype xsd:decimal ;
owl:withRestrictions (
[ xsd:minExclusive 0 ; xsd:maxExclusive 150 ]
)
] .
JSON Schema input:
{
"age": {
"type": "number",
"exclusiveMinimum": 0,
"exclusiveMaximum": 150
}
}
XML Schema output:
<xs:restriction base="xs:decimal">
<xs:minExclusive value="0"/>
<xs:maxExclusive value="150"/>
</xs:restriction>
JSON Schema output:
{
"type": "number",
"exclusiveMinimum": 0,
"exclusiveMaximum": 150
}
Total digits and fraction digits
Restrict the total number of digits and the number of digits after the decimal point. Only available via OWL input.
OWL input:
ex:unitPrice a owl:DatatypeProperty ;
rdfs:range [
a rdfs:Datatype ;
owl:onDatatype xsd:decimal ;
owl:withRestrictions (
[ xsd:totalDigits 10 ; xsd:fractionDigits 2 ]
)
] .
XML Schema output:
<xs:restriction base="xs:decimal">
<xs:totalDigits value="10"/>
<xs:fractionDigits value="2"/>
</xs:restriction>
totalDigits and fractionDigits cannot be expressed in JSON Schema or SHACL. These constraints are only emitted in XML Schema output.
Enumeration constraints
Allowed values (enumeration)
Restrict the value to one of a fixed set of options.
OWL input (using individuals of a class):
ex:Color a owl:Class .
ex:Red a ex:Color .
ex:Green a ex:Color .
ex:Blue a ex:Color .
ex:favoriteColor a owl:ObjectProperty ;
rdfs:range ex:Color .
When the wizard encounters a class used as range with individuals defined, those individuals become the allowed values.
OWL individuals are stored as full URIs internally. In the output formats, the values will be the full URIs (e.g., http://example.org/Red) rather than just the local name. The examples below use JSON Schema enum input, where the short values pass through as-is.
JSON Schema input:
{
"color": {
"type": "string",
"enum": ["Red", "Green", "Blue"]
}
}
XML Schema output:
<xs:restriction base="xs:string">
<xs:enumeration value="Red"/>
<xs:enumeration value="Green"/>
<xs:enumeration value="Blue"/>
</xs:restriction>
JSON Schema output:
{
"type": "string",
"enum": ["Red", "Green", "Blue"]
}
SHACL output:
ex:colorShape sh:in ( "Red" "Green" "Blue" ) .
Fixed value
A fixed value is a special case of enumeration with exactly one allowed value.
XML Schema output:
<xs:restriction base="xs:string">
<xs:enumeration value="EUR"/>
</xs:restriction>
JSON Schema output:
{ "type": "string", "const": "EUR" }
SHACL output:
ex:currencyShape
sh:defaultValue "EUR" ;
sh:in ( "EUR" ) .
Merging constraints
When the same property has constraints defined in multiple places (e.g., both the OWL ontology and a SHACL shapes graph), the wizard merges them by taking the most restrictive value for each aspect. For example:
minInclusive: the highest value winsmaxInclusive: the lowest value winsminLength: the highest value winsmaxLength: the lowest value wins
Limitations
The following limitations apply to the current implementation:
Input parsing limitations
| Limitation | Details |
|---|---|
| Named custom datatypes | When OWL defines a named datatype (e.g., ex:PositiveDecimal a rdfs:Datatype ; owl:onDatatype xsd:decimal ; owl:withRestrictions (...)) and a property references it via rdfs:range ex:PositiveDecimal, the wizard may not resolve the restrictions. Use inline anonymous restrictions on the property range instead. |
owl:unionOf in range | When a property range is defined as a union of classes, the wizard may not discover all class individuals. |
Output limitations
| Limitation | Details |
|---|---|
pattern | XML Schema and JSON Schema use slightly different regex dialects. The wizard does not convert between them. |
See also
- SHACL input: SHACL-specific constraint syntax
- OWL input: OWL class and property definitions
- Generate output: overview of output schema generation