Module atelier_core::action[][src]

Expand description

This module provides a set of traits that describes actions that can operate on models. These actions take three major forms; linters, validators, and transformers.

  1. Linters; these inspect the model for stylistic issues, they are a subset of validators.
  2. Validators; these inspect models for errors and warnings that may produce errors when the model is used.
  3. Transformers; these take in a model and transform it into another model.

Example

The following example is taken from the Smithy specification discussing relative name resolution. The run_validation_actions function is commonly used to take a list of actions to be performed on the model in sequence.

use atelier_core::action::validate::{
    run_validation_actions, CorrectTypeReferences
};
use atelier_core::action::Validator;
use atelier_core::builder::{
    ModelBuilder, ShapeTraits, SimpleShapeBuilder, StructureBuilder, TraitBuilder
};
use atelier_core::model::Model;
use atelier_core::Version;
use std::convert::TryInto;

let model: Model = ModelBuilder::new(Version::V10, "smithy.example")
    .uses("foo.baz#Bar")
    .structure(
        StructureBuilder::new("MyStructure")
            .member("a", "MyString")
            .member("b", "smithy.example#MyString")
            .member("d", "foo.baz#Bar")
            .member("f", "String")
            .member("g", "MyBoolean")
            .apply_trait(TraitBuilder::new("documentation"))
            .into(),
    )
    .simple_shape(SimpleShapeBuilder::string("MyString"))
    .simple_shape(SimpleShapeBuilder::boolean("MyBoolean"))
    .try_into().unwrap();
let result = run_validation_actions(&mut [
        Box::new(CorrectTypeReferences::default()),
    ], &model, false);

This will result in the following list of validation errors. Note that the error is denoted against shape or member identifier accordingly.

[
    ActionIssue {
        reporter: "CorrectTypeReferences",
        level: Info,
        message: "The simple shape (smithy.example#MyBoolean) is simply a synonym, did you mean to add any constraint traits?",
        locus: Some(
            ShapeID {
                namespace: NamespaceID(
                    "smithy.example",
                ),
                shape_name: Identifier(
                    "MyBoolean",
                ),
                member_name: None,
            },
        ),
    },
    ActionIssue {
        reporter: "CorrectTypeReferences",
        level: Info,
        message: "The simple shape (smithy.example#MyString) is simply a synonym, did you mean to add any constraint traits?",
        locus: Some(
            ShapeID {
                namespace: NamespaceID(
                    "smithy.example",
                ),
                shape_name: Identifier(
                    "MyString",
                ),
                member_name: None,
            },
        ),
    },
]

Modules

This module contains core Linter implementations. It also provides a function, run_linter_actions, that takes a list of linters to run against a model. This is the preferred way to run the linter actions as it allows for fast fail on detecting errors in an action.

This module contains core Validator implementations. It also provides a function, run_validation_actions, that takes a list of validators to run against a model. This is the preferred way to run the validation actions as it allows for fast fail on detecting errors in an action.

Structs

An issue reported by an action. An issue may, or may not, be associated with a shape but will always include a message.

Enums

Denotes the level associated with an issue reported by an action.

Traits

A trait required by Linter, Validator, and Transformer.

Check the model for stylistic or other conventions that the author should be aware of. An error represents a failure in the linter itself, not the presence of any issues which should be fetched using Action::issues or Action::issues_mut.

Create a new model from an existing one; this might be a filter, a decorator, or generator. An error represents a failure in the transformer itself, not the presence of any issues which should be fetched using Action::issues or Action::issues_mut.

Validate the model according to rules that determine whether it is complete and usable.. An error represents a failure in the validator itself, not the presence of any issues which should be fetched using Action::issues or Action::issues_mut.