Метод 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
+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)
};
}