Skip to content

Commit a11cdc5

Browse files
committed
docs: update hey-api changes
1 parent ef6123c commit a11cdc5

3 files changed

Lines changed: 40 additions & 12 deletions

File tree

docs/docs/developer-guide/contributing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ bun run lint:fix
109109

110110
- Use `<script setup lang="ts">` for all components
111111
- Import types from `@/types/utils` — never define local type aliases
112+
- Import Zod schemas as `z<SchemaName>` from `@/types/zod.gen`, and use `toTypedSchema` from `@/utils/zodAdapter` (not `@vee-validate/zod`, which is Zod v3 only)
112113
- Stores delegate API calls to services (stores manage state only)
113114
- Use `loading` (not `isLoading`) for loading state variables
114115
- Use composables (`usePagination`, `useModalWithData`) for common patterns

docs/docs/developer-guide/frontend.md

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ frontend/src/
4444
│ └── profile/ # User profile settings
4545
├── composables/ # Reusable composition functions
4646
├── types/
47-
│ ├── schema.ts # Auto-generated TypeScript types
48-
│ ├── zod.ts # Auto-generated Zod schemas
49-
│ ├── utils.ts # Shared entity type exports
47+
│ ├── types.gen.ts # Auto-generated TypeScript types (@hey-api/openapi-ts)
48+
│ ├── zod.gen.ts # Auto-generated Zod schemas (@hey-api/openapi-ts)
49+
│ ├── utils.ts # Re-exports from types.gen + shared utility types
5050
│ └── components.ts # Component-specific types
51-
├── utils/ # Utility functions
51+
├── utils/
52+
│ ├── zodAdapter.ts # Zod v4 → vee-validate TypedSchema adapter
53+
│ └── ... # other utility functions
5254
└── views/ # Route-level page components
5355
```
5456

@@ -101,18 +103,36 @@ export const useWidgetStore = defineStore('widget', () => {
101103

102104
### Type Imports
103105

104-
Always import entity types from `@/types/utils`never define local type aliases from `schema.ts`:
106+
Always import entity types from `@/types/utils``utils.ts` re-exports the named types from `types.gen.ts` and adds hand-written utility types:
105107

106108
```typescript
107109
// Correct
108110
import type { UserRead, AssessmentRead } from '@/types/utils';
109111

110-
// Wrong — don't do this
111-
import type { components } from '@/types/schema';
112+
// Wrong — `components` is not exported by the generator
113+
import type { components } from '@/types/types.gen';
112114
type UserRead = components['schemas']['UserRead'];
113115
```
114116

115-
If a type isn't exported yet, add it to `utils.ts`.
117+
If a type isn't re-exported yet, add the name to the `export type { … } from './types.gen'` block in `utils.ts`.
118+
119+
### Form Validation
120+
121+
Forms use [vee-validate](https://vee-validate.logaretm.com/) with the auto-generated Zod schemas. Each schema is exported individually with a `z` prefix (`zUserBase`, `zAssessmentBase`, …) — there is no `schemas` namespace.
122+
123+
```typescript
124+
import { useForm } from 'vee-validate';
125+
import { toTypedSchema } from '@/utils/zodAdapter';
126+
import { zUserBase } from '@/types/zod.gen';
127+
128+
const { handleSubmit } = useForm({
129+
validationSchema: toTypedSchema(zUserBase),
130+
});
131+
```
132+
133+
`toTypedSchema` is a small local adapter (`utils/zodAdapter.ts`) that bridges Zod v4 schemas to vee-validate's `TypedSchema` interface — the published `@vee-validate/zod` package only supports Zod v3.
134+
135+
Validation runs **only on form submit** (configured globally in `main.ts`). After a failed submit, vee-validate auto-revalidates each field as the user edits it, so errors clear live once they've been surfaced. The default Zod v4 message for missing required fields (`"Invalid input: expected string, received undefined"`) is overridden to `"Required"` via a global `z.config({ customError })` — see `main.ts`.
116136

117137
### Composables
118138

@@ -128,16 +148,23 @@ All components use `<script setup lang="ts">`. UI primitives come from shadcn-vu
128148

129149
## Type Generation
130150

151+
Frontend types are generated from the backend's OpenAPI schema using [`@hey-api/openapi-ts`](https://heyapi.dev/). Configuration lives in `frontend/openapi-ts.config.ts`.
152+
131153
After any backend API change, regenerate the frontend types:
132154

133155
```bash
134156
bun run update:api # Requires backend running on localhost:8000
135157
```
136158

137-
This runs three steps: fetch the OpenAPI schema, generate TypeScript types (`schema.ts`), and generate Zod schemas (`zod.ts`).
159+
This runs two steps:
160+
161+
1. `fetch:openapi` — downloads `openapi.json` from the running backend
162+
2. `gen:api` — runs `@hey-api/openapi-ts` to produce `src/types/types.gen.ts` (TypeScript types) and `src/types/zod.gen.ts` (Zod schemas)
163+
164+
Each script can also be run individually.
138165

139166
!!! warning
140-
Never edit `schema.ts` or `zod.ts` manually — they are overwritten on each generation.
167+
Never edit `types.gen.ts` or `zod.gen.ts` manually — they are overwritten on each generation. Add re-exports to `utils.ts` instead.
141168

142169
## Linting and Formatting
143170

docs/docs/developer-guide/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ Stores manage reactive state but **delegate all API calls to services**. Types a
6363

6464
### Frontend ↔ Backend Contract
6565

66-
The OpenAPI schema is the contract between frontend and backend. After any backend API change:
66+
The OpenAPI schema is the contract between frontend and backend. Code generation is handled by [`@hey-api/openapi-ts`](https://heyapi.dev/), configured in `frontend/openapi-ts.config.ts`. After any backend API change:
6767

6868
```bash
6969
bun run update:api # Fetches OpenAPI schema and regenerates TypeScript types + Zod schemas (requires running backend service at localhost:8000)
7070
```
7171

72-
This generates `src/types/schema.ts` (TypeScript types) and `src/types/zod.ts` (Zod validation schemas) from the running backend.
72+
This generates `src/types/types.gen.ts` (TypeScript types) and `src/types/zod.gen.ts` (Zod validation schemas) from the running backend. Forms validate against the generated `z<SchemaName>` exports through a small Zod v4 adapter at `src/utils/zodAdapter.ts`.
7373

7474
### Docker Build
7575

0 commit comments

Comments
 (0)