Skip to content

Commit b7d5dd2

Browse files
authored
Merge pull request #486 from spacedriveapp/feat/openapi-migration
feat: OpenAPI Migration with Generated TypeScript Types
2 parents 7c827cf + a8a9c0a commit b7d5dd2

66 files changed

Lines changed: 11568 additions & 1180 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 80 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ rust-embed = { version = "8", features = ["mime-guess"] }
126126
mime_guess = "2"
127127
async-stream = "0.3"
128128

129+
# OpenAPI / utoipa
130+
utoipa = { version = "5", features = ["axum_extras", "chrono", "uuid"] }
131+
utoipa-axum = "0.2"
132+
utoipa-swagger-ui = { version = "9", features = ["axum"] }
133+
129134
# Indoc for test fixtures
130135
indoc = "2"
131136
arrow-array = "57.3.0"
@@ -175,6 +180,10 @@ parking_lot = "0.12"
175180
[target.'cfg(target_os = "macos")'.dependencies]
176181
security-framework = "3"
177182

183+
[[bin]]
184+
name = "openapi-spec"
185+
path = "src/bin/openapi_spec.rs"
186+
178187
[profile.release]
179188
lto = "thin"
180189
strip = true

interface/bun.lock

Lines changed: 57 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

interface/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"graphology-layout-forceatlas2": "^0.10.1",
5252
"graphology-types": "^0.24.8",
5353
"ogl": "^1.0.11",
54+
"openapi-fetch": "^0.17",
5455
"react": "^19.0.0",
5556
"react-dom": "^19.0.0",
5657
"react-hook-form": "^7.71.1",
@@ -68,6 +69,7 @@
6869
"@types/react-dom": "^19.0.0",
6970
"@vitejs/plugin-react": "^4.3.4",
7071
"autoprefixer": "^10.4.18",
72+
"openapi-typescript": "^7",
7173
"postcss": "^8.4.36",
7274
"sass": "^1.72.0",
7375
"tailwindcss": "^3.4.1",

interface/src/api/client-typed.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import createClient from "openapi-fetch";
2+
import type { paths } from "./schema";
3+
4+
let baseUrl = "";
5+
6+
export function setServerUrl(url: string) {
7+
baseUrl = url;
8+
}
9+
10+
function getClient() {
11+
return createClient<paths>({
12+
baseUrl: baseUrl ? `${baseUrl}/api` : "/api",
13+
headers: getAuthHeaders(),
14+
});
15+
}
16+
17+
function getAuthHeaders(): Record<string, string> {
18+
const token = localStorage.getItem("spacebot_auth_token");
19+
return token ? { Authorization: `Bearer ${token}` } : {};
20+
}
21+
22+
// Re-export the typed client for direct use
23+
export { getClient };
24+
export type { paths };

0 commit comments

Comments
 (0)