Skip to content

Commit

Permalink
Merge pull request #2184 from microsoftgraph/dev
Browse files Browse the repository at this point in the history
Merge dev into master
  • Loading branch information
millicentachieng authored Sep 4, 2024
2 parents 0666f30 + 73a4e6f commit 54d0cba
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CodeSnippetsPipeline.Test/CodeSnippetsPipeline.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="NUnit" Version="4.2.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="moq" Version="4.20.70" />
<PackageReference Include="moq" Version="4.20.71" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
4 changes: 2 additions & 2 deletions CodeSnippetsReflection.OpenAPI.Test/PythonGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public async Task GeneratesTheCorrectSnippetForUsers()
Assert.Contains(".me.get()", result);
}
[Fact]
public async Task GeneratesTheSnippetHeader()
public async Task GeneratesTheClientCommnet()
{
using var requestPayload = new HttpRequestMessage(HttpMethod.Get, $"{ServiceRootUrl}/me/messages");
var snippetModel = new SnippetModel(requestPayload, ServiceRootUrl, await GetV1SnippetMetadata());
var result = _generator.GenerateCodeSnippet(snippetModel);
Assert.Contains("graph_client = GraphServiceClient(credentials, scopes)", result);
Assert.Contains("# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python", result);
}
[Fact]
public async Task GeneratesThePostMethodCall()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.22.0" />
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.17" />
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.19" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ namespace CodeSnippetsReflection.OpenAPI.LanguageGenerators
public class PythonGenerator : ILanguageGenerator<SnippetModel, OpenApiUrlTreeNode>
{
private const string ClientVarName = "graph_client";
private const string ClientVarType = "GraphServiceClient";
private const string CredentialVarName = "credentials";
private const string ScopesVarName = "scopes";
private const string RequestBodyVarName = "request_body";
private const string RequestConfigurationVarName = "request_configuration";
private const string RequestConfigurationType = "RequestConfiguration";
private const string RequestParametersPropertyName = "query_params";
private const string VersionInformationString = "# Code snippets are only available for the latest version. Current version is 1.x";

private const string InitializationInfoString = "# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python";


private static readonly HashSet<string> ReservedTypeNames = new(StringComparer.OrdinalIgnoreCase)
{
Expand Down Expand Up @@ -67,13 +68,14 @@ public string GenerateCodeSnippet(SnippetModel snippetModel)
{
var indentManager = new IndentManager();
var codeGraph = new SnippetCodeGraph(snippetModel);
var snippetBuilder = new StringBuilder($"{Environment.NewLine}{Environment.NewLine}" +
$"{ClientVarName} = {ClientVarType}({CredentialVarName}, {ScopesVarName}){Environment.NewLine}{Environment.NewLine}");
var snippetBuilder = new StringBuilder();
snippetBuilder.AppendLine(InitializationInfoString);

WriteRequestPayloadAndVariableName(codeGraph, snippetBuilder, indentManager);
WriteRequestExecutionPath(codeGraph, snippetBuilder, indentManager);
var importStatements = GetImportStatements(snippetModel);
snippetBuilder.Insert(0, string.Join(Environment.NewLine, importStatements));
snippetBuilder.Insert(0, VersionInformationString + Environment.NewLine);
snippetBuilder.Insert(VersionInformationString.Length + Environment.NewLine.Length, string.Join(Environment.NewLine, importStatements) + Environment.NewLine);
return snippetBuilder.ToString();
}
private static HashSet<string> GetImportStatements(SnippetModel snippetModel)
Expand Down
2 changes: 1 addition & 1 deletion FileService.Test/FileService.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="Moq" Version="4.20.71" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
1 change: 0 additions & 1 deletion GraphWebApi/GraphWebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.22.0" />
<PackageReference Include="Microsoft.ApplicationInsights.PerfCounterCollector" Version="2.22.0" />
<PackageReference Include="Microsoft.ApplicationInsights.SnapshotCollector" Version="1.4.6" />
<PackageReference Include="Microsoft.ApplicationInsights.Web" Version="2.22.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.ApplicationInsights.HostingStartup" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.8" />
Expand Down
2 changes: 1 addition & 1 deletion KnownIssuesService.Test/KnownIssuesService.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="Moq" Version="4.20.71" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
Expand Down
1 change: 0 additions & 1 deletion KnownIssuesService/KnownIssuesService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="19.225.1" />
<PackageReference Include="Microsoft.VisualStudio.Services.Client" Version="19.225.1" />
Expand Down
2 changes: 1 addition & 1 deletion MockTestUtility/MockTestUtility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="moq" Version="4.20.70" />
<PackageReference Include="moq" Version="4.20.71" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

Expand Down
1 change: 0 additions & 1 deletion OpenAPIService.Test/OpenAPIService.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.17" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
Expand Down
4 changes: 2 additions & 2 deletions OpenAPIService/OpenAPIService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.1" />
<PackageReference Include="Microsoft.OData.Edm" Version="8.0.1" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.17" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.19" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.6.8" />
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.17" />
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.19" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion PermissionsService/PermissionsService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageReference Include="Microsoft.Graph.Kibali" Version="0.24.0" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.17" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.19" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion apidoctor

0 comments on commit 54d0cba

Please sign in to comment.