# Generate API Types

Fetch the OpenAPI schema from the backend and generate TypeScript types.

## Usage

```
/gen-api-types
```

## Instructions

1. Ensure the backend server is running at `http://127.0.0.1:8000`. If the command fails with a connection error, inform the user that the backend must be running first.

2. Run the type generation:
   ```bash
   bun run gen:api-types
   ```
   This executes:
   ```
   openapi-typescript http://127.0.0.1:8000/api/schema/ --output src/shared/api/__generated__/openapi.types.ts
   ```

3. Report success and note that the generated types are at `src/shared/api/__generated__/openapi.types.ts`.

4. The generated file exports:
   - `paths` — all API endpoints with request/response types
   - `components` — schema definitions (used as `components["schemas"]["ModelName"]`)
   - `operations` — operation-level types

## Usage in Code

```tsx
// Import schema types
import type { components } from "@shared/api/__generated__/openapi.types"

type ProjectRead = components["schemas"]["ProjectRead"]

// Use with the API client
import api from "@shared/api"

api.useQuery("get", "/api/projects/")
api.useMutation("post", "/api/projects/", { onSuccess, onError })
```

## Notes

- Requires the backend running at `http://127.0.0.1:8000`
- Uses `openapi-typescript` to generate types from the `/api/schema/` endpoint
- The API client (`src/shared/api/index.ts`) uses `openapi-fetch` + `openapi-react-query` with these generated types
- After regeneration, check for any TypeScript errors in components that use the API types, as schema changes may break existing code
