es:model-validate( $model-descriptor as node() ) as map:map
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
map:map 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 XML model descriptor :) xquery version "1.0-ml"; import module namespace es = "http://marklogic.com/entity-services" at "/MarkLogic/entity-services/entity-services.xqy"; es:model-validate( <es:model xmlns:es="http://marklogic.com/entity-services"> <es:info> <es:title>Example</es:title> <es:version>1.0.0</es:version> </es:info> <es:definitions> <Name> <es:properties> <first><es:datatype>string</es:datatype></first> <middle><es:datatype>string</es:datatype></middle> <last><es:datatype>string</es:datatype></last> </es:properties> <es:required>first</es:required> <es:required>last</es:required> </Name> </es:definitions> </es:model> ) (: ==> The basic model, as a <json:object/>. You can inspect the contents using map:map functions, as well as passing the basic model to any Entity Services functions that expect a basic model as input. The map:map contents are equivalent to the following JSON serialization: { "info": { "title": "Example", "version": "1.0.0" }, "definitions": { "Name": { "properties": { "first": { "datatype": "string" }, "middle": { "datatype": "string" }, "last": { "datatype": "string" } }, "required": [ "first", "last" ] } } } :)
(: Validate a descriptor in the db and use it as a map:map :) (: Refer to the previous example for the descriptor contents :) xquery version "1.0-ml"; import module namespace es = "http://marklogic.com/entity-services" at "/MarkLogic/entity-services/entity-services.xqy"; let $model-desc := fn:doc("/descriptors/name.xml") let $basic-model := es:model-validate($model-desc) return map:get($basic-model, "info") (: ==> The value of the "info" property of the basic model. The value is a <json:object/>. The JSON serialization appears as follows: {"title":"Example", "version":"1.0.0"} :)
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.