feat: add OpenAPI spec (dev only) with typed frontend client
- Add springdoc-openapi 3.0.2 (supports Spring Boot 4) to backend - Disable api-docs/swagger-ui in application.yaml (prod default) - Enable both in application-dev.yaml; Swagger UI at /swagger-ui.html - Add openapi-fetch (runtime) and openapi-typescript (dev) to frontend - Add generate:api npm script — run with backend up to regenerate types - Add src/lib/api.server.ts typed client factory (uses SvelteKit fetch) - Gitignore src/lib/generated/api.ts (generated artifact) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
25
frontend/src/lib/api.server.ts
Normal file
25
frontend/src/lib/api.server.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Typed API client for the Familienarchiv backend.
|
||||
*
|
||||
* Types are generated from the OpenAPI spec — run `npm run generate:api`
|
||||
* (with the backend running in dev mode) to regenerate src/lib/generated/api.ts.
|
||||
*
|
||||
* Usage in +page.server.ts:
|
||||
*
|
||||
* export async function load({ fetch }) {
|
||||
* const api = createApiClient(fetch);
|
||||
* const { data, error } = await api.GET('/api/documents/{id}', {
|
||||
* params: { path: { id } }
|
||||
* });
|
||||
* }
|
||||
*/
|
||||
import createClient from 'openapi-fetch';
|
||||
import { env } from '$env/dynamic/private';
|
||||
import type { paths } from '$lib/generated/api';
|
||||
|
||||
export function createApiClient(fetch: typeof globalThis.fetch) {
|
||||
return createClient<paths>({
|
||||
baseUrl: env.API_INTERNAL_URL || 'http://localhost:8080',
|
||||
fetch
|
||||
});
|
||||
}
|
||||
0
frontend/src/lib/generated/.gitkeep
Normal file
0
frontend/src/lib/generated/.gitkeep
Normal file
Reference in New Issue
Block a user