Skip to content

Commit 3446e81

Browse files
author
root
committed
create swagger
1 parent df67d02 commit 3446e81

40 files changed

Lines changed: 13088 additions & 1194 deletions

Makefile

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.PHONY: help install tidy build run test lint fmt check sec scan sbom \
22
image start stop restart logs stats delete rm kill-port redo \
3-
openapi-gen openapi-check
3+
openapi-gen openapi-merge openapi-check openapi-sync
44

55
# ============================================================
66
# Default values
@@ -36,7 +36,9 @@ help:
3636
@echo " make fmt Format code (gofmt, prettier)"
3737
@echo " make check Format + lint in one step (local dev)"
3838
@echo " make openapi-gen Auto-generate OpenAPI spec skeleton from route source"
39+
@echo " make openapi-merge Merge ext-api.yaml + native-api.yaml -> api.yaml"
3940
@echo " make openapi-check Assert all /api/ext routes are in the spec (CI gate)"
41+
@echo " make openapi-sync Generate + validate OpenAPI in one command"
4042
@echo " make sec Security scan (govulncheck, npm audit, gitleaks)"
4143
@echo " make scan Container image scan (trivy, HIGH/CRITICAL)"
4244
@echo " make sbom Generate SBOM → sbom.spdx.json (syft)"
@@ -140,7 +142,7 @@ tidy:
140142
build:
141143
ifeq ($(ARG2),backend)
142144
@echo "Building backend (static binary, no dependencies)..."
143-
@$(MAKE) openapi-gen
145+
@$(MAKE) openapi-sync
144146
@cd backend && CGO_ENABLED=0 go build -ldflags="-w -s" -o appos ./cmd/appos
145147
@echo "✓ Backend built → backend/appos (statically linked)"
146148
else ifeq ($(ARG2),dashboard)
@@ -151,7 +153,7 @@ else ifeq ($(ARG2),library)
151153
@echo "'make build library' is no longer needed - library is downloaded during Docker build (cached)"
152154
else
153155
@echo "Building all..."
154-
@$(MAKE) openapi-gen
156+
@$(MAKE) openapi-sync
155157
@cd backend && CGO_ENABLED=0 go build -ldflags="-w -s" -o appos ./cmd/appos
156158
@echo "✓ Backend built → backend/appos"
157159
@cd dashboard && npm run build
@@ -183,11 +185,11 @@ test:
183185
@echo "Running tests..."
184186
@if [ -f "backend/go.mod" ]; then \
185187
echo "→ Go tests..."; \
186-
cd backend && go test ./... -v || true; \
188+
cd backend && go test ./... -v; \
187189
fi
188190
@if [ -f "dashboard/package.json" ]; then \
189191
echo "→ JS tests..."; \
190-
cd dashboard && npm test 2>/dev/null || true; \
192+
cd dashboard && npm test 2>/dev/null; \
191193
fi
192194
@echo "✓ Tests completed"
193195

@@ -207,14 +209,26 @@ lint:
207209
@echo "✓ Linting completed"
208210

209211
openapi-gen:
210-
@echo "Generating OpenAPI spec skeleton from route source..."
211-
@go run backend/cmd/gen-openapi/main.go
212+
@echo "Generating OpenAPI ext spec from route source..."
213+
@cd backend && go run ./cmd/openapi gen
212214
@echo "→ spec: backend/docs/openapi/ext-api.yaml"
213215

216+
openapi-merge:
217+
@echo "Merging OpenAPI specs (ext + native)..."
218+
@cd backend && go run ./cmd/openapi merge
219+
@echo "→ spec: backend/docs/openapi/api.yaml"
220+
214221
openapi-check:
215222
@echo "Checking all /api/ext routes are covered by OpenAPI spec..."
216223
@cd backend && go test ./internal/routes/ -run TestAllExtRoutesCoveredByOpenAPISpec -v
217224

225+
openapi-sync:
226+
@echo "Syncing OpenAPI spec (generate + merge + validate)..."
227+
@$(MAKE) openapi-gen
228+
@$(MAKE) openapi-merge
229+
@$(MAKE) openapi-check
230+
@echo "✓ OpenAPI sync completed"
231+
218232
fmt:
219233
@echo "Formatting code..."
220234
@if [ -f "backend/go.mod" ]; then \

backend/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,38 @@ go build -o appos cmd/appos/main.go
3333
./appos serve --http=0.0.0.0:8090
3434
```
3535

36+
## OpenAPI Maintenance
37+
38+
OpenAPI docs are embedded into the `appos` binary and served at:
39+
40+
- `/openapi` (Swagger UI)
41+
- `/openapi/spec` (raw YAML)
42+
43+
Primary spec file:
44+
45+
- `backend/docs/openapi/api.yaml` (generated merged artifact)
46+
47+
Recommended workflow after route changes:
48+
49+
```bash
50+
# from project root
51+
make openapi-sync
52+
```
53+
54+
Available commands:
55+
56+
- `make openapi-gen` — regenerate `ext-api.yaml` from `/api/ext/*` route source (machine-generated)
57+
- `make openapi-merge` — merge `ext-api.yaml` + `native-api.yaml` into `api.yaml`
58+
- `make openapi-check` — fail when Ext route/spec drift or duplicate YAML keys exist
59+
- `make openapi-sync` — run generate + merge + check in order
60+
61+
Maintenance rules:
62+
63+
- Keep `native-api.yaml` manually curated.
64+
- Treat `ext-api.yaml` as generated file (do not edit manually).
65+
- Treat `api.yaml` as generated merge artifact (do not edit manually).
66+
- Rebuild backend (`make build backend`) after spec updates so embedded docs are refreshed.
67+
3668
## Project Structure
3769

3870
```

0 commit comments

Comments
 (0)