feat(auth): add Swagger docs and unify CLI on cobra - #32
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Mirrors the
runningproject'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-serviceis now a singlegithub.com/spf13/cobrabinary, replacing the ad-hocos.Argsswitch. Subcommands each live in their owncmd_*.gofile:serveseed [email] [password]migratemigrate-storage azure-to-mysql [--dry-run] [--clear-target]The
compareCounts/countsEmptyhelpers (covered bymain_test.go) moved tocmd_migrate_storage.go.Swagger
swaggo/swag.main.go:ClientID(X-Client-Id),BearerAuth,BasicAuth.internal/server/swagger.go) is behind theswaggerbuild tag with a no-op stub (swagger_stub.go) for the default build, so plaingo build/go testnever need the generated code. Served at/swagger/index.htmlonly whenSWAGGER_ENABLED=true.cmd/auth-service/docscommitted; newMakefilewrapsbuild/test/vet/swagger/build-service-swagger.Docker / compose
Explicit
servecommand:ENTRYPOINT ["/app/auth-service"]+CMD ["serve"], image built with-tags swaggerso the UI is available at runtime when enabled; compose setscommand: ["serve"]andSWAGGER_ENABLED: "true".Config
New
SwaggerEnabledfield viaSWAGGER_ENABLEDenv (default off).Verification
go build ./...andgo build -tags swagger ./...— passgo vet(both tags),gofmt -l .— cleango test ./...— pass (MySQL integration suite green)/swagger/index.html→ 200,/swagger/doc.json→ 35 paths, title "Auth Service API"auth-service --helplists all subcommandsNotes
ListTeams,ListMembers,ListMyTeams) returngin.H{"teams": [...]}, so their schema is documented asmap[string]interface{}(accurate wrapper, loses element type). Tightening to typed wrapper structs would need small handler changes — deferred.make swaggerand commit the regenerated docs.