Skip to content

feat(auth): add Swagger docs and unify CLI on cobra - #32

Merged
zhaochy1990 merged 3 commits into
masterfrom
feat/auth-swagger-cobra-cli
Jul 30, 2026
Merged

feat(auth): add Swagger docs and unify CLI on cobra#32
zhaochy1990 merged 3 commits into
masterfrom
feat/auth-swagger-cobra-cli

Conversation

@zhaochy1990

Copy link
Copy Markdown
Owner

Summary

Mirrors the running project's setup for the Go auth backend (sources/dev/authentication-go): a unified cobra CLI and swaggo/gin-swagger API docs.

Cobra CLI

cmd/auth-service is now a single github.com/spf13/cobra binary, replacing the ad-hoc os.Args switch. Subcommands each live in their own cmd_*.go file:

Command Purpose
serve Start the Gin HTTP server (default container command)
seed [email] [password] Bootstrap the admin user + Admin Dashboard app client
migrate Backfill legacy Azure Table rows (no-op on MySQL)
migrate-storage azure-to-mysql [--dry-run] [--clear-target] Azure Tables → MySQL cutover

The compareCounts/countsEmpty helpers (covered by main_test.go) moved to cmd_migrate_storage.go.

Swagger

  • All 35 endpoints (auth, oauth, users, teams, admin) annotated with swaggo/swag.
  • General API info + 3 security schemes on main.go: ClientID (X-Client-Id), BearerAuth, BasicAuth.
  • UI mount (internal/server/swagger.go) is behind the swagger build tag with a no-op stub (swagger_stub.go) for the default build, so plain go build/go test never need the generated code. Served at /swagger/index.html only when SWAGGER_ENABLED=true.
  • Generated cmd/auth-service/docs committed; new Makefile wraps build/test/vet/swagger/build-service-swagger.

Docker / compose

Explicit serve command: ENTRYPOINT ["/app/auth-service"] + CMD ["serve"], image built with -tags swagger so the UI is available at runtime when enabled; compose sets command: ["serve"] and SWAGGER_ENABLED: "true".

Config

New SwaggerEnabled field via SWAGGER_ENABLED env (default off).

Verification

  • go build ./... and go build -tags swagger ./... — pass
  • go vet (both tags), gofmt -l . — clean
  • go test ./... — pass (MySQL integration suite green)
  • Runtime smoke test: /swagger/index.html → 200, /swagger/doc.json → 35 paths, title "Auth Service API"
  • auth-service --help lists all subcommands

Notes

  • Three list endpoints (ListTeams, ListMembers, ListMyTeams) return gin.H{"teams": [...]}, so their schema is documented as map[string]interface{} (accurate wrapper, loses element type). Tightening to typed wrapper structs would need small handler changes — deferred.
  • After future route/DTO changes, rerun make swagger and commit the regenerated docs.

Mirror the running project's setup for the Go auth backend.

Cobra CLI: cmd/auth-service is now a single github.com/spf13/cobra binary
with subcommands (serve, seed, migrate, migrate-storage), each in its own
cmd_*.go file, replacing the ad-hoc os.Args switch. The container default
command is serve; maintenance tasks run by overriding it.

Swagger: annotate all 35 endpoints (auth, oauth, users, teams, admin) with
swaggo/swag; general API info + security schemes (ClientID, BearerAuth,
BasicAuth) live on main.go. The /swagger UI mount is behind the `swagger`
build tag with a no-op stub for the default build, and is served only when
SWAGGER_ENABLED=true. Generated cmd/auth-service/docs is committed; a
Makefile wraps build/test/swagger targets.

Docker/compose updated to the explicit `serve` command and built with
-tags swagger so the UI is available at runtime when enabled.
Remove the `migrate` and `migrate-storage` cobra commands and the now-unused
Azure Table backfill methods (MigrateInviteCodeKinds, MigrateUserInviteCodes,
MigrateUserSortIndexes, and the migrateSortIndexes helper). The CLI now exposes
only `serve` and `seed`. Delete main_test.go (it only covered the removed
migrate-storage helpers) and update README/CLAUDE.md accordingly.
CI checks out zhaochy1990/x@master (go 1.25, requires pflag v1.0.10) and runs
`go vet` in readonly mode, which failed with "updates to go.mod needed". Bump
the pflag indirect requirement to v1.0.10 so the module graph is tidy against
the x version CI uses.
@zhaochy1990
zhaochy1990 merged commit 25b627e into master Jul 30, 2026
7 checks passed
@zhaochy1990
zhaochy1990 deleted the feat/auth-swagger-cobra-cli branch July 30, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant