Validation

AMF can be used to validate parsed AML models. The validator is accessible through the validate method in the main AMF model.

The name of any loaded AML dialect can be used as the validation profile name used to validate the model.

Example

Java
JavaScript
package aml_org.examples;

import amf.client.AMF;
import amf.client.model.document.DialectInstance;
import amf.client.parse.Aml10Parser;
import amf.client.validate.ValidationReport;

import java.util.concurrent.ExecutionException;

import static java.lang.System.out;

public class Validating {

    //#validation-example
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        AMF.init().get();

        AMF.registerDialect("file://aml/music/dialect/playlist.yaml").get();

        DialectInstance model = (DialectInstance) new Aml10Parser().parseFileAsync("file://aml/music/playlist1.yaml").get();

        ValidationReport report = AMF.validate(model, "Playlist 1.0", "AMF").get();

        out.println("Validates?");
        out.println(report.conforms());
    }
}


var amf = require("amf-client-js");
var AMF = amf.AMF;
var Aml10Parser = amf.Aml10Parser;

//#validation-example
AMF.init()
    .then(function() {
        return AMF.registerDialect("file://aml/music/dialect/playlist.yaml");
    })
    .then(function() {
        return new Aml10Parser()
            .parseFileAsync("file://aml/music/playlist1.yaml");
    })
    .then(function(unit) {
        return AMF.validate(unit, "Playlist 1.0", "AMF");
    })
    .then(function(report) {
        console.log("Validates?");
        console.log(report.conforms);
    });

results matching ""

    No results matching ""