Skip to content

Latest commit

Β 

History

History
91 lines (72 loc) Β· 3.49 KB

File metadata and controls

91 lines (72 loc) Β· 3.49 KB

Open Sauced

πŸ• Go API Client πŸ•

The generated Go OpenSauced API client

GitHub code size in bytes GitHub issues GitHub Release Discord Twitter

This is a generated OpenAPI client for the OpenSauced API which uses the Swagger doc for the defined API. It can be used as a canonical and versioned source to interface with the OpenSauced API using Go.

πŸ”§ Versioning

The version of the client corresponds directly withe the version of the API. See the OpenSauced API release notes for breaking changes, new features, etc.

πŸ—οΈ Usage

Add the client as a dependency in your project:

go get github.com/open-sauced/go-api/client

Here's a sample Go program that uses the client to get all pull requests

package main

import (
        "context"
        "fmt"
        "os"

        client "github.com/open-sauced/go-api/client"
)

func main() {
    configuration := client.NewConfiguration()
    apiClient := client.NewAPIClient(configuration)

    // The prod server is at index 1
    ctx := context.WithValue(context.Background(), client.ContextServerIndex, 1)

    resp, r, err := apiClient.PullRequestsServiceAPI.ListAllPullRequests(ctx).Execute()
    if err != nil {
        fmt.Fprintf(os.Stderr, "Error when calling `PullRequestsServiceAPI.ListAllPullRequests``: %v\n", err)
        fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
    }

    fmt.Printf("Responses: %v", resp)
}

Explore the generated docs within client/docs and generated/README.md to learn more about how this client works.

🚜 Generating the client

make generate-client

There are some rough edges when generating the OpenAPI client that you'll want to keep in mind:

  • Duplicate type structs may be defined (especially for endpoints that utilize dependent Dtos)
    • Remove duplicate type structs that don't correspond to the right API endpoint. Always refer to the API's swagger doc for the canonical source of truth.
    • Also remove the corresponding documentation bits.
  • The tests may not have correctly generated struct member func names.
    • Either remove those generated tests or find the correct struct member func and make the correct change.
  • In general, it's a good idea to view the diff and run go test ./... before committing new changes.
  • The "contributions" service, at the time of this writing, is not fully complete. So, it will have missing endpoints and no actual services. Its files can be safely deleted.