feat: add REST API with OpenAPI/Swagger documentation - #22
Merged
Conversation
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>
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
/api/v1/*with 6 endpoints for programmatic access to accounts, relationships, reputation scores, and statistics/swagger/with auto-generated OpenAPI spec via swaggo/swaginternal/bsnpackage for reuse between HTML and API handlersCountPersons,CountCorporate,CountSynthetic) andGetAccountMetadatafor API pagination and detail responsesAPI Endpoints
/api/v1/stats/api/v1/accounts?type=&limit=&offset=/api/v1/accounts/{id}/api/v1/accounts/{id}/reputation/api/v1/accounts/{id}/relationships?type=&confirmed=&mutual=/api/v1/search?q=&tags=&sort=&limit=&offset=Test plan
go build ./...compiles cleanlygo test ./...— all existing tests pass (including handler tests after BSN extraction)make swaggergenerates OpenAPI specmake dev— start server and verify Swagger UI loads athttp://localhost:8080/swagger/index.html/🤖 Generated with Claude Code