Метод CheckPath для проверки путей в схемах
This commit is contained in:
+6
-19
@@ -31,32 +31,19 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
|||||||
"Item.spell.system.heightening.damage"
|
"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)
|
if (CheckPath(node, DictionaryPaths))
|
||||||
//{
|
|
||||||
// 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))
|
return new DictionarySchemaType(node);
|
||||||
{
|
|
||||||
return new DictionarySchemaType(parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,29 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
{
|
{
|
||||||
internal class TypeResolver
|
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)
|
public JTokenType TokenType(JToken? value)
|
||||||
{
|
{
|
||||||
if (value is null || value.Type is JTokenType.Null or JTokenType.Undefined or JTokenType.None)
|
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;
|
return value.Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual AbstractSchemaType Resolve(SchemaNode parent, JToken? value)
|
public virtual AbstractSchemaType Resolve(SchemaNode node, JToken? value)
|
||||||
{
|
{
|
||||||
var type = TokenType(value);
|
var type = TokenType(value);
|
||||||
|
|
||||||
@@ -31,9 +54,9 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
|
|
||||||
return type switch
|
return type switch
|
||||||
{
|
{
|
||||||
JTokenType.Array => new ArraySchemaType(parent),
|
JTokenType.Array => new ArraySchemaType(node),
|
||||||
JTokenType.Object => new ObjectSchemaType(parent),
|
JTokenType.Object => new ObjectSchemaType(node),
|
||||||
_ => new StaticSchemaType(parent, type)
|
_ => new StaticSchemaType(node, type)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user