Commit da88e4e
feat: add REST API endpoints for data sources (#125)
* feat: add REST API endpoints for data sources
Add RESTful API with GET endpoints for querying database data sources:
- GET /api/sources - List all configured data sources
- GET /api/sources/{source-id} - Get specific data source details
Implementation details:
- OpenAPI 3.0 spec-first approach with openapi-typescript for type generation
- Exposes source configuration (type, host, port, database, user, readonly, max_rows)
- Includes SSH tunnel configuration (host, port, user) without credentials
- Properly excludes sensitive fields (passwords, SSH keys)
- Returns 404 for non-existent sources
- Indicates default source with is_default flag
Technical changes:
- Added OpenAPI spec at src/api/openapi.yaml
- Implemented route handlers in src/api/sources.ts
- Extended ConnectorManager to store and expose SourceConfig objects
- Integrated routes into existing Express HTTP server
- Added generate:api-types script to build process
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* test: add integration tests for REST API endpoints
Add comprehensive integration tests for data sources API endpoints:
- GET /api/sources - list all sources
- GET /api/sources/{source-id} - get specific source
Test coverage:
- Validates response format matches OpenAPI schema
- Tests multiple data sources with different configurations
- Verifies is_default flag for first source
- Confirms readonly and max_rows settings are exposed
- Tests 404 error handling for non-existent sources
- Validates sensitive fields (passwords, SSH credentials) are excluded
- Tests URL-encoded source IDs and special characters
Technical details:
- Sets up Express server on test port (13579)
- Uses three in-memory SQLite databases for testing
- 14 tests passing, 1 skipped (SSH tunnel test)
- Clean setup and teardown of server and database connections
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* refactor: address code review feedback for REST API
Fix 5 issues identified in PR review:
1. Path parameter naming consistency
- Changed OpenAPI spec from {source-id} to {sourceId}
- Now matches Express route parameter naming convention
2. Remove unused variable
- Removed unused sourceIds in listSources function
- Cleaner code with no dead variables
3. Simplify redundant null checks
- Removed double validation in getSource handler
- Single check for sourceConfig is sufficient
- Improves code clarity and reduces duplication
4. Fix inconsistent null safety
- Removed .filter(Boolean) from getAllSourceConfigs
- Non-null assertion is safe due to synchronized Maps
- sourceIds and sourceConfigs are always in sync
5. Add type field validation
- Replace implicit type assumption with explicit check
- Throws clear error if type is missing
- Added comment explaining why type is guaranteed
All integration tests passing (14 tests).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* test: fix issues in integration tests
Address followup code review feedback:
1. Fix grammar error
- Changed "should include all database type" to "should include database type"
- Grammatically correct test description
2. Remove incomplete SSH test section
- Removed unused variables: managerWithSSH, appWithSSH, serverWithSSH
- Removed sourcesWithSSH constant
- Eliminated always-false conditions in cleanup code
- Removed non-functional beforeAll/afterAll hooks
- Removed skipped SSH tunnel test
The SSH test section had setup/teardown code but no actual implementation,
causing undefined variable warnings. Removed entirely until proper SSH test
infrastructure is available.
Test results: 14 tests passing (previously 14 passing + 1 skipped)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
---------
Co-authored-by: Claude <[email protected]>1 parent b1cda56 commit da88e4e
File tree
8 files changed
+963
-10
lines changed- src
- api
- __tests__
- connectors
8 files changed
+963
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
| 20 | + | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| 65 | + | |
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
| |||
0 commit comments