More MCP refactoring
This commit is contained in:
@@ -1427,22 +1427,25 @@ FString MCPUtils::SetPropertyFromJson(
|
||||
*FieldName, *Prop->GetCPPType());
|
||||
}
|
||||
|
||||
FString MCPUtils::PopulateFromJson(
|
||||
bool MCPUtils::PopulateFromJson(
|
||||
UStruct* StructType,
|
||||
void* Container,
|
||||
const TSharedPtr<FJsonValue>& JsonValue)
|
||||
const TSharedPtr<FJsonValue>& JsonValue,
|
||||
MCPErrorCallback Error)
|
||||
{
|
||||
if (!JsonValue.IsValid() || (JsonValue->Type != EJson::Object))
|
||||
{
|
||||
return TEXT("Expected a JSON object");
|
||||
Error.SetError(TEXT("Expected a JSON object"));
|
||||
return false;
|
||||
}
|
||||
return PopulateFromJson(StructType, Container, JsonValue->AsObject().Get());
|
||||
return PopulateFromJson(StructType, Container, JsonValue->AsObject().Get(), Error);
|
||||
}
|
||||
|
||||
FString MCPUtils::PopulateFromJson(
|
||||
bool MCPUtils::PopulateFromJson(
|
||||
UStruct* StructType,
|
||||
void* Container,
|
||||
const FJsonObject* Json)
|
||||
const FJsonObject* Json,
|
||||
MCPErrorCallback Error)
|
||||
{
|
||||
// Build a set of known property names (as JSON keys) for the unknown-field check.
|
||||
TSet<FString> KnownKeys;
|
||||
@@ -1460,7 +1463,8 @@ FString MCPUtils::PopulateFromJson(
|
||||
{
|
||||
if (!KnownKeys.Contains(KV.Key))
|
||||
{
|
||||
return FString::Printf(TEXT("Unknown parameter '%s'"), *KV.Key);
|
||||
Error.SetError(FString::Printf(TEXT("Unknown parameter '%s'"), *KV.Key));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1474,17 +1478,19 @@ FString MCPUtils::PopulateFromJson(
|
||||
{
|
||||
if (!bOptional)
|
||||
{
|
||||
return FString::Printf(TEXT("Missing required parameter '%s'"), *JsonKey);
|
||||
Error.SetError(FString::Printf(TEXT("Missing required parameter '%s'"), *JsonKey));
|
||||
return false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
FString Error = SetPropertyFromJson(Container, Prop, JsonKey, Json);
|
||||
if (!Error.IsEmpty())
|
||||
FString PropError = SetPropertyFromJson(Container, Prop, JsonKey, Json);
|
||||
if (!PropError.IsEmpty())
|
||||
{
|
||||
return Error;
|
||||
Error.SetError(PropError);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return FString();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user