es.modelValidate( model-descriptor as Node ) as Object
Validates an entity services model descriptor. If the descriptor is valid, returns an in-memory version of the basic model; otherwise, an exception is raised.
Parameters | |
---|---|
model-descriptor | A document or node containing a model descriptor, or a JavaScript object representing a model descriptor. |
Use this function as an entry point to the Entity Services API code generation functions. You can pass in either an in-memory JSON or XML model descriptor or a document that contains a JSON or XML model descriptor.
If the input descriptor is valid, then this function returns a
validated basic model. If the model descriptor is invalid, this function
throws an ES-MODEL-INVALID
exception. The error message
includes details about the validation failure(s).
Note that a JSON model descriptor looks the same as the default serialization of a validated basic model, so the input and output will be identical if the input is a valid JSON descriptor.
// Validate an in-memory model descriptor const es = require('/MarkLogic/entity-services/entity-services'); es.modelValidate( { "info": { "title": "Example", "version": "1.0.0" }, "definitions": { "Name": { "properties": { "first": { "datatype": "string" }, "middle": { "datatype": "string" }, "last": { "datatype": "string" } }, "required": [ "first", "last" ] } } } ); // Result: The basic model, as an Object. You can pass the result to any // Entity Services functions that expect a basic model as input. The output // basic model is the same as the input descriptor, when working with JSON.
// Validate a model descriptor stored in the database as XML const es = require('/MarkLogic/entity-services/entity-services'); // Assume /descriptors/name.xml contains the XML equiv to the descriptor // in the previous example. const modelDesc = fn.doc('/descriptors/name.xml'); es.modelValidate(modelDesc).info; // Validation returns the basic model, as an Object. The info property // contains the following: // // {"title":"Example", "version":"1.0.0"}
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.