Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Changelog

## [Unreleased](https://github.com/openfga/go-sdk/compare/v0.7.3...HEAD)

- feat: add a generic API Executor `fgaClient.GetAPIExecutor()` to allow calling any OpenFGA API method. See [Calling Other Endpoints](./README.md#calling-other-endpoints) for more.
- feat: add generic `ToPtr[T any](v T) *T` function for creating pointers to any type
- deprecation: `PtrBool`, `PtrInt`, `PtrInt32`, `PtrInt64`, `PtrFloat32`, `PtrFloat64`, `PtrString`, and `PtrTime` are now deprecated in favor of the generic `ToPtr` function
- feat: add a top-level makefile in go-sdk to simplify running tests and linters: (#250)
- feat: add support for StreamedListObjects endpoint (#252)
- chore: add a top-level makefile in go-sdk to simplify running tests and linters: (#250)

## v0.7.3

### [0.7.3](https://github.com/openfga/go-sdk/compare/v0.7.2...v0.7.3) (2025-10-08)
Expand Down
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ This is an autogenerated Go SDK for OpenFGA. It provides a wrapper around the [O
- [Assertions](#assertions)
- [Read Assertions](#read-assertions)
- [Write Assertions](#write-assertions)
- [Calling other endpoints](#calling-other-endpoints)
- [Retries](#retries)
- [API Endpoints](#api-endpoints)
- [Models](#models)
Expand Down Expand Up @@ -1046,7 +1047,89 @@ data, err := fgaClient.WriteAssertions(context.Background()).
Execute()
```

### Calling Other Endpoints

In certain cases you may want to call other APIs not yet wrapped by the SDK. You can do so by using the `APIExecutor` available from the `fgaClient`.
The `APIExecutor` allows you to make raw HTTP calls to any OpenFGA endpoint by specifying the operation name, HTTP method, path, parameters, body, and headers, while still honoring the client configuration (authentication, telemetry, retries, and error handling).

This is useful when:

- you want to call a new endpoint that is not yet supported by the SDK
- you are using an earlier version of the SDK that doesn't yet support a particular endpoint
- you have a custom endpoint deployed that extends the OpenFGA API

In all cases, you initialize the SDK the same way as usual, and then get the `APIExecutor` from the `fgaClient` instance.

```go
// Initialize the client, same as above
fgaClient, err := NewSdkClient(&ClientConfiguration{...})

// Get the generic API executor
executor := fgaClient.GetAPIExecutor()

// Custom new endpoint that doesn't exist in the SDK yet
requestBody := map[string]interface{}{
"user": "user:bob",
"action": "custom_action",
"resource": "resource:123",
}

// Build the request
request := openfga.NewAPIExecutorRequestBuilder("CustomEndpoint", http.MethodPost, "/stores/{store_id}/custom-endpoint").
WithPathParameter("store_id", storeID).
WithQueryParameter("page_size", "20").
WithQueryParameter("continuation_token", "eyJwayI6...").
WithBody(requestBody).
WithHeader("X-Experimental-Feature", "enabled").
Build()
```

#### Example: Calling a new "Custom Endpoint" endpoint and handling raw response

```go
// Get raw response without automatic decoding
rawResponse, err := executor.Execute(ctx, request)

if err != nil {
log.Fatalf("Custom endpoint failed: %v", err)
}

// Manually decode the response
var result map[string]interface{}
if err := json.Unmarshal(rawResponse.Body, &result); err != nil {
log.Fatalf("Failed to decode: %v", err)
}

fmt.Printf("Response: %+v\n", result)

// You can access fields like headers, status code, etc. from rawResponse:
fmt.Printf("Status Code: %d\n", rawResponse.StatusCode)
fmt.Printf("Headers: %+v\n", rawResponse.Headers)
```

#### Example: Calling a new "Custom Endpoint" endpoint and decoding response into a struct

```go
// Define a struct to hold the response
type CustomEndpointResponse struct {
Allowed bool `json:"allowed"`
Reason string `json:"reason"`
}
var customEndpointResponse CustomEndpointResponse

// Get raw response decoded into CustomEndpointResponse struct
rawResponse, err := executor.ExecuteWithDecode(ctx, request, &customEndpointResponse) // Pass pointer to struct for decoding

if err != nil {
log.Fatalf("Custom endpoint failed: %v", err)
}

fmt.Printf("Response: %+v\n", customEndpointResponse)

// You can access fields like headers, status code, etc. from rawResponse:
fmt.Printf("Status Code: %d\n", rawResponse.StatusCode)
fmt.Printf("Headers: %+v\n", rawResponse.Headers)
```

### Retries

Expand Down
6 changes: 6 additions & 0 deletions api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ func (c *APIClient) GetConfig() *Configuration {
return c.cfg
}

// GetAPIExecutor returns an APIExecutor that can be used to call any OpenFGA API endpoint
// This is useful for calling endpoints that are not yet supported by the SDK
func (c *APIClient) GetAPIExecutor() APIExecutor {
return NewAPIExecutor(c)
}

// prepareRequest build the request
func (c *APIClient) prepareRequest(
ctx context.Context,
Expand Down
Loading
Loading