Метод CheckPath для проверки путей в схемах

This commit is contained in:
2025-03-29 16:26:39 +04:00
parent cabcb54816
commit 33105e29c4
2 changed files with 36 additions and 26 deletions
@@ -31,32 +31,19 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
"Item.spell.system.heightening.damage"
];
protected bool ShouldBeDictionary(SchemaNode parent, JToken? value)
public override AbstractSchemaType Resolve(SchemaNode node, JToken? value)
{
//if (value is not JValue || value.Parent is not JProperty)
//{
// return false;
//}
//var p = (JProperty)value.Parent;
//return DictionaryPaths.Any(path => path == $"{parent.Path}.{p.Name}");
return DictionaryPaths.Any(path => path == parent.Path);
}
public override AbstractSchemaType Resolve(SchemaNode parent, JToken? value)
{
if (ShouldBeDictionary(parent, value))
if (CheckPath(node, DictionaryPaths))
{
return new DictionarySchemaType(parent);
return new DictionarySchemaType(node);
}
if (parent.Path.EndsWith(".rules"))
if (node.Path.EndsWith(".rules"))
{
return new FoundryRulesSchemaType(parent);
return new FoundryRulesSchemaType(node);
}
return base.Resolve(parent, value);
return base.Resolve(node, value);
}
}
}
+27 -4
View File
@@ -10,6 +10,29 @@ namespace Pf2eDataScrapper.SchemaBuilder
{
internal class TypeResolver
{
public bool CheckPath(SchemaNode node, string path)
{
if (!path.Contains("*"))
{
return path == node.Path;
}
var pathParts = path.Split('.');
var nodeParts = node.Path.Split('.');
if (pathParts.Length > nodeParts.Length)
{
return false;
}
return !pathParts.Where((t, i) => t != "*" && t != nodeParts[i]).Any();
}
public bool CheckPath(SchemaNode node, ICollection<string> paths)
{
return paths.Any(path => CheckPath(node, path));
}
public JTokenType TokenType(JToken? value)
{
if (value is null || value.Type is JTokenType.Null or JTokenType.Undefined or JTokenType.None)
@@ -20,7 +43,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
return value.Type;
}
public virtual AbstractSchemaType Resolve(SchemaNode parent, JToken? value)
public virtual AbstractSchemaType Resolve(SchemaNode node, JToken? value)
{
var type = TokenType(value);
@@ -31,9 +54,9 @@ namespace Pf2eDataScrapper.SchemaBuilder
return type switch
{
JTokenType.Array => new ArraySchemaType(parent),
JTokenType.Object => new ObjectSchemaType(parent),
_ => new StaticSchemaType(parent, type)
JTokenType.Array => new ArraySchemaType(node),
JTokenType.Object => new ObjectSchemaType(node),
_ => new StaticSchemaType(node, type)
};
}