chore(admin): gitignore generated schema/version, regen on every script (#7638)

Qodo flagged the committed admin/src/api/schema.d.ts as a build artifact
that violates the rule against committing generated files (rule 467291,
"Exclude build artifacts and runtime-generated files from version control").

This commit:
- Adds admin/src/api/{schema.d.ts,version.ts} to .gitignore.
- Removes both from VCS (the prior squash had committed them).
- Chains \`gen:api\` into the dev and test scripts so a fresh checkout
  lands a working dev server / test run without an extra step. build
  and build-copy already chained gen:api.
- Drops the now-redundant CI freshness diff step from
  frontend-admin-tests.yml — with the files no longer committed, the
  build step's gen:api invocation is the only check needed.
- Updates admin/README.md to describe the new generated-file workflow.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
John McLear 2026-05-07 15:56:48 +01:00
parent b97baa3ef5
commit 40fe8a4c23
6 changed files with 24 additions and 3602 deletions

View file

@ -68,16 +68,6 @@ jobs:
name: Disable import/export rate limiting
run: |
sed -e '/^ *"importExportRateLimiting":/,/^ *\}/ s/"max":.*/"max": 100000000/' -i settings.json
- name: Verify admin OpenAPI schema is up to date
working-directory: admin
run: |
pnpm gen:api
if ! git diff --exit-code src/api/schema.d.ts src/api/version.ts; then
echo ""
echo "::error::admin/src/api/schema.d.ts or version.ts is out of date."
echo "Run \`pnpm --filter admin gen:api\` and commit the result."
exit 1
fi
- name: Build admin frontend
working-directory: admin
run: |

5
.gitignore vendored
View file

@ -38,3 +38,8 @@ stage/
prime/
.craft/
*.snap
# Generated by `pnpm --filter admin gen:api` from src/node/hooks/express/openapi.ts.
# Regenerated by build/test/dev scripts; not committed.
/admin/src/api/schema.d.ts
/admin/src/api/version.ts

View file

@ -8,11 +8,11 @@ endpoints are added to the OpenAPI spec) over a typed REST client.
| Script | What it does |
| -------------------- | -------------------------------------------------------- |
| `pnpm dev` | Vite dev server. Expects an etherpad backend on :9001. |
| `pnpm gen:api` | Regenerates `src/api/schema.d.ts` from the OpenAPI spec. |
| `pnpm dev` | `gen:api` + Vite dev server (expects backend on :9001). |
| `pnpm gen:api` | Regenerates `src/api/{schema.d.ts,version.ts}` from the OpenAPI spec. |
| `pnpm build` | `gen:api` + `tsc` + `vite build`. |
| `pnpm build-copy` | Same, but writes into `../src/templates/admin`. |
| `pnpm test` | Smoke tests for the API client wiring. |
| `pnpm test` | `gen:api` + smoke tests for the API client wiring. |
| `pnpm lint` | ESLint. |
## Typed API client
@ -25,32 +25,31 @@ The admin uses [`openapi-typescript`] to generate types from
[`openapi-fetch`]: https://github.com/openapi-ts/openapi-typescript/tree/main/packages/openapi-fetch
[`openapi-react-query`]: https://github.com/openapi-ts/openapi-typescript/tree/main/packages/openapi-react-query
### Regenerating the schema
### Generated files
`admin/src/api/schema.d.ts` and `admin/src/api/version.ts` are generated by
`gen:api` and gitignored — never commit them. They are produced by:
```sh
pnpm --filter admin gen:api
```
This runs `admin/scripts/gen-api.mjs`, which loads
`src/node/hooks/express/openapi.ts`, calls `generateDefinitionForVersion` for
the latest API version, pipes the JSON through `openapi-typescript`, and
writes the result to `admin/src/api/schema.d.ts`. The latest API version
read from the spec is also emitted to `admin/src/api/version.ts` so
`client.ts` can build the right `/api/<version>/` baseUrl. Both generated
files are checked in.
`admin/scripts/gen-api.mjs` loads `src/node/hooks/express/openapi.ts`, calls
`generateDefinitionForVersion` for the latest API version, pipes the JSON
through `openapi-typescript` to produce `schema.d.ts`, and emits a runtime
constant `LATEST_API_VERSION` (read from `info.version` in the spec) to
`version.ts` so `client.ts` can build the right `/api/<version>/` baseUrl.
Run `gen:api` after any change to:
`gen:api` runs as the first step of `dev`, `build`, `build-copy`, and
`test`, so a fresh checkout produces the generated files automatically when
any of those scripts is invoked. After modifying any of the following, the
next `pnpm <dev|build|test>` will refresh the generated files; you can also
run `gen:api` directly:
- `src/node/hooks/express/openapi.ts`
- `src/node/handler/APIHandler.ts` (changes to `latestApiVersion`)
- the resource definitions referenced by `openapi.ts`
### CI freshness check
`.github/workflows/frontend-admin-tests.yml` runs `pnpm gen:api` and fails the
build if `admin/src/api/schema.d.ts` is out of date. If you see the failure
locally, run `pnpm --filter admin gen:api` and commit the regenerated file.
### Using the client
```tsx

View file

@ -4,13 +4,13 @@
"version": "2.7.3",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "pnpm gen:api && vite",
"gen:api": "node scripts/gen-api.mjs",
"build": "pnpm gen:api && tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"build-copy": "pnpm gen:api && tsc && vite build --outDir ../src/templates/admin --emptyOutDir",
"preview": "vite preview",
"test": "tsx --test src/api/__tests__/client.test.ts"
"test": "pnpm gen:api && tsx --test src/api/__tests__/client.test.ts"
},
"dependencies": {
"@radix-ui/react-switch": "^1.2.6",

File diff suppressed because it is too large Load diff

View file

@ -1,5 +0,0 @@
// GENERATED — do not edit. Run `pnpm --filter admin gen:api` to regenerate.
// Source: src/node/hooks/express/openapi.ts (#7638)
export const LATEST_API_VERSION = "1.3.1";
export const API_BASE_URL = `/api/${LATEST_API_VERSION}`;