Skip to content

feat: add REST API with OpenAPI/Swagger documentation - #22

Merged
xdefrag merged 4 commits into
masterfrom
feat/rest-api-swagger
Feb 9, 2026
Merged

feat: add REST API with OpenAPI/Swagger documentation#22
xdefrag merged 4 commits into
masterfrom
feat/rest-api-swagger

Conversation

@xdefrag

@xdefrag xdefrag commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a JSON REST API at /api/v1/* with 6 endpoints for programmatic access to accounts, relationships, reputation scores, and statistics
  • Add Swagger UI at /swagger/ with auto-generated OpenAPI spec via swaggo/swag
  • Extract BSN (Business Social Network) relationship grouping logic into shared internal/bsn package for reuse between HTML and API handlers
  • Add repository count methods (CountPersons, CountCorporate, CountSynthetic) and GetAccountMetadata for API pagination and detail responses

API Endpoints

Method Path Description
GET /api/v1/stats Aggregate statistics
GET /api/v1/accounts?type=&limit=&offset= Paginated account list
GET /api/v1/accounts/{id} Full account detail
GET /api/v1/accounts/{id}/reputation Reputation graph
GET /api/v1/accounts/{id}/relationships?type=&confirmed=&mutual= Relationships by category
GET /api/v1/search?q=&tags=&sort=&limit=&offset= Search accounts

Test plan

  • go build ./... compiles cleanly
  • go test ./... — all existing tests pass (including handler tests after BSN extraction)
  • make swagger generates OpenAPI spec
  • make dev — start server and verify Swagger UI loads at http://localhost:8080/swagger/index.html
  • Test each endpoint via Swagger UI or curl
  • Verify HTML site still works at /

🤖 Generated with Claude Code

xdefrag and others added 4 commits February 9, 2026 11:43
Add a JSON REST API at /api/v1/* with Swagger UI at /swagger/ for
programmatic access to Lore's account, relationship, reputation, and
statistics data.

New endpoints:
- GET /api/v1/stats - aggregate statistics
- GET /api/v1/accounts - paginated account list with type filter
- GET /api/v1/accounts/{id} - full account detail
- GET /api/v1/accounts/{id}/reputation - reputation graph
- GET /api/v1/accounts/{id}/relationships - relationships by category
- GET /api/v1/search - search accounts by name/tags

Extract BSN (Business Social Network) relationship logic into shared
internal/bsn package for reuse between HTML handler and API handler.
Add CountPersons/CountCorporate/CountSynthetic and GetAccountMetadata
repository methods for API pagination and detail responses.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Buffer JSON encoding to prevent partial responses on error
- Add Stellar account ID format validation to detail endpoints
- Add 404 responses for non-existent accounts with existence check
- Replace broken listAll() 3-query approach with single GetAllAccounts query
- Populate trustlines from account_balances table in detail response
- Fix synthetic type detection to require both MTLAP=0 and MTLAC=0
- Make BSN package-level vars unexported to prevent external mutation
- Regenerate Swagger docs with 404 response annotations

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add AccountExists checks to GetRelationships and GetReputation
  endpoints to honor the 404 contract documented in Swagger
- Add search query length validation (max 100 chars) and tag length
  validation matching the web handler
- Discard too-short queries (<2 chars) while preserving tag-only search
- Extract validateAccountID, inferAccountType, convertCategories, and
  convertRelationship helpers to eliminate duplication
- Unify account type classification between listAll and Search via
  shared inferAccountType helper
- Simplify tag parsing with lo.FilterMap (trim-before-filter)
- Regenerate Swagger docs with 400 response for search endpoint

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The basePath was /api/v1 while route annotations already included the
full /api/v1/* paths, causing Swagger UI to send requests to
/api/v1/api/v1/stats which fell through to the HTML catch-all handler.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@xdefrag
xdefrag merged commit 61a4fe8 into master Feb 9, 2026
3 checks passed
@xdefrag
xdefrag deleted the feat/rest-api-swagger branch February 9, 2026 11:21
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