private static void writeSnippet(SnippetCodeGraph codeGraph, StringBuilder builder) { writeHeadersAndOptions(codeGraph, builder); WriteBody(codeGraph, builder); builder.AppendLine(""); WriteExecutionStatement( codeGraph, builder, codeGraph.HasBody() ? RequestBodyVarName : default,
private static void WriteRequestExecutionPath(SnippetCodeGraph codeGraph, StringBuilder payloadSb, IndentManager indentManager) { var method = codeGraph.HttpMethod.Method.ToLower(); var configParameter = codeGraph.HasHeaders() || codeGraph.HasParameters() ? $"{RequestConfigurationVarName}" : string.Empty; var bodyParameter = codeGraph.HasBody() ? $"{RequestBodyVarName}" : string.Empty; var optionsParameter = codeGraph.HasOptions() ? "options" : string.Empty; var returnVar = codeGraph.HasReturnedBody() ? "$requestResult = " : string.Empty; var parameterList = GetActionParametersList(bodyParameter, configParameter, optionsParameter); payloadSb.AppendLine(GetRequestConfiguration(codeGraph, indentManager)); payloadSb.AppendLine($"{returnVar}{ClientVarName}->{GetFluentApiPath(codeGraph.Nodes)}->{method}({parameterList});"); }
public string GenerateCodeSnippet(SnippetModel snippetModel) { var indentManager = new IndentManager(); var codeGraph = new SnippetCodeGraph(snippetModel); var payloadSb = new StringBuilder( "<?php" + Environment.NewLine + Environment.NewLine + "// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY" + Environment.NewLine + $"{ClientVarName} = new {ClientVarType}({HttpCoreVarName});{Environment.NewLine}{Environment.NewLine}"); if (codeGraph.HasBody()) { WriteObjectProperty(RequestBodyVarName, payloadSb, codeGraph.Body, indentManager); } WriteRequestExecutionPath(codeGraph, payloadSb, indentManager); return(payloadSb.ToString()); }