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/schemacontainer_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:labelversion is populated from an owl:Ontology owl:versionInfodescription is populated from an owl:Ontology dct:descriptionThe Shapes Graph is cleaned so that Node Shapes that are not references from any where and that don't have any properties attached are removed.
A pure value shape is a shape that has no non-deactivated attached properties (directly or through inheritance), and no target defined.
Each node shape that is not a pure value 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 that are pure value shape will be turned into string schemas being simple iri-reference.
title is populated from the node shape rdfs:labeldescription is populated from the node shape rdfs:commentid propertyshui:propertyRole shuiIDRole and this property has a sh:pattern, it is considered the pattern of the short form of the URI in the schema, and it is used for the pattern constraint on the id key.sh:node*/sh:pattern associated to the node shape (meaning, directly or through inheritance), it is turned into a pattern constraint on the id key, after attempting to reduce the pattern using the context (e.g. remove base URI)sh:node*/skos:example associated to the node shape (meaning, directly or through inheritance), it is turned into an example constraint on the id keyadditionalProperties is set to false, except if the flag "never set additional properties" is set.sh:node*/sh:property (meaning, directly or through inheritance) is processed as described belowNon-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 keysh:hasValue, a const schema is created with the value.
If a JSON-LD context was provided, an attempt is made to simplify the value to its actual mapping from the context, either because it is directly declared in the vocab, or because a prefix is declared.
sh:in, an enum schema is created with the list of possible values.
If a JSON-LD context was provided, an attempt is made to simplify the list of possible values to their actual mapping from the context, either because they are directly declared in the vocab, or because a prefix is declared.sh:node, then :
sh:node reference is a pure value shape, don't do anything specific, as further steps will take care of itshacl-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 section(sh:node*)/sh:pattern exists (i.e. attached directly to the property shape or through inheritance), and if the datatype of the property is not rdf:langString nor xsd:integer, then turn it into a string schema with a pattern constraint.
If a JSON-LD context was provided, the pattern constraint is "reduced" so that patterns matching complete IRIs may match only the end of IRI if they are shortened due to @base in the context(sh:node*)/sh:datatype (i.e. attached directly to the property shape or through inheritance), or an sh:qualifiedValueShape that has an sh:datatype then:
container_language in the #/$defs section(sh:node*)/sh:nodeKind (i.e. attached directly to the property shape or through inheritance) then
sh:IRI, generate a string schema of format iri-reference.sh:Literal, generate a string schema.(sh:node*)/sh:example (i.e. attached directly to the property shape or through inheritance) attempt to reduce them with the context and put them in "examples".empty schema@container: language, then:
@container : @set.
If the compaction test returns an array, then an array will be declared in the output schema.
title is populated from the property shape sh:namedescription is populated from the property shape sh:descriptionsh:minCount, or the sh:qualifiedMinCount of the property 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.