Skip to main content

resolve_context

Function resolve_context 

Source
pub fn resolve_context(
    parent: Option<&EffectiveContext>,
    authored: &Value,
    resources: &ContextResources,
    base_file: Option<&str>,
) -> Result<EffectiveContext, ContextError>
Expand description

Resolve an authored @context value over a parent and supplied resource closure.

The base_file identifies the containing local context file, if any. A digest-addressed resource has no file base. Reuse the same parent for sibling attribute and annotation scopes so their local bindings remain isolated.

use morphir_core::metadata::{ContextResources, Coercion, resolve_context};
use serde_json::json;
let resources = ContextResources::new("contexts");
let context = resolve_context(None, &json!({
    "@vocab": "morphir://ir/pkg/acme/metadata?format=4.0.0#/module/naming/value/",
    "replacement": {"@id": "morphir://ir/pkg/acme/metadata?format=4.0.0#/module/naming/value/replacement", "@type": "@id"}
}), &resources, None).unwrap();
assert_eq!(context.expand_key("replacement").unwrap().coercion(), Coercion::NodeId);