public object Interpret(BaseSchema schema, object value, IProcessContext context, string path) { if (value == null || !CanInterpret(schema)) { return(value); } var uid = JsonPointer.GetChild(value, "uid") as string; if (uid == null) { // schema validation threw error when uid is required, so here when uid is null, it must be optional, which is allowed return(value); } if (string.IsNullOrEmpty(uid)) { Logger.LogWarning($"Invalid xrefProperties for /{path}: empty uid is not allowed."); return(value); } var xrefSpec = new XRefSpec { Uid = uid }; var parts = schema.XrefProperties ?? new List <string> { "name", "fullName" }; var root = context.GetModel <object>(); foreach (var part in parts.Distinct()) { var jsonPointer = new JsonPointer(path + "/" + part); var property = jsonPointer.GetValue(root); if (property != null) { if (property is string str) { xrefSpec[part] = str; } else { Logger.LogWarning($"Type {property.GetType()} from {jsonPointer} is not supported as the value of xref spec."); } } } if (IsInternalXrefSpec(schema)) { context.Uids.Add(new UidDefinition(uid, context.OriginalFileAndType.FullPath, path: path + "/uid")); xrefSpec.Href = ((RelativePath)context.OriginalFileAndType.File).GetPathFromWorkingFolder().UrlEncode().ToString(); context.XRefSpecs.Add(xrefSpec); } else { context.ExternalXRefSpecs.Add(xrefSpec); } return(value); }
public object Interpret(BaseSchema schema, object value, IProcessContext context, string path) { if (value == null || !CanInterpret(schema)) { return(value); } var uid = JsonPointer.GetChild(value, "uid") as string; if (string.IsNullOrEmpty(uid)) { Logger.LogWarning($"Invalid xrefProperties for {path}: uid is not defined."); return(value); } var xrefSpec = new XRefSpec { Uid = uid }; var parts = schema.XrefProperties ?? new List <string> { "name", "fullName" }; var root = context.Model.Content; foreach (var part in parts.Distinct()) { var jsonPointer = new JsonPointer(path + "/" + part); var property = jsonPointer.GetValue(root); if (property != null) { if (property is string str) { xrefSpec[part] = str; } else { Logger.LogWarning($"Type {property.GetType()} from {jsonPointer} is not supported as the value of xref spec."); } } } if (IsInternalXrefSpec(schema)) { context.Properties.Uids.Add(new UidDefinition(uid, context.Model.LocalPathFromRoot, path: path + "/uid")); xrefSpec.Href = ((RelativePath)context.Model.Key).UrlEncode().ToString(); context.Properties.XRefSpecs.Add(xrefSpec); } else { context.Properties.ExternalXRefSpecs.Add(xrefSpec); } return(value); }