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
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ Fizzy uses **two auth strategies** (no OAuth):

## API Surface Inventory

111 operations across the current Smithy-defined API surface:
112 operations across the current Smithy-defined API surface:

| Area | Operations |
|---------|-----------|
| Identity | GetMyIdentity |
| Identity | GetMyIdentity, UpdateMyTimezone |
| Access Tokens | ListAccessTokens, CreateAccessToken, DeleteAccessToken |
| Account | GetAccountSettings, UpdateAccountSettings, GetJoinCode, UpdateJoinCode, ResetJoinCode, UpdateAccountEntropy, CreateAccountExport, GetAccountExport |
| Boards | ListBoards, CreateBoard, GetBoard, ListBoardAccesses, UpdateBoard, DeleteBoard, PublishBoard, UnpublishBoard, UpdateBoardInvolvement, UpdateBoardEntropy, ListStreamCards, ListPostponedCards, ListClosedCards |
Expand Down
13 changes: 13 additions & 0 deletions behavior-model.json
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,19 @@
]
}
},
"UpdateMyTimezone": {
"idempotent": true,
"retry": {
"max": 3,
"base_delay_ms": 1000,
"backoff": "exponential",
"retry_on": [
429,
500,
503
]
}
},
"UpdateNotificationSettings": {
"idempotent": true,
"retry": {
Expand Down
6 changes: 4 additions & 2 deletions conformance/runner/ruby/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def dispatch_operation(tc, client)

# Pins
when "ListPins"
client.pins.list
client.pins.list(account_id: account_id)

# Uploads
when "CreateDirectUpload"
Expand Down Expand Up @@ -344,9 +344,11 @@ def dispatch_operation(tc, client)
when "CompleteJoin"
client.sessions.complete_join(**symbolize_body(body))

# Identity (account-independent)
# Identity
when "GetMyIdentity"
client.identity.me
when "UpdateMyTimezone"
client.identity.update_timezone(account_id: account_id, **symbolize_body(body))

# Devices
when "RegisterDevice"
Expand Down
3 changes: 3 additions & 0 deletions conformance/runner/typescript/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ async function dispatch(
case "GetMyIdentity":
data = await (client as any).identity.me();
break;
case "UpdateMyTimezone":
data = await (client as any).identity.updateTimezone({ timezoneName: body.timezone_name });
break;

// Notifications
case "ListNotifications": {
Expand Down
27 changes: 24 additions & 3 deletions conformance/tests/paths.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,11 @@
"tags": ["paths"]
},
{
"name": "ListPins has no account prefix",
"name": "ListPins uses account-scoped my path",
"operation": "ListPins",
"method": "GET",
"path": "/my/pins.json",
"path": "/{accountId}/my/pins.json",
"pathParams": { "accountId": "999" },
"mockResponses": [
{
"status": 200,
Expand All @@ -223,7 +224,27 @@
}
],
"assertions": [
{ "type": "requestPath", "expected": "/my/pins.json" },
{ "type": "requestPath", "expected": "/999/my/pins.json" },
{ "type": "noError" }
],
"tags": ["paths"]
},
{
"name": "UpdateMyTimezone uses account-scoped my path",
"operation": "UpdateMyTimezone",
"method": "PATCH",
"path": "/{accountId}/my/timezone.json",
"pathParams": { "accountId": "999" },
"requestBody": { "timezone_name": "America/New_York" },
"mockResponses": [
{
"status": 204,
"headers": {},
"body": null
}
],
"assertions": [
{ "type": "requestPath", "expected": "/999/my/timezone.json" },
{ "type": "noError" }
],
"tags": ["paths"]
Expand Down
20 changes: 20 additions & 0 deletions conformance/tests/request-shapes.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@
],
"tags": ["request-shapes"]
},
{
"name": "UpdateMyTimezone sends timezone_name field",
"operation": "UpdateMyTimezone",
"method": "PATCH",
"path": "/{accountId}/my/timezone.json",
"pathParams": { "accountId": "999" },
"requestBody": { "timezone_name": "America/New_York" },
"mockResponses": [
{
"status": 204,
"headers": {},
"body": null
}
],
"assertions": [
{ "type": "requestBodyField", "expected": "timezone_name" },
{ "type": "noError" }
],
"tags": ["request-shapes"]
},
{
"name": "CreateCardReaction sends content field",
"operation": "CreateCardReaction",
Expand Down
2 changes: 2 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
55 changes: 47 additions & 8 deletions go/cmd/generate-services/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package main
import (
"encoding/json"
"fmt"
"go/format"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -145,6 +146,7 @@ func responseTypeName(refName string, schemas map[string]json.RawMessage) (goTyp
// whose service cannot be derived from suffix matching.
var operationServiceOverrides = map[string]string{
"GetMyIdentity": "Identity",
"UpdateMyTimezone": "Identity",
"CreateDirectUpload": "Uploads",
"RedeemMagicLink": "Sessions",
"CompleteJoin": "Sessions",
Expand Down Expand Up @@ -360,6 +362,12 @@ func deriveMethodName(opID, serviceName string) string {
return opID
}

// routeRenderedPathOperations identifies operations whose request paths are
// rendered from the generated route table instead of an inline path template.
var routeRenderedPathOperations = map[string]bool{
"UpdateMyTimezone": true,
}

// ---------------------------------------------------------------------------
// Client type determination
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -514,7 +522,7 @@ func generateServiceFile(svc ServiceDef) string {
if isAccountScoped(svc.Name) {
path = stripAccountPrefix(path)
}
if strings.Contains(path, "{") {
if strings.Contains(path, "{") && !routeRenderedPathOperations[op.OperationID] {
needsFmt = true
}
// Query params need fmt for Sprintf
Expand Down Expand Up @@ -659,7 +667,7 @@ func generateMethod(serviceName string, op ParsedOp) string {
if isPaginatedList {
buf.WriteString(generatePaginatedListBody(op, fmtStr, goParams))
} else {
buf.WriteString(generateMethodBody(op, fmtStr, hasFormatParams, goParams, returnsData))
buf.WriteString(generateMethodBody(op, fmtStr, hasFormatParams, pathParamNames, goParams, returnsData))
}

buf.WriteString("}\n")
Expand Down Expand Up @@ -720,8 +728,8 @@ func generateDocComment(methodName, serviceName string, op ParsedOp) string {
case strings.HasPrefix(methodName, "List"):
comment = fmt.Sprintf("// %s %s %s.", methodName, action, smartPlural(resource, serviceName, op))
default:
// For uncountable nouns (like "settings"), skip the article
if isUncountable(resource, serviceName) {
// For uncountable nouns and possessive resources, skip the article.
if isUncountable(resource, serviceName) || strings.HasPrefix(resource, "my ") {
comment = fmt.Sprintf("// %s %s %s.", methodName, action, resource)
} else {
comment = fmt.Sprintf("// %s %s %s %s.", methodName, action, article, resource)
Expand Down Expand Up @@ -797,14 +805,37 @@ func queryParamsNeedURLEscape(queryParams []QueryParam) bool {
return false
}

func generateMethodBody(op ParsedOp, fmtStr string, hasFormatParams bool, goParams []string, returnsData bool) string {
func routeParamsLiteral(pathParamNames []string, goParams []string) string {
if len(pathParamNames) == 0 {
return "nil"
}
pairs := make([]string, len(pathParamNames))
for i, name := range pathParamNames {
pairs[i] = fmt.Sprintf("%q: %s", name, goParams[i])
}
return "map[string]string{" + strings.Join(pairs, ", ") + "}"
}

func routeErrorReturn(op ParsedOp, returnsData bool) string {
errExpr := fmt.Sprintf("ErrUsage(%q)", "missing generated route for "+op.OperationID)
if returnsData {
return "return nil, nil, " + errExpr
}
return "return nil, " + errExpr
}

func generateMethodBody(op ParsedOp, fmtStr string, hasFormatParams bool, pathParamNames []string, goParams []string, returnsData bool) string {
var buf strings.Builder

hasQueryParams := len(op.QueryParams) > 0

// Build path expression
var pathExpr string
if hasQueryParams {
if routeRenderedPathOperations[op.OperationID] {
fmt.Fprintf(&buf, "\tpath, ok := URLPathByOperation(%q, %s)\n", op.OperationID, routeParamsLiteral(pathParamNames, goParams))
fmt.Fprintf(&buf, "\tif !ok {\n\t\t%s\n\t}\n", routeErrorReturn(op, returnsData))
pathExpr = "path"
} else if hasQueryParams {
// When query params exist, we need a mutable path variable
if hasFormatParams {
args := make([]string, len(goParams))
Expand Down Expand Up @@ -1071,7 +1102,7 @@ func main() {
filename := toSnakeCase(name) + "_service.go"
outPath := filepath.Join(outputDir, filename)

if err := os.WriteFile(outPath, []byte(code), 0600); err != nil {
if err := writeGoFile(outPath, code); err != nil {
log.Fatalf("writing %s: %v", outPath, err)
}
fmt.Printf("Generated %s (%d operations)\n", filename, len(svc.Operations))
Expand All @@ -1081,14 +1112,22 @@ func main() {
// Generate operations registry
registryCode := generateOperationsRegistry(services)
registryPath := filepath.Join(outputDir, "operations_registry.go")
if err := os.WriteFile(registryPath, []byte(registryCode), 0600); err != nil {
if err := writeGoFile(registryPath, registryCode); err != nil {
log.Fatalf("writing operations_registry.go: %v", err)
}
fmt.Printf("Generated operations_registry.go (%d operations)\n", totalOps)

fmt.Printf("\nGenerated %d services with %d operations total.\n", len(services), totalOps)
}

func writeGoFile(path string, code string) error {
formatted, err := format.Source([]byte(code))
if err != nil {
return err
}
return os.WriteFile(path, formatted, 0600)
}

// isSimplePlural returns true if the remainder is the service resource
// singular or plural (e.g. "Card" for "Cards", "Comments" for "Comments").
func isSimplePlural(remainder, serviceName string) bool {
Expand Down
4 changes: 2 additions & 2 deletions go/pkg/fizzy/api-provenance.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"fizzy": {
"repo": "basecamp/fizzy",
"revision": "abd59567e38335fb73da47415d6b7fe68ef48f9c",
"date": "2026-04-14",
"revision": "08395fab0e85da88f40702f8fafe556a55af73b3",
"date": "2026-06-01",
"branch": "main",
"paths": {
"api_docs_index": "docs/api/README.md",
Expand Down
10 changes: 10 additions & 0 deletions go/pkg/fizzy/identity_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions go/pkg/fizzy/identity_service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package fizzy

import (
"context"
"net/http"
"net/http/httptest"
"testing"

"github.com/basecamp/fizzy-sdk/go/pkg/generated"
)

func TestIdentityUpdateTimezone(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPatch {
t.Fatalf("method = %s, want PATCH", r.Method)
}
if r.URL.Path != "/999/my/timezone.json" {
t.Fatalf("path = %s, want /999/my/timezone.json", r.URL.Path)
}
w.WriteHeader(http.StatusNoContent)
}))
defer server.Close()

client := NewClient(&Config{BaseURL: server.URL}, &StaticTokenProvider{Token: "test"})
_, err := client.Identity().UpdateMyTimezone(context.Background(), "999", &generated.UpdateMyTimezoneRequest{TimezoneName: "America/New_York"})
if err != nil {
t.Fatalf("UpdateMyTimezone: %v", err)
}
}

func TestPinsListUsesAccountScopedPath(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
t.Fatalf("method = %s, want GET", r.Method)
}
if r.URL.Path != "/999/my/pins.json" {
t.Fatalf("path = %s, want /999/my/pins.json", r.URL.Path)
}
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`[]`))
}))
defer server.Close()

client := NewClient(&Config{BaseURL: server.URL}, &StaticTokenProvider{Token: "test"})
_, _, err := client.ForAccount("999").Pins().List(context.Background())
if err != nil {
t.Fatalf("ListPins: %v", err)
}
}
3 changes: 2 additions & 1 deletion go/pkg/fizzy/operations_registry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading