Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snippets Refactor for dotnet #1793

Merged
merged 7 commits into from
Nov 1, 2023
Merged

Snippets Refactor for dotnet #1793

merged 7 commits into from
Nov 1, 2023

Conversation

andrueastman
Copy link
Member

@andrueastman andrueastman commented Oct 26, 2023

Partial of #1577

This PR refactors the snippet generation in C# to align with the new specification. In summary, this PR introduces the following changes to generated snippets.

  • Dropping of initialization statement var graphClient = new GraphServiceClient(requestAdapter)
  • Adding of using statements at the top of the snippets in favour of fully qualifying types with namespace names.
  • Addition of statements as comments for snippet guidance.

This means a snippet for a GET method without a request body that looked like this

// Code snippets are only available for the latest version. Current version is 5.x

var graphClient = new GraphServiceClient(requestAdapter);

var result = await graphClient.Me.GetAsync();

Now looks like this

// Code snippets are only available for the latest version. Current version is 5.x

// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Me.GetAsync();

This means a snippet for with a request body that looked like this

// Code snippets are only available for the latest version. Current version is 5.x

var graphClient = new GraphServiceClient(requestAdapter);

var requestBody = new User
{
	AccountEnabled = true,
	DisplayName = "Adele Vance",
	MailNickname = "AdeleV",
	UserPrincipalName = "AdeleV@contoso.onmicrosoft.com",
	PasswordProfile = new PasswordProfile
	{
		ForceChangePasswordNextSignIn = true,
		Password = "xWwvJ]6NMw+bWH-d",
	},
};
var result = await graphClient.Users.PostAsync(requestBody);

Now looks like this

// Code snippets are only available for the latest version. Current version is 5.x

// Dependencies
using Microsoft.Graph.Beta.Models;

var requestBody = new User
{
	AccountEnabled = true,
	DisplayName = "Adele Vance",
	MailNickname = "AdeleV",
	UserPrincipalName = "AdeleV@contoso.onmicrosoft.com",
	PasswordProfile = new PasswordProfile
	{
		ForceChangePasswordNextSignIn = true,
		Password = "xWwvJ]6NMw+bWH-d",
	},
};

// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Users.PostAsync(requestBody);

A preview of the generated snippets can viewed in the docs at the link below.
https://review.learn.microsoft.com/en-us/graph/api/user-post-users?view=graph-rest-beta&branch=pr-en-us-22904&tabs=csharp

Microsoft Reviewers: Open in CodeFlow

@sonarcloud
Copy link

sonarcloud bot commented Oct 26, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

90.9% 90.9% Coverage
0.0% 0.0% Duplication

@andrueastman andrueastman self-assigned this Oct 30, 2023
@andrueastman andrueastman marked this pull request as ready for review October 30, 2023 06:37
@andrueastman andrueastman requested a review from a team as a code owner October 30, 2023 06:37
@andrueastman andrueastman enabled auto-merge (squash) October 30, 2023 06:37
Copy link
Member

@SilasKenneth SilasKenneth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@andrueastman andrueastman merged commit 6f0480f into dev Nov 1, 2023
49 checks passed
@andrueastman andrueastman deleted the andrueastman/snippetsV2 branch November 1, 2023 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants