[−][src]Module atelier_rdf::model
Implements the mapping between the Smithy semantic model and an RDF graph. The functions
model_to_rdf
and rdf_to_model
perform the mapping itself.
Mapping
This provides a brief description of the Model to RDF mapping; the qualified names in the examples
below use the prefix "smithy" which is defined in vocabulary::PREFIX
and which maps to the namespace IRI in vocabulary::NAMESPACE
.
These values are set in the examples below in Turtle syntax as a common preamble:
@prefix smithy: <https://awslabs.github.io/smithy/vocab/1.0#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
Note the inclusion of the xsd
namespace for literals.
Model
- Each model MUST have a subject, either a provided IRI or a blank node will be created.
- This subject MUST have an
rdf:type
ofsmithy:Model
. - This subject MAY have a relationship, typed as
smithy:shapes
to a node withrdf:type
ofrdf:Bag
. This relationship may be omitted if the model contains no shapes.
_:subject a smithy:Model ;
smithy:shapes _:shapes .
_:shapes a rdf:Bag .
Shape
- Each shape MUST be present as a member of the
smithy:shapes
bag introduced above. - The identifier is the URN form of the shapes shape ID.
- The shape MUST include an
rdf:type
statement that denotes it's Smithy type. - Additional requirements are type specific and introduced below.
_:shapes rdf:li <urn:smithy:example.motd:Shape> .
<urn:smithy:example.motd:Shape> a smithy:String .
- Simple shapes;
- no additional rules.
- List and Set shapes;
- An additional statement for the shape MUST be present with the predicate
smithy:member
and the object being the URN of the target shape. - This member MAY have traits (see below).
- An additional statement for the shape MUST be present with the predicate
- Map shapes;
- An additional statement for the shape MUST be present with the predicate
smithy:key
and the object being the URN of the target shape. - An additional statement for the shape MUST be present with the predicate
smithy:value
and the object being the URN of the target shape. - These members MAY have traits (see below).
- An additional statement for the shape MUST be present with the predicate
- Structure and Union shapes;
- Each member of the shape becomes a statement with the shape ID as predicate and the object being a URN for the target shape.
- These members MAY have traits (see below).
- Service shapes;
- An additional statement for the shape MUST be present with the predicate
smithy:version
and the object being a literal, non-empty, string. - Each member of the shape becomes a statement with the corresponding predicate
smithy:*
and the object being the URN of the target shape. - For the multi-valued members
operations
, andresources
, the statement SHALL be repeated once for each value.
- An additional statement for the shape MUST be present with the predicate
- Operation shapes;
- Each member of the shape becomes a statement with the corresponding predicate
smithy:*
and the object being the URN of the target shape. - For the multi-valued member
errors
the statement SHALL be repeated once for each value.
- Each member of the shape becomes a statement with the corresponding predicate
- Resource Shapes;
- The resource subject MAY have a relationship, typed as
smithy:identifiers
to a node withrdf:type
ofrdf:Bag
. This relationship may be omitted if the model contains no identifier pairs.- Each identifier pair consists of a blank node in the bag with two statements;
- one with the predicate
smithy:key
and the object being a literal string for the identifier name, - one with the predicate
smithy:value
and the object being the URN of the target shape.
- one with the predicate
- Each identifier pair consists of a blank node in the bag with two statements;
- Each member of the shape becomes a statement with the corresponding predicate
smithy:*
and the object being the URN of the target shape. - For the multi-valued members
operations
,collectionOperations
, andresources
, the statement SHALL be repeated once for each value.
- The resource subject MAY have a relationship, typed as
Traits
Any shape, either a top-level shape, or a member, may have traits applied, these are represented as follows:
- This shape MAY have a relationship, typed as
smithy:traits
to a node withrdf:type
ofrdf:Bag
. This relationship may be omitted if the shape has no applied traits. - Each applied trait is represented as a blank node, with predicate
rdf:li
in the trait bag. - This new node MUST include a statement with the predicate
smithy:trait
and object being the URN of the trait shape. - The new node MAY include a statement with the predicate
smithy:value
and object being the value applied with this shape (see production below).
<urn:smithy:example.motd:Shape> a smithy:String ;
smithy:traits _:shape_traits .
_:shape_traits a rdf:Bag ;
rdf:li _:a_trait .
_:a_trait smithy:trait <urn:smithy:smithy.api:required> .
Values
Values are attached to a node with the predicate smithy:value
and the value represented as follows:
- string values MUST be represented as unqualified string literals,
- boolean values MUST be represented as string literals with the type
xsd:boolean
, - numeric values MUST be represented as string literals with either the type
xsd:signedLong
orxsd:double
. - null values MUST be represented as
rdf:nil
, - array values MUST be represented as a new blank node,
- this node MUST have a statement with
rdf:type
ofrdf:List
, - each element in the array occurs in this list with the predicate
rdf:li
and object being the value represented using these same production rules,
- this node MUST have a statement with
- object values MUST be represented as a new blank node,
- this node MUST have a statement with
rdf:type
ofrdf:Bag
, - each element in the object occurs in this list with the predicate
rdf:li
and object being a new node blank node, - this node MUST have a statement with
smithy:key
and the object being a string literal for the identifier name, - this node MUST have a statement with
smithy:value
and the object being the URN of the target shape.
- this node MUST have a statement with
_:a_trait smithy:trait <urn:smithy:smithy.api:documentation> ;
smithy:value "Here is some documentation".
Functions
model_to_rdf | Convert a Smithy semantic model into a canonical RDF graph representation. |
rdf_to_model | Convert an RDF graph into a Smithy semantic model. |