This repository contains the auto-generated Go client for the Cloud Foundry CAPI (Cloud Controller API) v3.
This client is generated from CAPI version 3.195.0.
go get github.com/cloudfoundry-community/capi-openapi-go-client/v3@v3.195.1
Or add this to your go.mod
file:
require github.com/cloudfoundry-community/capi-openapi-go-client/v3 v3.195.1
This module uses Go's versioned module structure:
- Module path:
github.com/cloudfoundry-community/capi-openapi-go-client/v3
- Package:
capiclient
(located in thecapiclient/
subdirectory)
package main
import (
"context"
"fmt"
"net/http"
"github.com/cloudfoundry-community/capi-openapi-go-client/v3/capiclient"
)
func main() {
// Create a new client
client, err := capiclient.NewClientWithResponses("https://api.example.com")
if err != nil {
panic(err)
}
// Use the client to interact with CAPI
ctx := context.Background()
// Example: List organizations
resp, err := client.V3OrganizationsGetWithResponse(ctx, &capiclient.V3OrganizationsGetParams{})
if err != nil {
panic(err)
}
if resp.StatusCode() == http.StatusOK {
fmt.Printf("Found %d organizations\n", len(*resp.JSON200.Resources))
}
}
The client supports various authentication methods. Here's an example using Bearer token authentication:
import (
"context"
"net/http"
)
// Create a custom HTTP client with authentication
httpClient := &http.Client{
Transport: &authTransport{
Token: "your-bearer-token",
Base: http.DefaultTransport,
},
}
// Use the custom HTTP client
client, err := capiclient.NewClientWithResponses(
"https://api.example.com",
capiclient.WithHTTPClient(httpClient),
)
Where authTransport
is a custom RoundTripper that adds the Authorization header:
type authTransport struct {
Token string
Base http.RoundTripper
}
func (t *authTransport) RoundTrip(req *http.Request) (*http.Response, error) {
req.Header.Set("Authorization", "Bearer "+t.Token)
return t.Base.RoundTrip(req)
}
- CAPI Documentation
- OpenAPI Specification Source
- For detailed API documentation, see the generated code in the capiclient directory
This repository includes a validation test to ensure the module can be properly imported by other Go projects:
# Validate that the module can be imported
make validate
# Test with local changes (before pushing)
make test-local
.
├── capiclient/ # The actual capiclient package
│ └── client.go # Generated client code
├── tests/ # Import validation tests
│ └── import-test/ # Test module that imports capiclient
├── go.mod # Module definition for v3
├── Makefile # Build and validation commands
└── README.md # This file
The validation process ensures:
- The module structure is correct for Go's versioned modules
- The package can be imported using the expected import path
- The types and functions are accessible to importing code
This is particularly important for v2+ Go modules which require specific directory structures.
This client is automatically generated from the OpenAPI specification using oapi-codegen.
To regenerate this client:
- Clone capi-openapi-spec
- Run
make gen-go-client VERSION=3.195.0
- Run
./bin/publish --version=3.195.0
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Contributions are welcome! This client is auto-generated from the Cloud Foundry OpenAPI specification. To update the client:
- Update the OpenAPI specification in the capi-openapi-spec repository
- Regenerate the client using the generation process described above
- Validate the changes using
make test-local
- Submit a pull request with your changes
When creating a new release:
- Ensure all changes are committed and pushed
- Run
make validate
to ensure the module works correctly - Tag the release with the appropriate version (e.g.,
v3.196.0
) - Push the tag to GitHub
- The Go module proxy will automatically pick up the new version
If you encounter import errors like "module found but does not contain package":
- Ensure you're using the correct import path:
github.com/cloudfoundry-community/capi-openapi-go-client/v3/capiclient
- Check that your Go version supports modules (Go 1.11+)
- Try clearing your module cache:
go clean -modcache
- Ensure you're using the latest version of the module
For v2+ modules in Go:
- The module path must include the major version suffix (e.g.,
/v3
) - The actual code must be properly organized (package in subdirectory)
- Tags must match the module version (e.g.,
v3.195.1
)
For issues and questions, please open an issue in the GitHub repository.