Repository navigation
openapi: openai/api, cloudflare/api-spec, mongodb/atlas-admin-spec; one version per day #241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| package adapter | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "github.com/patch-it-dev/patch-it-plugins/core/fetch" | ||
| "github.com/patch-it-dev/patch-it-plugins/core/github" | ||
| "github.com/patch-it-dev/patch-it-plugins/core/plugin" | ||
| ) | ||
|
|
||
| // Variables, not constants, only so tests can point them at a local server. | ||
| var ( | ||
| cloudflareRepo = "cloudflare/api-schemas" | ||
| cloudflarePath = "openapi.json" | ||
| // cloudflareCommitsURL lists the commits that changed the spec, newest | ||
| // first; with per_page=1, the newest. | ||
| cloudflareCommitsURL = "https://api.github.com/repos/cloudflare/api-schemas/commits?path=openapi.json&per_page=1" | ||
| // cloudflareCommitURL is one commit, for its date. | ||
| cloudflareCommitURL = "https://api.github.com/repos/cloudflare/api-schemas/commits/%s" | ||
| // cloudflareSpecURLTemplate is the OpenAPI description of the whole | ||
| // Cloudflare API (api.cloudflare.com/client/v4) at one commit of | ||
| // cloudflare/api-schemas (BSD-3-Clause), the spec Cloudflare's SDKs and | ||
| // Terraform provider are generated from. A bot commits it as "Update | ||
| // schema: openapi.json" several times a day and the repo has no tags | ||
| // (checked 2026-11-21), so the commits are the versions. About 30 MB; | ||
| // openapi.yaml beside it is the same spec. | ||
| cloudflareSpecURLTemplate = "https://raw.githubusercontent.com/cloudflare/api-schemas/%s/openapi.json" | ||
| ) | ||
|
|
||
| // Cloudflare adapts the Cloudflare API's spec in cloudflare/api-schemas for | ||
| // the openapi plugin. A tag here is a commit SHA. | ||
| type Cloudflare struct{} | ||
|
|
||
| var _ Adapter = Cloudflare{} | ||
|
|
||
| func (Cloudflare) API() string { return "cloudflare/api-spec" } | ||
|
|
||
| // LatestTag is the SHA of the newest commit that changed the spec. | ||
| func (Cloudflare) LatestTag(ctx context.Context) (string, error) { | ||
| sha, err := github.LatestCommit(ctx, github.Get, cloudflareCommitsURL) | ||
| if err != nil { | ||
| return "", fmt.Errorf("looking up cloudflare's latest spec commit: %w", err) | ||
| } | ||
| return sha, nil | ||
| } | ||
|
|
||
| // Versions are the days the spec changed, each read at that day's last | ||
| // commit (Daily). | ||
| func (Cloudflare) Versions(ctx context.Context) ([]plugin.Version, error) { | ||
| return commits(ctx, cloudflareRepo, cloudflarePath) | ||
| } | ||
|
|
||
| // Fetch downloads the spec at commit sha and moves the server's /client/v4 | ||
| // into the paths: see ServerBasePath. Version is the commit's date | ||
| // (YYYY-MM-DD): info.version is a fixed "4.0.0" (checked 2026-11-21). | ||
| func (Cloudflare) Fetch(ctx context.Context, sha string) (Spec, error) { | ||
| fullSHA, date, err := github.Commit(ctx, github.Get, fmt.Sprintf(cloudflareCommitURL, sha)) | ||
| if err != nil { | ||
| return Spec{}, fmt.Errorf("looking up cloudflare spec commit %s: %w", sha, err) | ||
| } | ||
| if fullSHA == "" { | ||
| return Spec{}, fmt.Errorf("github commit %s has no sha", sha) | ||
| } | ||
| url := fmt.Sprintf(cloudflareSpecURLTemplate, fullSHA) | ||
| body, err := fetch.Get(ctx, url, nil) // raw.githubusercontent.com needs no auth | ||
| if err != nil { | ||
| return Spec{}, fmt.Errorf("fetching cloudflare spec %s: %w", sha, err) | ||
| } | ||
| if !json.Valid(body) { | ||
| return Spec{}, fmt.Errorf("cloudflare spec %s is not valid json", sha) | ||
| } | ||
| // The one server is "https://api.cloudflare.com/client/v4" and the | ||
| // paths don't repeat it: moved, an operation is named by the path a | ||
| // caller sends. | ||
| content, err := ServerBasePath(body) | ||
| if err != nil { | ||
| return Spec{}, fmt.Errorf("cloudflare spec %s: %w", sha, err) | ||
| } | ||
| return Spec{Content: content, Version: date.UTC().Format("2006-01-02"), SourceURL: url}, nil | ||
| } | ||
|
|
||
| // SourcePointer: see BasePathPointer. | ||
| func (Cloudflare) SourcePointer(content []byte) func(string) string { | ||
| return BasePathPointer(content) | ||
| } | ||
|
|
||
| var ( | ||
| _ Reshaper = Cloudflare{} | ||
| _ Lister = Cloudflare{} | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package adapter | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "github.com/patch-it-dev/patch-it-plugins/core/fetch" | ||
| "github.com/patch-it-dev/patch-it-plugins/core/github" | ||
| "github.com/patch-it-dev/patch-it-plugins/core/plugin" | ||
| ) | ||
|
|
||
| // Variables, not constants, only so tests can point them at a local server. | ||
| var ( | ||
| atlasRepo = "mongodb/openapi" | ||
| atlasPath = "openapi/v2.json" | ||
| // atlasCommitsURL lists the commits that changed the spec, newest first; | ||
| // with per_page=1, the newest. | ||
| atlasCommitsURL = "https://api.github.com/repos/mongodb/openapi/commits?path=openapi/v2.json&per_page=1" | ||
| // atlasCommitURL is one commit, for its date. | ||
| atlasCommitURL = "https://api.github.com/repos/mongodb/openapi/commits/%s" | ||
| // atlasSpecURLTemplate is the OpenAPI description of the MongoDB Atlas | ||
| // Administration API v2 at one commit of mongodb/openapi: every | ||
| // operation with every resource version it serves. MongoDB's release | ||
| // workflow commits it ("ci(prod): Release OpenAPI Spec") a few times a | ||
| // week, 768 commits from 2024-07-25 to 2026-11-19 (checked 2026-11-21); | ||
| // the repo's v0.0.N tags mark tooling releases, not the spec. | ||
| atlasSpecURLTemplate = "https://raw.githubusercontent.com/mongodb/openapi/%s/openapi/v2.json" | ||
| ) | ||
|
|
||
| // MongoDBAtlas adapts the Atlas Administration API's spec in mongodb/openapi | ||
| // for the openapi plugin. A tag here is a commit SHA. | ||
| type MongoDBAtlas struct{} | ||
|
|
||
| var _ Adapter = MongoDBAtlas{} | ||
|
|
||
| func (MongoDBAtlas) API() string { return "mongodb/atlas-admin-spec" } | ||
|
|
||
| // LatestTag is the SHA of the newest commit that changed the spec. | ||
| func (MongoDBAtlas) LatestTag(ctx context.Context) (string, error) { | ||
| sha, err := github.LatestCommit(ctx, github.Get, atlasCommitsURL) | ||
| if err != nil { | ||
| return "", fmt.Errorf("looking up mongodb atlas's latest spec commit: %w", err) | ||
| } | ||
| return sha, nil | ||
| } | ||
|
|
||
| // Versions are the days the spec changed, each read at that day's last | ||
| // commit (Daily). | ||
| func (MongoDBAtlas) Versions(ctx context.Context) ([]plugin.Version, error) { | ||
| return commits(ctx, atlasRepo, atlasPath) | ||
| } | ||
|
|
||
| // Fetch downloads the spec at commit sha. Version is the commit's date | ||
| // (YYYY-MM-DD): info.version is a fixed "2.0", and the resource versions | ||
| // (application/vnd.atlas.2025-03-12+json) are per operation, several in one | ||
| // spec. The server is https://cloud.mongodb.com with no path: the paths are | ||
| // already what a caller sends (/api/atlas/v2/...). | ||
| func (MongoDBAtlas) Fetch(ctx context.Context, sha string) (Spec, error) { | ||
| fullSHA, date, err := github.Commit(ctx, github.Get, fmt.Sprintf(atlasCommitURL, sha)) | ||
| if err != nil { | ||
| return Spec{}, fmt.Errorf("looking up mongodb atlas spec commit %s: %w", sha, err) | ||
| } | ||
| if fullSHA == "" { | ||
| return Spec{}, fmt.Errorf("github commit %s has no sha", sha) | ||
| } | ||
| url := fmt.Sprintf(atlasSpecURLTemplate, fullSHA) | ||
| body, err := fetch.Get(ctx, url, nil) // raw.githubusercontent.com needs no auth | ||
| if err != nil { | ||
| return Spec{}, fmt.Errorf("fetching mongodb atlas spec %s: %w", sha, err) | ||
| } | ||
| if !json.Valid(body) { | ||
| return Spec{}, fmt.Errorf("mongodb atlas spec %s is not valid json", sha) | ||
| } | ||
| return Spec{Content: body, Version: date.UTC().Format("2006-01-02"), SourceURL: url}, nil | ||
| } | ||
|
|
||
| var _ Lister = MongoDBAtlas{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package adapter | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "github.com/patch-it-dev/patch-it-plugins/core/fetch" | ||
| "github.com/patch-it-dev/patch-it-plugins/core/github" | ||
| "github.com/patch-it-dev/patch-it-plugins/core/plugin" | ||
| "gopkg.in/yaml.v3" | ||
| ) | ||
|
|
||
| // Variables, not constants, only so tests can point them at a local server. | ||
| var ( | ||
| openaiRepo = "openai/openai-openapi" | ||
| openaiPath = "openapi.yaml" | ||
| // openaiCommitsURL lists the commits that changed the spec, newest | ||
| // first; with per_page=1, the newest. | ||
| openaiCommitsURL = "https://api.github.com/repos/openai/openai-openapi/commits?path=openapi.yaml&per_page=1" | ||
| // openaiCommitURL is one commit, for its date. | ||
| openaiCommitURL = "https://api.github.com/repos/openai/openai-openapi/commits/%s" | ||
| // openaiSpecURLTemplate is the OpenAPI description of the OpenAI API at | ||
| // one commit of openai/openai-openapi (MIT), the spec OpenAI's own SDKs | ||
| // are generated from. The repo commits it several times a day (589 | ||
| // commits that changed openapi.yaml from 2022-01-19 to 2026-11-21, | ||
| // checked 2026-11-21) and tags it seldom (1.3.0, 2.0.0), so the commits | ||
| // are the versions. openapi.json beside it only exists from 2026-07-16: | ||
| // the YAML has the whole history. | ||
| openaiSpecURLTemplate = "https://raw.githubusercontent.com/openai/openai-openapi/%s/openapi.yaml" | ||
| ) | ||
|
|
||
| // OpenAI adapts the OpenAI API's spec in openai/openai-openapi for the | ||
| // openapi plugin. A tag here is a commit SHA. | ||
| type OpenAI struct{} | ||
|
|
||
| var _ Adapter = OpenAI{} | ||
|
|
||
| func (OpenAI) API() string { return "openai/api" } | ||
|
|
||
| // LatestTag is the SHA of the newest commit that changed the spec. | ||
| func (OpenAI) LatestTag(ctx context.Context) (string, error) { | ||
| sha, err := github.LatestCommit(ctx, github.Get, openaiCommitsURL) | ||
| if err != nil { | ||
| return "", fmt.Errorf("looking up openai's latest spec commit: %w", err) | ||
| } | ||
| return sha, nil | ||
| } | ||
|
|
||
| // Versions are the days the spec changed, each read at that day's last | ||
| // commit (Daily): several commits a day is the norm here, and a day is the | ||
| // version a caller can name. | ||
| func (OpenAI) Versions(ctx context.Context) ([]plugin.Version, error) { | ||
| return commits(ctx, openaiRepo, openaiPath) | ||
| } | ||
|
|
||
| // Fetch downloads the spec at commit sha, converts it from YAML to JSON (what | ||
| // diff.Parse reads) and moves the server's /v1 into the paths: see | ||
| // ServerBasePath. Version is the commit's date (YYYY-MM-DD): info.version | ||
| // ("2.3.0") isn't bumped with each change, and the API has no dated versions | ||
| // of its own. | ||
| func (OpenAI) Fetch(ctx context.Context, sha string) (Spec, error) { | ||
| fullSHA, date, err := github.Commit(ctx, github.Get, fmt.Sprintf(openaiCommitURL, sha)) | ||
| if err != nil { | ||
| return Spec{}, fmt.Errorf("looking up openai spec commit %s: %w", sha, err) | ||
| } | ||
| if fullSHA == "" { | ||
| return Spec{}, fmt.Errorf("github commit %s has no sha", sha) | ||
| } | ||
| url := fmt.Sprintf(openaiSpecURLTemplate, fullSHA) | ||
| body, err := fetch.Get(ctx, url, nil) // raw.githubusercontent.com needs no auth | ||
| if err != nil { | ||
| return Spec{}, fmt.Errorf("fetching openai spec %s: %w", sha, err) | ||
| } | ||
| content, err := YAMLToJSON(body) | ||
| if err != nil { | ||
| return Spec{}, fmt.Errorf("openai spec %s: %w", sha, err) | ||
| } | ||
| // The server is "https://api.openai.com/v1" and the paths don't repeat | ||
| // /v1 (checked 2026-11-21): moved, an operation is named by the path a | ||
| // caller sends ("POST /v1/audio/translations"). | ||
| if content, err = ServerBasePath(content); err != nil { | ||
| return Spec{}, fmt.Errorf("openai spec %s: %w", sha, err) | ||
| } | ||
| return Spec{Content: content, Version: date.UTC().Format("2006-01-02"), SourceURL: url}, nil | ||
| } | ||
|
|
||
| // SourcePointer: see BasePathPointer. | ||
| func (OpenAI) SourcePointer(content []byte) func(string) string { return BasePathPointer(content) } | ||
|
|
||
| var _ Reshaper = OpenAI{} | ||
|
|
||
| // YAMLToJSON converts a YAML spec to JSON: diff.Parse reads JSON only, and | ||
| // normalize quotes the node it cites re-serialized, never the original bytes, | ||
| // so nothing quoted changes. | ||
| func YAMLToJSON(body []byte) ([]byte, error) { | ||
| var doc any | ||
| if err := yaml.Unmarshal(body, &doc); err != nil { | ||
| return nil, fmt.Errorf("parsing yaml: %w", err) | ||
| } | ||
| return json.Marshal(doc) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking:
Dailylooks right to me.GitHubCommitsandgithub.Commitboth use the committer date in UTC, so the listed ID andFetch'sVersionagree, and the duplicate IDs are always next to each other because the list is sorted.One thing to check when this rolls out: Supabase, Neon, Convex, PlanetScale and Appwrite are already running. If patch-it's hosted ingestion service last stored a day with two commits by its ID, that ID now points at the day's last commit. If the stored ID came from an earlier commit that day, the commits after it on that day may never be diffed. This happens at most once per source and can only miss events, never produce wrong ones, so it fits "precision over recall". A sentence about it in the PR description would help whoever deploys this.
Small inconsistency:
var _ Lister = OpenAI{}(line 294) sits here, while the Cloudflare and MongoDB assertions are in their own files. It could move toopenai.go.