-
Notifications
You must be signed in to change notification settings - Fork 261
Add OpenAPI docs for Sourcebot public API #996
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
brendan-kellam
merged 6 commits into
sourcebot-dev:main
from
KonradStanski:konrad/public-openapi
Mar 12, 2026
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
17a49a9
Add OpenAPI docs for Sourcebot public API
KonradStanski 16a5ca0
Address OpenAPI PR review feedback
KonradStanski 1937304
Merge branch 'main' into konrad/public-openapi
brendan-kellam 30cf3a5
update release flow to commit docs changes on version change
brendan-kellam 5e16c10
feedback
brendan-kellam 165ed98
feedback
brendan-kellam 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| --- | ||
| title: API Reference | ||
| sidebarTitle: API Reference | ||
| --- | ||
|
|
||
| Sourcebot exposes a public REST API for code search, repository listing, and file browsing. | ||
|
|
||
| The endpoint reference in this section is generated from the web app's Zod schemas and OpenAPI registry, then rendered by Mintlify from [`api-reference/sourcebot-public.openapi.json`](/api-reference/sourcebot-public.openapi.json). | ||
|
|
||
| The first documented surface includes: | ||
|
|
||
| - `/api/search` | ||
| - `/api/stream_search` | ||
| - `/api/repos` | ||
| - `/api/version` | ||
| - `/api/source` | ||
| - `/api/tree` | ||
| - `/api/files` | ||
|
|
||
| To refresh the spec after changing those contracts: | ||
|
|
||
| ```bash | ||
| yarn openapi:generate | ||
| ``` | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import fs from 'node:fs/promises'; | ||
| import path from 'node:path'; | ||
| import { apiHandler } from '@/lib/apiHandler'; | ||
|
|
||
| export const dynamic = 'force-dynamic'; | ||
|
|
||
| const openApiPathCandidates = [ | ||
|
brendan-kellam marked this conversation as resolved.
Outdated
|
||
| path.resolve(process.cwd(), 'docs/api-reference/sourcebot-public.openapi.json'), | ||
| path.resolve(process.cwd(), '../docs/api-reference/sourcebot-public.openapi.json'), | ||
| path.resolve(process.cwd(), '../../docs/api-reference/sourcebot-public.openapi.json'), | ||
| ]; | ||
|
|
||
| async function loadOpenApiDocument() { | ||
| for (const candidate of openApiPathCandidates) { | ||
| try { | ||
| return JSON.parse(await fs.readFile(candidate, 'utf8')); | ||
| } catch (error) { | ||
| if ((error as NodeJS.ErrnoException).code !== 'ENOENT') { | ||
| throw error; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| throw new Error('OpenAPI spec file not found'); | ||
| } | ||
|
|
||
| export const GET = apiHandler(async () => { | ||
| const document = await loadOpenApiDocument(); | ||
|
|
||
| return Response.json(document, { | ||
| headers: { | ||
| 'Content-Type': 'application/vnd.oai.openapi+json;version=3.0.3', | ||
| }, | ||
| }); | ||
| }, { track: false }); | ||
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
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
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,38 @@ | ||
| import { CodeHostType } from '@sourcebot/db'; | ||
| import z from 'zod'; | ||
| import { fileTreeItemSchema, fileTreeNodeSchema } from './types'; | ||
|
|
||
| export const getTreeRequestSchema = z.object({ | ||
| repoName: z.string(), | ||
| revisionName: z.string(), | ||
| paths: z.array(z.string()), | ||
| }); | ||
|
|
||
| export const getTreeResponseSchema = z.object({ | ||
| tree: fileTreeNodeSchema, | ||
| }); | ||
|
|
||
| export const getFilesRequestSchema = z.object({ | ||
| repoName: z.string(), | ||
| revisionName: z.string(), | ||
| }); | ||
|
|
||
| export const getFilesResponseSchema = z.array(fileTreeItemSchema); | ||
|
|
||
| export const fileSourceRequestSchema = z.object({ | ||
| path: z.string(), | ||
| repo: z.string(), | ||
| ref: z.string().optional(), | ||
| }); | ||
|
|
||
| export const fileSourceResponseSchema = z.object({ | ||
| source: z.string(), | ||
| language: z.string(), | ||
| path: z.string(), | ||
| repo: z.string(), | ||
| repoCodeHostType: z.nativeEnum(CodeHostType), | ||
| repoDisplayName: z.string().optional(), | ||
| repoExternalWebUrl: z.string().optional(), | ||
| webUrl: z.string(), | ||
| externalWebUrl: z.string().optional(), | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.