Skip to content

Commit 01f667a

Browse files
authored
chore(web): TS API client type generation (#3096)
* chore(web): initial setup for TS API client type generation * chore: almost there * chore: all tests are green * chore: close to done * chore: update the docs * chore: comment * chore: simplify fetch calls * chore: more cleanup and feedback * chore: feedback * chore: eslint
1 parent 1cf5744 commit 01f667a

Some content is hidden

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

55 files changed

+5501
-1242
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,9 @@ jobs:
7575
- name: Install dependencies
7676
run: |
7777
npm install
78-
- name: Run web lint
78+
- name: Run web tests (types check, lint, and unit tests)
7979
run: |
80-
npm run lint
81-
- name: Run web unit tests
82-
run: |
83-
npm run test:unit
80+
npm run test
8481
- name: Build web
8582
run: |
8683
npm run build

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,14 @@ scan:
342342
--ignore-unfixed \
343343
./
344344

345+
.PHONY: api-types
346+
api-types:
347+
@echo "Generating OpenAPI documentation..."
348+
$(MAKE) -C api swagger
349+
@echo "Generating TypeScript types from OpenAPI spec..."
350+
cd web && npm run types:api:generate
351+
@echo "API types generated successfully!"
352+
345353
.PHONY: list-distros
346354
list-distros:
347355
@$(MAKE) -C dev/distros list

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,22 @@ The build system checks for overrides in this order:
382382
383383
The system automatically generates a KOTS version string based on your override, ensuring proper versioning for development builds on rebuilds.
384384
385+
## API Type Generation (V3 Manager Experience Only)
386+
387+
The V3 manager experience uses OpenAPI/Swagger to generate TypeScript types for the web frontend. When you make changes to API endpoints or types in the `api/` directory for the V3 installer, you need to regenerate the types:
388+
389+
```bash
390+
make api-types
391+
```
392+
393+
This command:
394+
1. Generates OpenAPI documentation from Go code annotations (`api/docs/swagger.yaml`)
395+
2. Generates TypeScript types from the OpenAPI spec (`web/src/types/api.ts`)
396+
397+
The types are automatically generated before building the web frontend (`npm run build` runs `types:api:generate` as a pre-build step), but you should run `make api-types` manually when developing API changes to ensure the frontend types stay in sync.
398+
399+
**Note:** This is only relevant when working on the V3 manager experience (the new installer UI). The V2 experience uses KOTS admin console and does not use these generated types.
400+
385401
## Dependency Versions
386402
387403
The [versions.mk](versions.mk) file serves as the single source of truth for all external dependency versions.

api/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ include ../versions.mk
66
.PHONY: swagger
77
swagger: swag
88
swag fmt -g api.go
9-
swag init --parseDependency --v3.1 -g api.go
9+
swag init --parseDependency --requiredByDefault --v3.1 -g api.go
1010

1111
.PHONY: swag
1212
swag:

api/docs/docs.go

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

api/docs/swagger.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)