Module write

Module write 

Source
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.

  1. Reduce layers in the model that do not add value; i.e. [Identifierin the Rust model has an innervalue` field.
  2. Where an Option<T> field is None do not add a key in the generated object.
  3. Where a Vec<T> field is_empty do not add a key in the generated object.
  4. Use the key "__type" as a discriminator where the content of an object is ambiguous, especially in arrays.
  5. 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§

ValueOptions
WriteOptions

Traits§

ToJson

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