Expand description
This module provides SDML to JSON Value functions for the entire model.
§Model Representation in JSON
§Template Context
Note that the created context values are not intended as a direct 1:1 representation of either the published surface syntax grammar or the Rust model. The form is simplified for use in the template language using the following guidelines.
- Reduce layers in the model that do not add value; i.e. [Identifier
in the Rust model has an inner
value` field. - Where an
Option<T>
field isNone
do not add a key in the generated object. - Where a
Vec<T>
fieldis_empty
do not add a key in the generated object. - Use the key
"__type"
as a discriminator where the content of an object is ambiguous, especially in arrays. - Only add
source_span
values for major objects such as definitions, not for individual names etc.
The upshot of this is that an if
statement in a template is used to check for presence of a value
before you use it. The following demonstrates this pattern for optional fields and possibly empty
collections.
{% if module.base_uri -%}
*Base URI*: {{ module.base_uri }}
{%- endif %}
{% if module.annotations -%}
{% for ann in module.annotations -%}
{{ ann.name }}
{%- endfor %}
{%- endif %}
Structs§
Traits§
Functions§
- module_
list_ to_ value - module_
to_ value - Convert a SDML
Module
into a JSON Value - write_
module - write_
module_ to_ string - write_
module_ with_ options - write_
module_ with_ options_ to_ string