Skip to content

Commit c329028

Browse files
committed
feat(api): document public API authentication
1 parent 65a4560 commit c329028

File tree

4 files changed

+75
-10
lines changed

4 files changed

+75
-10
lines changed

docs/api-reference/sourcebot-public.openapi.json

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33
"info": {
44
"title": "Sourcebot Public API",
55
"version": "v4.15.6",
6-
"description": "OpenAPI description for the public Sourcebot REST endpoints used for search, repository listing, and file browsing."
6+
"description": "OpenAPI description for the public Sourcebot REST endpoints used for search, repository listing, and file browsing. Authentication is instance-dependent: API keys are the standard integration mechanism, OAuth bearer tokens are EE-only, and some instances may allow anonymous access."
77
},
8+
"security": [
9+
{
10+
"bearerAuth": []
11+
},
12+
{
13+
"sourcebotApiKey": []
14+
},
15+
{}
16+
],
817
"tags": [
918
{
1019
"name": "Search",
@@ -512,8 +521,7 @@
512521
"properties": {
513522
"version": {
514523
"type": "string",
515-
"description": "Running Sourcebot version.",
516-
"example": "v4.15.2"
524+
"description": "Running Sourcebot version."
517525
}
518526
},
519527
"required": [
@@ -657,11 +665,25 @@
657665
"additionalProperties": false
658666
}
659667
},
660-
"parameters": {}
668+
"parameters": {},
669+
"securitySchemes": {
670+
"bearerAuth": {
671+
"type": "http",
672+
"scheme": "bearer",
673+
"description": "Send either a Sourcebot API key (`sbk_...` or legacy `sourcebot-...`) or, on EE instances with OAuth enabled, an OAuth access token (`sboa_...`) in the Authorization header."
674+
},
675+
"sourcebotApiKey": {
676+
"type": "apiKey",
677+
"in": "header",
678+
"name": "X-Sourcebot-Api-Key",
679+
"description": "Send a Sourcebot API key (`sbk_...` or legacy `sourcebot-...`) in the X-Sourcebot-Api-Key header."
680+
}
681+
}
661682
},
662683
"paths": {
663684
"/api/search": {
664685
"post": {
686+
"operationId": "search",
665687
"tags": [
666688
"Search"
667689
],
@@ -712,6 +734,7 @@
712734
},
713735
"/api/stream_search": {
714736
"post": {
737+
"operationId": "streamSearch",
715738
"tags": [
716739
"Search"
717740
],
@@ -763,6 +786,7 @@
763786
},
764787
"/api/repos": {
765788
"get": {
789+
"operationId": "listRepositories",
766790
"tags": [
767791
"Repositories"
768792
],
@@ -878,6 +902,7 @@
878902
},
879903
"/api/version": {
880904
"get": {
905+
"operationId": "getVersion",
881906
"tags": [
882907
"Misc"
883908
],
@@ -898,6 +923,7 @@
898923
},
899924
"/api/source": {
900925
"get": {
926+
"operationId": "getFileSource",
901927
"tags": [
902928
"Files"
903929
],
@@ -974,6 +1000,7 @@
9741000
},
9751001
"/api/tree": {
9761002
"post": {
1003+
"operationId": "getFileTree",
9771004
"tags": [
9781005
"Files"
9791006
],
@@ -1043,6 +1070,7 @@
10431070
},
10441071
"/api/files": {
10451072
"post": {
1073+
"operationId": "listFiles",
10461074
"tags": [
10471075
"Files"
10481076
],

docs/docs/api-reference/overview.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ You can fetch the OpenAPI document for your Sourcebot instance from `/api/openap
77

88
This API reference is generated from the web app's Zod schemas and OpenAPI registry. Mintlify renders it from the checked-in spec at [`/api-reference/sourcebot-public.openapi.json`](/api-reference/sourcebot-public.openapi.json).
99

10+
For authenticated access, create an API key in Sourcebot from **Settings -> API Keys** and send it with either:
11+
12+
- `X-Sourcebot-Api-Key: sbk_...`
13+
- `Authorization: Bearer sbk_...`
14+
15+
Some instances may also allow anonymous access for these endpoints. On EE instances with OAuth enabled, bearer tokens with the `sboa_...` prefix are also accepted.
16+
1017
The first documented endpoints include:
1118

1219
- `/api/search`

packages/web/src/openapi/publicApiDocument.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { OpenAPIRegistry, OpenApiGeneratorV3 } from '@asteasolutions/zod-to-openapi';
22
import type { ZodTypeAny } from 'zod';
3-
import type { SchemaObject } from 'openapi3-ts/oas30';
3+
import type { ComponentsObject, SchemaObject, SecuritySchemeObject } from 'openapi3-ts/oas30';
44
import {
55
publicFileSourceRequestSchema,
66
publicFileSourceResponseSchema,
@@ -45,6 +45,20 @@ const publicGetTreeResponseSchema: SchemaObject = {
4545
additionalProperties: false,
4646
};
4747

48+
const securitySchemes: Record<string, SecuritySchemeObject> = {
49+
bearerAuth: {
50+
type: 'http',
51+
scheme: 'bearer',
52+
description: 'Send either a Sourcebot API key (`sbk_...` or legacy `sourcebot-...`) or, on EE instances with OAuth enabled, an OAuth access token (`sboa_...`) in the Authorization header.',
53+
},
54+
sourcebotApiKey: {
55+
type: 'apiKey',
56+
in: 'header',
57+
name: 'X-Sourcebot-Api-Key',
58+
description: 'Send a Sourcebot API key (`sbk_...` or legacy `sourcebot-...`) in the X-Sourcebot-Api-Key header.',
59+
},
60+
};
61+
4862
function jsonContent(schema: ZodTypeAny | SchemaObject) {
4963
return {
5064
'application/json': {
@@ -66,6 +80,7 @@ export function createPublicOpenApiDocument(version: string) {
6680
registry.registerPath({
6781
method: 'post',
6882
path: '/api/search',
83+
operationId: 'search',
6984
tags: [searchTag.name],
7085
summary: 'Run a blocking code search',
7186
request: {
@@ -87,6 +102,7 @@ export function createPublicOpenApiDocument(version: string) {
87102
registry.registerPath({
88103
method: 'post',
89104
path: '/api/stream_search',
105+
operationId: 'streamSearch',
90106
tags: [searchTag.name],
91107
summary: 'Run a streaming code search',
92108
description: 'Returns a server-sent event stream. Each event data payload is a JSON object describing either a chunk, final summary, or error.',
@@ -113,6 +129,7 @@ export function createPublicOpenApiDocument(version: string) {
113129
registry.registerPath({
114130
method: 'get',
115131
path: '/api/repos',
132+
operationId: 'listRepositories',
116133
tags: [reposTag.name],
117134
summary: 'List repositories',
118135
request: {
@@ -147,6 +164,7 @@ export function createPublicOpenApiDocument(version: string) {
147164
registry.registerPath({
148165
method: 'get',
149166
path: '/api/version',
167+
operationId: 'getVersion',
150168
tags: [miscTag.name],
151169
summary: 'Get Sourcebot version',
152170
responses: {
@@ -160,6 +178,7 @@ export function createPublicOpenApiDocument(version: string) {
160178
registry.registerPath({
161179
method: 'get',
162180
path: '/api/source',
181+
operationId: 'getFileSource',
163182
tags: [filesTag.name],
164183
summary: 'Get file contents',
165184
request: {
@@ -179,6 +198,7 @@ export function createPublicOpenApiDocument(version: string) {
179198
registry.registerPath({
180199
method: 'post',
181200
path: '/api/tree',
201+
operationId: 'getFileTree',
182202
tags: [filesTag.name],
183203
summary: 'Get a file tree',
184204
request: {
@@ -201,6 +221,7 @@ export function createPublicOpenApiDocument(version: string) {
201221
registry.registerPath({
202222
method: 'post',
203223
path: '/api/files',
224+
operationId: 'listFiles',
204225
tags: [filesTag.name],
205226
summary: 'List files in a repository revision',
206227
request: {
@@ -227,16 +248,26 @@ export function createPublicOpenApiDocument(version: string) {
227248
info: {
228249
title: 'Sourcebot Public API',
229250
version,
230-
description: 'OpenAPI description for the public Sourcebot REST endpoints used for search, repository listing, and file browsing.',
251+
description: 'OpenAPI description for the public Sourcebot REST endpoints used for search, repository listing, and file browsing. Authentication is instance-dependent: API keys are the standard integration mechanism, OAuth bearer tokens are EE-only, and some instances may allow anonymous access.',
231252
},
253+
security: [
254+
{ bearerAuth: [] },
255+
{ sourcebotApiKey: [] },
256+
{},
257+
],
232258
tags: [searchTag, reposTag, filesTag, miscTag],
233259
});
234260

235-
document.components = document.components ?? {};
236-
document.components.schemas = {
237-
...(document.components.schemas ?? {}),
261+
const components: ComponentsObject = document.components ?? {};
262+
components.schemas = {
263+
...(components.schemas ?? {}),
238264
PublicFileTreeNode: publicFileTreeNodeSchema,
239265
};
266+
components.securitySchemes = {
267+
...(components.securitySchemes ?? {}),
268+
...securitySchemes,
269+
};
270+
document.components = components;
240271

241272
return document;
242273
}

packages/web/src/openapi/publicApiSchemas.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export const publicFileSourceResponseSchema = fileSourceResponseSchema.openapi('
4141
export const publicVersionResponseSchema = z.object({
4242
version: z.string().openapi({
4343
description: 'Running Sourcebot version.',
44-
example: 'v4.15.2',
4544
}),
4645
}).openapi('PublicVersionResponse');
4746

0 commit comments

Comments
 (0)