in src/Core/Compiling/Policy/SetBodyCompiler.cs [18:80]
public void Handle(ICompilationContext context, InvocationExpressionSyntax node)
{
var arguments = node.ArgumentList.Arguments;
if (arguments.Count is > 2 or 0)
{
context.Report(Diagnostic.Create(
CompilationErrors.ArgumentCountMissMatchForPolicy,
node.ArgumentList.GetLocation(),
"set-body"));
return;
}
var value = node.ArgumentList.Arguments[0].Expression.ProcessParameter(context);
var element = new XElement("set-body", value);
if (node.ArgumentList.Arguments.Count == 2)
{
var contentType = node.ArgumentList.Arguments[1].Expression.ProcessExpression(context);
if (contentType is { Type: nameof(SetBodyConfig), NamedValues: not null })
{
if (contentType.NamedValues.TryGetValue(nameof(SetBodyConfig.Template), out var template))
{
if (template.Value != "liquid")
{
context.Report(Diagnostic.Create(
CompilationErrors.OnlyOneOfTwoShouldBeDefined,
template.Node.GetLocation(),
"forward-request.template",
"liquid"
));
}
else
{
element.Add(new XAttribute("template", template.Value));
}
}
if (contentType.NamedValues.TryGetValue(nameof(SetBodyConfig.XsiNil), out var xsiNil))
{
if (xsiNil.Value != "blank" && xsiNil.Value != "null")
{
context.Report(Diagnostic.Create(
CompilationErrors.OnlyOneOfTwoShouldBeDefined,
xsiNil.Node.GetLocation(),
"forward-request.xsi-nil",
"blank",
"null"
));
}
else
{
element.Add(new XAttribute("xsi-nil", xsiNil.Value));
}
}
if (contentType.NamedValues.TryGetValue(nameof(SetBodyConfig.ParseDate), out var parseDate))
{
element.Add(new XAttribute("parse-date", parseDate.Value!));
}
}
}
context.AddPolicy(element);
}