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
90 changes: 90 additions & 0 deletions adapter/supabase.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package adapter

import (
"context"
"encoding/json"
"fmt"
"time"

"github.com/patch-it-dev/patch-it-plugins/fetch"
)

// Variables, not constants, only so tests can point them at a local server.
var (
// supabaseCommitsURL lists the commits that changed the Management API
// spec in supabase/supabase, newest first; with per_page=1, the newest.
supabaseCommitsURL = "https://api.github.com/repos/supabase/supabase/commits?path=apps/docs/spec/api_v1_openapi.json&per_page=1"
// supabaseCommitURL is one commit, for its date.
supabaseCommitURL = "https://api.github.com/repos/supabase/supabase/commits/%s"
// supabaseSpecURLTemplate is the Management API spec (api.supabase.com)
// at one commit. Supabase serves it live at
// https://api.supabase.com/api/v1-json, which has no versions; the docs
// copy in supabase/supabase is the same spec, committed when it changes
// (90 commits from 2024-05-31 to 2026-11-18), and a commit never changes.
supabaseSpecURLTemplate = "https://raw.githubusercontent.com/supabase/supabase/%s/apps/docs/spec/api_v1_openapi.json"
)

// Supabase adapts the Supabase Management API spec in supabase/supabase for
// the openapi plugin. The repo tags no spec releases, so a tag here is the
// commit that last changed the spec.
type Supabase struct{}

var _ Adapter = Supabase{}

func (Supabase) API() string { return "supabase" }

// LatestTag is the SHA of the newest commit that changed the spec.
func (Supabase) LatestTag(ctx context.Context) (string, error) {
body, err := fetch.Get(ctx, supabaseCommitsURL, githubHeaders())
if err != nil {
return "", fmt.Errorf("looking up supabase's latest spec commit: %w", err)
}
var commits []struct {
SHA string `json:"sha"`
}
if err := json.Unmarshal(body, &commits); err != nil {
return "", fmt.Errorf("parsing github commits response: %w", err)
}
if len(commits) == 0 || commits[0].SHA == "" {
return "", fmt.Errorf("github lists no commit that changed the supabase spec")
}
return commits[0].SHA, nil
}

// Fetch downloads the spec at commit sha.
//
// Version is the commit's date (YYYY-MM-DD): the Management API has no
// version of its own (`/v1`, info.version a fixed "1.0.0", checked
// 2026-11-19), so the date the spec changed is the closest thing to "the API
// version the change arrived in".
func (Supabase) Fetch(ctx context.Context, sha string) (Spec, error) {
meta, err := fetch.Get(ctx, fmt.Sprintf(supabaseCommitURL, sha), githubHeaders())
if err != nil {
return Spec{}, fmt.Errorf("looking up supabase spec commit %s: %w", sha, err)
}
var commit struct {
SHA string `json:"sha"`
Commit struct {
Committer struct {
Date time.Time `json:"date"`
} `json:"committer"`
} `json:"commit"`
}
if err := json.Unmarshal(meta, &commit); err != nil {
return Spec{}, fmt.Errorf("parsing github commit %s: %w", sha, err)
}
if commit.SHA == "" || commit.Commit.Committer.Date.IsZero() {
return Spec{}, fmt.Errorf("github commit %s has no sha or date", sha)
}
// Pin to the full SHA even when given a short one: the citation must
// name exactly one document.
url := fmt.Sprintf(supabaseSpecURLTemplate, commit.SHA)
body, err := fetch.Get(ctx, url, nil) // raw.githubusercontent.com needs no auth
if err != nil {
return Spec{}, fmt.Errorf("fetching supabase spec %s: %w", sha, err)
}
if !json.Valid(body) {
return Spec{}, fmt.Errorf("supabase spec %s is not valid json", sha)
}
return Spec{Content: body, Version: commit.Commit.Committer.Date.UTC().Format("2006-01-02"), SourceURL: url}, nil
}
90 changes: 90 additions & 0 deletions adapter/supabase_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package adapter

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

// fakeSupabaseGitHub serves the commits list, one commit, and specs by path.
func fakeSupabaseGitHub(t *testing.T, commitsJSON string, commits, specs map[string]string) *httptest.Server {
t.Helper()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch {
case r.URL.Path == "/commits":
w.Write([]byte(commitsJSON))
case strings.HasPrefix(r.URL.Path, "/commits/"):
body, ok := commits[strings.TrimPrefix(r.URL.Path, "/commits/")]
if !ok {
http.Error(w, `{"message":"No commit found"}`, http.StatusUnprocessableEntity)
return
}
w.Write([]byte(body))
default:
body, ok := specs[r.URL.Path]
if !ok {
http.NotFound(w, r)
return
}
w.Write([]byte(body))
}
}))
t.Cleanup(srv.Close)
oldList, oldOne, oldSpec := supabaseCommitsURL, supabaseCommitURL, supabaseSpecURLTemplate
supabaseCommitsURL = srv.URL + "/commits"
supabaseCommitURL = srv.URL + "/commits/%s"
supabaseSpecURLTemplate = srv.URL + "/%s/spec.json"
t.Cleanup(func() { supabaseCommitsURL, supabaseCommitURL, supabaseSpecURLTemplate = oldList, oldOne, oldSpec })
return srv
}

const fullSHA = "eb21ae25f7954ea1e5db34209ff69fce597b0ae3"

func TestSupabaseLatestTagIsTheNewestSpecCommit(t *testing.T) {
fakeSupabaseGitHub(t, `[{"sha":"`+fullSHA+`"},{"sha":"older"}]`, nil, nil)
tag, err := Supabase{}.LatestTag(context.Background())
if err != nil || tag != fullSHA {
t.Errorf("got %q, %v; want %s", tag, err, fullSHA)
}
}

func TestSupabaseLatestTagRejectsNoCommit(t *testing.T) {
fakeSupabaseGitHub(t, `[]`, nil, nil)
if _, err := (Supabase{}).LatestTag(context.Background()); err == nil {
t.Error("no commit: want an error")
}
}

// The version is the commit's date, since the Management API has none (its
// info.version is a fixed 1.0.0); the source is pinned to the full SHA even
// when a short one is asked for, and the content is passed through.
func TestSupabaseFetchPinsTheFullSHAAndDatesByCommit(t *testing.T) {
const body = `{"openapi":"3.0.0","info":{"version":"1.0.0"},"paths":{}}`
srv := fakeSupabaseGitHub(t, "", map[string]string{
"eb21ae25": `{"sha":"` + fullSHA + `","commit":{"committer":{"date":"2026-06-29T08:15:50Z"}}}`,
}, map[string]string{"/" + fullSHA + "/spec.json": body})
spec, err := Supabase{}.Fetch(context.Background(), "eb21ae25")
if err != nil {
t.Fatal(err)
}
if spec.Version != "2026-06-29" || spec.SourceURL != srv.URL+"/"+fullSHA+"/spec.json" || string(spec.Content) != body {
t.Errorf("got version %q, url %s, content %s", spec.Version, spec.SourceURL, spec.Content)
}
}

func TestSupabaseFetchFailures(t *testing.T) {
commit := `{"sha":"` + fullSHA + `","commit":{"committer":{"date":"2026-06-29T08:15:50Z"}}}`
for name, c := range map[string]struct{ commits, specs map[string]string }{
"unknown commit": {nil, nil},
"commit without date": {map[string]string{"x": `{"sha":"` + fullSHA + `"}`}, nil},
"spec missing": {map[string]string{"x": commit}, nil},
"invalid json": {map[string]string{"x": commit}, map[string]string{"/" + fullSHA + "/spec.json": "<html>"}},
} {
fakeSupabaseGitHub(t, "", c.commits, c.specs)
if _, err := (Supabase{}).Fetch(context.Background(), "x"); err == nil {
t.Errorf("%s: want an error", name)
}
}
}
15 changes: 13 additions & 2 deletions diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ type Options struct {
// deprecated, for a spec that often says so in words and not in the
// `deprecated` flag. Nil reads only the flag.
DeprecatedSummary func(summary string) bool

// QuoteDeprecatedOperation makes a deprecation by the flag cite the whole
// operation, not the bare `true`: for a spec that says why in the
// operation's description ("This endpoint is deprecated - use the deploy
// endpoint"). The excerpt is the operation serialized with sorted keys, so
// `deprecated` comes before `description` and survives the 2,000-character
// cut (only a `callbacks` key would sort ahead of it).
QuoteDeprecatedOperation bool
}

// OperationDeprecated reports whether an operation object is marked
Expand Down Expand Up @@ -281,9 +289,12 @@ func (d *differ) paths(oldPaths, newPaths map[string]any) {
d.add(w, OperationRemoved, "", true, oldOp)
default:
if !d.opts.OperationDeprecated(oldOp) && d.opts.OperationDeprecated(newOp) {
if truthy(newOp["deprecated"]) {
switch {
case truthy(newOp["deprecated"]) && d.opts.QuoteDeprecatedOperation:
d.add(w, OperationDeprecated, "", false, newOp)
case truthy(newOp["deprecated"]):
d.add(w.child("deprecated"), OperationDeprecated, "", false, newOp["deprecated"])
} else {
default:
// Said in words: the summary is the evidence.
d.add(w.child("summary"), OperationDeprecated, "", false, newOp["summary"])
}
Expand Down
16 changes: 16 additions & 0 deletions diff/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,19 @@ func TestPathTemplatesAmbiguousFallsBackToExactPaths(t *testing.T) {
t.Errorf("got %v, want GET /d/{name} removed", got)
}
}

// With QuoteDeprecatedOperation, a deprecation by the flag cites the whole
// operation, where the vendor says why; without, the bare `true`.
func TestQuoteDeprecatedOperation(t *testing.T) {
oldSpec := mustParse(t, pathsSpec(`"/f":{"post":{"description":"Creates a function."}}`))
newSpec := mustParse(t, pathsSpec(`"/f":{"post":{"deprecated":true,"description":"This endpoint is deprecated - use the deploy endpoint."}}`))
got := ChangesWith(oldSpec, newSpec, Options{QuoteDeprecatedOperation: true})
op, _ := got[0].Node.(map[string]any)
if len(got) != 1 || got[0].Kind != OperationDeprecated || got[0].Pointer != "/paths/~1f/post" || op["description"] != "This endpoint is deprecated - use the deploy endpoint." {
t.Errorf("got %+v, want one operation_deprecated citing the operation", got)
}
got = Changes(oldSpec, newSpec)
if len(got) != 1 || got[0].Pointer != "/paths/~1f/post/deprecated" || got[0].Node != true {
t.Errorf("without the option: %+v, want the flag cited", got)
}
}
1 change: 1 addition & 0 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The table between the `plugins:start` and `plugins:end` markers is also publishe
| [`github`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/github.md) | GitHub | REST API changes between dated API versions | `openapi` | [github/rest-api-description](https://github.com/github/rest-api-description) | live |
| [`gitlab`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/gitlab.md) | GitLab | REST API changes between releases, request side only (what callers send) | `openapi` | [gitlab-org/gitlab `doc/api/openapi`](https://gitlab.com/gitlab-org/gitlab/-/tree/master/doc/api/openapi) | live |
| [`vercel`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/vercel.md) | Vercel | REST API operations deprecated, and deprecated operations removed, between SDK releases of the spec | `openapi` | [vercel/sdk](https://github.com/vercel/sdk) (`vercel-spec.json`) | paused: merged, not in a tagged release yet, so patch-it's hosted ingestion service doesn't run it |
| [`supabase`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/supabase.md) | Supabase | Management API operations deprecated, and deprecated operations removed, between commits of the spec | `openapi` | [supabase/supabase](https://github.com/supabase/supabase) (`apps/docs/spec/api_v1_openapi.json`) | paused: merged, not in a tagged release yet, so patch-it's hosted ingestion service doesn't run it |
| [`openai-models`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/openai-models.md) | OpenAI | Model deprecations and shutdown dates (Chat Completions and Responses text models) | `retirements` | [OpenAI deprecations](https://developers.openai.com/api/docs/deprecations) | live |
| [`anthropic-models`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/anthropic-models.md) | Anthropic | Model deprecations and retirement dates (Messages API models) | `retirements` | [Anthropic model deprecations](https://platform.claude.com/docs/en/about-claude/model-deprecations) | live |
| [`anthropic`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/anthropic.md) | Anthropic | Parameters removed from `messages.create()` and friends in the Python SDK 1.0 | `migrationguide` | [anthropic-sdk-python MIGRATION.md](https://github.com/anthropics/anthropic-sdk-python/blob/v1.0.0/MIGRATION.md) | live |
Expand Down
5 changes: 4 additions & 1 deletion plugins/openapi/openapi.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package openapi is the source plugin for an API that publishes an OpenAPI
// spec per release (Stripe, Datadog, GitLab, GitHub, Vercel): fetch the newest spec,
// spec per release (Stripe, Datadog, GitLab, GitHub, Vercel, Supabase): fetch the newest spec,
// diff it against the last one seen, normalize the changes into events, and
// attach migration hints from the API's changelog when it has one. It can also
// replay two given releases.
Expand Down Expand Up @@ -33,6 +33,9 @@ func init() {
// No Hints: Vercel's changelog is product news, not keyed by API change.
// Only operation deprecations and removals are kept: see vercelKeep.
plugin.Register(Plugin{Adapter: adapter.Vercel{}, Diff: vercelDiff, Keep: vercelKeep})
// No Hints: Supabase's changelog is platform news, not keyed by
// operation. Only operation deprecations and removals: see supabase.go.
plugin.Register(Plugin{Adapter: adapter.Supabase{}, Diff: supabaseDiff, Keep: supabaseKeep})
}

// requestSide keeps the changes to what callers send. GitLab's response
Expand Down
2 changes: 1 addition & 1 deletion plugins/openapi/registered_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestRegistersItself(t *testing.T) {
for _, a := range []adapter.Adapter{adapter.Stripe{}, adapter.Datadog{}, adapter.GitLab{}, adapter.GitHub{}, adapter.Vercel{}} {
for _, a := range []adapter.Adapter{adapter.Stripe{}, adapter.Datadog{}, adapter.GitLab{}, adapter.GitHub{}, adapter.Vercel{}, adapter.Supabase{}} {
kittest.Registered(t, Plugin{Adapter: a})
}
}
28 changes: 28 additions & 0 deletions plugins/openapi/supabase.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package openapi

import "github.com/patch-it-dev/patch-it-plugins/diff"

// supabaseDiff is how the Supabase Management API spec says what it says:
//
// - Deprecations use the `deprecated` flag, and the description sometimes
// says why ("This endpoint is deprecated - use the deploy endpoint."), so
// the event quotes the whole operation, not the bare `true`.
// - Path parameters get renamed, and that isn't a change for callers:
// /v1/branches/{branch_id}/merge became .../{branch_id_or_ref}/merge on
// 2025-09-11.
var supabaseDiff = diff.Options{PathTemplates: true, QuoteDeprecatedOperation: true}

// supabaseKeep keeps operation deprecations, and removals of operations the
// old spec had marked deprecated. In the spec's history (90 commits,
// 2024-05-31 to 2026-11-18) that's 2 events: POST /v1/projects/{ref}/functions
// deprecated on 2025-02-19, GET /v1/projects/{ref}/analytics/endpoints/logs.all
// on 2026-06-29. Everything else is dropped:
//
// - 22 operations left the spec, none of them deprecated first: 14
// analytics warehouse operations on 2024-07-15, 7 path-parameter renames
// (which PathTemplates pairs up anyway), and one that came back 12
// days later. Without credentials every route answers 401, so whether a
// removed one still works can't be checked from outside.
// - Request and response property changes, new operations: not changes a
// caller has to fix, or not ones the spec's history shows reliably.
var supabaseKeep = deprecationsOnly(supabaseDiff)
Loading
Loading