Skip to content

Commit

Permalink
Merge pull request #13 from octokit/fix-dotnet-generation
Browse files Browse the repository at this point in the history
Updates how we generate .net and simplifies the test app
  • Loading branch information
nickfloyd authored May 31, 2023
2 parents d918983 + e9f578f commit 09f2c97
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-csharp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: go run schemas/main.go --schema-next=false

- name: Run generation
run: time kiota generate -l csharp --ll trace -o generated/csharp/Octokit -n Octokit -d schemas/downloaded.json
run: time kiota generate -l csharp --ll trace -o generated/csharp/Octokit -c OctokitClient -n Octokit.Client -d schemas/downloaded.json

- name: Build post-processing
run: go build -o post-processors/csharp/post-processor post-processors/csharp/main.go
Expand Down
59 changes: 37 additions & 22 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug Go post-processing",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/post-processors/go/main.go",
"args": ["${workspaceFolder}/generated/go"]
},
{
"name": "Debug C# post-processing",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/post-processors/csharp/main.go",
"args": ["${workspaceFolder}/generated/csharp"]
},
]
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/generated/csharp/bin/Debug/net7.0/csharp.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"stopAtEntry": false
},
{
"name": "Debug Go post-processing",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/post-processors/go/main.go",
"args": [
"${workspaceFolder}/generated/go"
]
},
{
"name": "Debug C# post-processing",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/post-processors/csharp/main.go",
"args": [
"${workspaceFolder}/generated/csharp"
]
},
]
}
41 changes: 41 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/generated/csharp/csharp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/generated/csharp/csharp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/generated/csharp/csharp.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
59 changes: 7 additions & 52 deletions generated/csharp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,56 +1,11 @@
using Azure.Identity;
using Azure.Core;
using Octokit.Client;
using Microsoft.Kiota.Abstractions.Authentication;
using Microsoft.Kiota.Authentication.Azure;
using Microsoft.Kiota.Http.HttpClientLibrary;
using Octokit;

var token = Environment.GetEnvironmentVariable("GITHUB_TOKEN");
if (string.IsNullOrEmpty(token))
{
Console.WriteLine("GITHUB_TOKEN environment variable is not set");
// throw new Exception("GITHUB_TOKEN environment variable is not set");
}
// API requires no authentication, so use the anonymous
var authProvider = new AnonymousAuthenticationProvider();
var adapter = new HttpClientRequestAdapter(authProvider);
var client = new OctokitClient(adapter);

var authProvider = new ApiKeyAuthenticationProvider(token, "Authorization", ApiKeyAuthenticationProvider.KeyLocation.Header, new string[] { "https://api.github.com" });
var requestAdapter = new HttpClientRequestAdapter(authProvider, null, null, new HttpClient
{
BaseAddress = new Uri("https://api.github.com/")
});
var pathParameters = new Dictionary<string, object>() {
{"baseurl", "https://api.github.com/"},
};
var octocatPathParams = new Octokit.Octocat.OctocatRequestBuilder(pathParameters, requestAdapter);
Action<Octokit.Octocat.OctocatRequestBuilder.OctocatRequestBuilderGetRequestConfiguration> requestConfig =
delegate (Octokit.Octocat.OctocatRequestBuilder.OctocatRequestBuilderGetRequestConfiguration config)
{
config.QueryParameters.S = "Hey yo!";
config.Headers.Add("Accept", "application/vnd.github.v3+json");
};

try
{
Stream requestPathParam = await octocatPathParams.GetAsync(requestConfig);
StreamReader rPathParams = new StreamReader(requestPathParam);
string responsePathParams = rPathParams.ReadToEnd();
Console.WriteLine(responsePathParams);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw;
}


// Passing path parms

// Basic request

// var client = new Octokit.ApiClient(requestAdapter);
// var request = await client.Octocat.GetAsync();

// StreamReader reader = new StreamReader(request);
// string response = reader.ReadToEnd();
// Console.WriteLine(response);

// Basic request
var user = await client.Users["nickfloyd"].GetAsync();
user?.AdditionalData.ToList().ForEach(x => Console.WriteLine(x.Key + ": " + x.Value));
29 changes: 1 addition & 28 deletions post-processors/csharp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,33 +101,6 @@ func fixThumbsUpThumbsDownProperties(inputFile string) string {
func fixPagesPaths(inputFile string) string {
// find: Path = PagesPostRequestBody_source_path.;
// replace: Path = PagesPostRequestBody_source_path.Root;
inputFile = strings.ReplaceAll(inputFile, "Path = PagesPostRequestBody_source_path.;", "Path = PagesPostRequestBody_source_path.Root;")

// find:
/*
public enum PagesPostRequestBody_source_path {
[EnumMember(Value = "/docs")]
Docs,
}
*/
// replace:
/*
public enum PagesPostRequestBody_source_path {
[EnumMember(Value = "/")]
Root,
[EnumMember(Value = "/docs")]
Docs,
}
*/

inputFile = strings.ReplaceAll(inputFile, `public enum PagesPostRequestBody_source_path {
[EnumMember(Value = "/docs")]
Docs,
}`, `public enum PagesPostRequestBody_source_path {
[EnumMember(Value = "/")]
Root,
[EnumMember(Value = "/docs")]
Docs,
}`)
inputFile = strings.ReplaceAll(inputFile, "Path = PagesPostRequestBody_source_path.;", "Path = PagesPostRequestBody_source_path.Docs;")
return inputFile
}
2 changes: 1 addition & 1 deletion scripts/generate-csharp.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

# Execute generation
kiota generate -l csharp --ll trace -o generated/csharp/Octokit -n Octokit -d schemas/updated/api.github.com.json --co
kiota generate -l csharp --ll trace -o generated/csharp/Octokit -c OctokitClient -n Octokit.Client -d schemas/updated/api.github.com.json --co

# Build and run post-processor
go build -o $(pwd)/post-processors/csharp/post-processor post-processors/csharp/main.go
Expand Down

0 comments on commit 09f2c97

Please sign in to comment.