This utility generates a JSON Schema document from a SHACL specification. Detailed documentation is available below.
The algorithm follow these steps to generate the JSON Schema:
@context
since we are targeting JSON-LDhttps://json-schema.org/draft/2020-12/schema
container_language
declaration is always added with a patternProperty
declaration with properties
being language codes to deal with "@container": "language"
properties.
title
is populated from an owl:Ontology dct:title
or rdfs:label
version
is populated from an owl:Ontology owl:versionInfo
description
is populated from an owl:Ontology dct:description
Each node shape with at least one non-deactivated property shape is turned into an object schema in the $defs
section of the schema, with the URI
local name as the name of the schema. Node shapes with no non-deactivated property shapes are turned into string schemas being simple iri-reference
.
title
is populated from the node shape rdfs:label
description
is populated from the node shape rdfs:comment
id
propertyadditionalProperties
is set to falseNon-deactivated property shapes are processed this way:
shacl-play:shortName
annotation, otherwise the local name of the property in sh:path is used as the JSON keytitle
is populated from the property shape sh:name
description
is populated from the property shape sh:description
sh:hasValue
, a const
schema is created with the valuesh:in
, an enum
schema is created with the list of possible valuessh:node
, then :
shacl-play:embed shacl-play:EmbedNever
, then a string schema with format iri-reference
is generated$ref
schema with a reference to one of the schemas in the #/$defs
sectionarray
schemash:pattern
, then turn it into a string schema with a pattern
constraint.sh:datatype
(with a consistent value for the same property across the SHACL spec), then:
container_language
in the #/$defs
sectionsh:nodeKind
pointing to sh:IRI, generate a string schema of format iri-reference
.empty
schemash:minCount
is > 0, the JSON key is added to the list of requiredProperties
of the schemaWith the provided root node shape IRI, create a reference to the corresponding schema from the #/$defs
section.