Метод CheckPath для проверки путей в схемах
This commit is contained in:
+7
-20
@@ -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);
|
||||
if (CheckPath(node, DictionaryPaths))
|
||||
{
|
||||
return new DictionarySchemaType(node);
|
||||
}
|
||||
|
||||
public override AbstractSchemaType Resolve(SchemaNode parent, JToken? value)
|
||||
if (node.Path.EndsWith(".rules"))
|
||||
{
|
||||
if (ShouldBeDictionary(parent, value))
|
||||
{
|
||||
return new DictionarySchemaType(parent);
|
||||
return new FoundryRulesSchemaType(node);
|
||||
}
|
||||
|
||||
if (parent.Path.EndsWith(".rules"))
|
||||
{
|
||||
return new FoundryRulesSchemaType(parent);
|
||||
}
|
||||
|
||||
return base.Resolve(parent, value);
|
||||
return base.Resolve(node, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user