Skip to content

Commit

Permalink
Sample application fixes (#25)
Browse files Browse the repository at this point in the history
* Set headers for unauth'd request

* Fix authorization

* Remove unnecessary comment

* Remove duplicate .csproj entry

* Bump Kiota version

* Fix post-processor error
  • Loading branch information
kfcampbell authored Nov 3, 2023
1 parent f502c40 commit 16a32c9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
go-version: '1.20.4'

- name: Install kiota
run: dotnet tool install --global Microsoft.OpenApi.Kiota --version 1.8.0-preview.202310260001
run: dotnet tool install --global Microsoft.OpenApi.Kiota --version 1.8.1

- name: Download latest schema
run: go run schemas/main.go --schema-next=false
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This repository is a prototype of code generation from GitHub's OpenAPI specific
1. Run `go build -o post-processors/go/post-processor post-processors/go/main.go` to build the post-processor.
1. Run `post-processors/go/post-processor $(pwd)/generated/go` to execute the post-processor.
1. Run `go build ./...` from the directory in which you've output the generated code to check compilation.
1. Run `go run main.go` from the directory in which you've output the generated code in order to run the sample application.
1. Run `go run *.go` from the directory in which you've output the generated code in order to run the sample application.
1. For more info, [see Kiota documentation](https://microsoft.github.io/kiota/get-started/go.html).
<!-- TODO(kfcampbell): create main.go file and run it -->

Expand Down
1 change: 0 additions & 1 deletion generated/csharp/csharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.28.0" />
<PackageReference Include="Azure.Identity" Version="1.8.2" />
<PackageReference Include="Azure.Identity" Version="1.10.2" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.1.1" />
<PackageReference Include="Microsoft.Kiota.Authentication.Azure" Version="1.0.0" />
Expand Down
29 changes: 22 additions & 7 deletions generated/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import (
"log"
"os"

abstractions "github.com/microsoft/kiota-abstractions-go"
auth "github.com/microsoft/kiota-abstractions-go/authentication"
http "github.com/microsoft/kiota-http-go"
"github.com/octokit/kiota/octocat"
"github.com/octokit/kiota/user"
)

func main() {
Expand All @@ -16,7 +19,7 @@ func main() {
log.Fatalf("GITHUB_TOKEN must be provided")
}

tokenProvider, err := auth.NewApiKeyAuthenticationProvider(token, "authorization", auth.HEADER_KEYLOCATION)
tokenProvider, err := auth.NewApiKeyAuthenticationProvider(fmt.Sprintf("Bearer %s", token), "Authorization", auth.HEADER_KEYLOCATION)
if err != nil {
log.Fatalf("failed to initialize token provider: %v", err)
}
Expand All @@ -27,16 +30,28 @@ func main() {
}

client := NewApiClient(adapter)
headers := abstractions.NewRequestHeaders()
_ = headers.TryAdd("Accept", "application/vnd.github.v3+json")

// unauthenticated request
// cat, err := client.Octocat().Get(context.Background(), nil)
// if err != nil {
// log.Fatalf("error getting octocat: %v", err)
// }
// fmt.Printf("%v\n", string(cat))
s := "Salutations"
octocatRequestConfig := &octocat.OctocatRequestBuilderGetRequestConfiguration{
QueryParameters: &octocat.OctocatRequestBuilderGetQueryParameters{
S: &s,
},
Headers: headers,
}
cat, err := client.Octocat().Get(context.Background(), octocatRequestConfig)
if err != nil {
log.Fatalf("error getting octocat: %v", err)
}
fmt.Printf("%v\n", string(cat))

// authenticated request for private user emails
userEmails, err := client.User().Emails().Get(context.Background(), nil)
emailsRequestConfig := &user.EmailsRequestBuilderGetRequestConfiguration{
Headers: headers,
}
userEmails, err := client.User().Emails().Get(context.Background(), emailsRequestConfig)
if err != nil {
log.Fatalf("%v\n", err)
}
Expand Down
2 changes: 1 addition & 1 deletion post-processors/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func walkFiles(path string, info fs.FileInfo, err error) error {
func fixImports(inputFile string) string {
// find: kiota/
// replace: github.com/octokit/kiota/
inputFile = strings.ReplaceAll(inputFile, "kiota/", "github.com/octokit/kiota/")
inputFile = strings.ReplaceAll(inputFile, `"kiota/`, `"github.com/octokit/kiota/`)
return inputFile
}

Expand Down

0 comments on commit 16a32c9

Please sign in to comment.