Fix OpenAPI docs#1375
Conversation
Greptile SummaryThis PR corrects the rswag-generated OpenAPI docs by fixing the most common mistake in OpenAPI 3.0 security declarations (conjunctive AND vs. disjunctive OR), removing non-API browser and Slack-command paths, and adding missing public endpoint specs.
Confidence Score: 4/5Safe to merge; all changes are OpenAPI documentation only — no application logic is touched. The email and Slack UID lookup endpoints retain 'Requires STATS_API_KEY' in their descriptions but now only advertise Bearer auth in the security block, while the equivalent admin stats endpoint correctly lists both Bearer and ApiKeyAuth as alternatives. This inconsistency will mislead API consumers who rely on the generated docs to know which credentials are accepted for those two endpoints. spec/requests/api/v1/users_spec.rb — verify whether the email/Slack lookup endpoints truly accept only Bearer or also accept STATS_API_KEY (ApiKeyAuth), and align the security declaration with the description. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[API Request] --> B{Endpoint type?}
B -->|Public| C[No auth required]
B -->|Authenticated /api/v1/| D{Auth method?}
B -->|WakaTime-compat| E{Auth method?}
B -->|Admin endpoints| F{Auth method?}
D -->|Bearer token| G[Accepted]
D -->|OR BasicApiKey| G
E -->|Bearer token| G
E -->|OR ApiKeyAuth| G
F -->|Bearer token| G
F -->|OR ApiKeyAuth| G
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
spec/requests/api/v1/users_spec.rb:7-8
Security scheme inconsistency on admin lookup endpoints: both `/api/v1/users/{email}/lookup` and `/api/v1/users/{slack_uid}/lookup` still say "Requires STATS_API_KEY" in their descriptions, but their security was narrowed to only `Bearer: []`. Compare with `/api/v1/stats`, which correctly documents both alternatives as `{ Bearer: [] }, { ApiKeyAuth: [] }`. If STATS_API_KEY is the intended auth method for these endpoints, consumers reading the OpenAPI docs will incorrectly believe only a Bearer token is accepted.
```suggestion
description 'Find a user ID by their email address. Useful for integrations that need to map emails to Hackatime users. Requires STATS_API_KEY.'
security [ { Bearer: [] }, { ApiKeyAuth: [] } ]
```
### Issue 2 of 2
spec/requests/api/v1/users_spec.rb:49-50
Same inconsistency for the Slack UID lookup — description says "Requires STATS_API_KEY" but security is `Bearer`-only, unlike the stats endpoint pattern.
```suggestion
description 'Find a user ID by their Slack User ID. Requires STATS_API_KEY.'
security [ { Bearer: [] }, { ApiKeyAuth: [] } ]
```
Reviews (1): Last reviewed commit: "Fix OpenAPI docs" | Re-trigger Greptile |
- Revert incorrect dual-auth on /api/v1/users/lookup_* endpoints; the controller disables ?api_key= query, so Bearer-only security is correct. - Remove duplicate path declarations between users_spec and stats_spec (trust_factor, projects, project/:name, projects/details, heartbeats/spans) -- kept in stats_spec since controller is StatsController. - Remove duplicate /user/info and /user/heartbeats path declarations from admin_users_spec (kept in admin_user_utils_spec). - admin_user_utils_spec: fix /user/stats schema (date -> start_date/end_date); add trust_level and notes to /user/convict request body; delete redundant third response(200) block on /heartbeats/by_user_agent_segment; remove nullable: true from lineno/cursorpos (controller coerces to 0). - admin_timeline_spec: delete duplicated dead schema declaration in /timeline response block. - compatibility_spec: add accepted heartbeat keys to request body schema (created_at, dependencies, editor, line_additions, line_deletions, machine, operating_system, project_root_count, user_agent, plugin). - internal_spec: remove nullable: true from owner_email/key_name (controller uses compact_blank, so absent keys are omitted, not null). - summary_spec: document additional accepted query params (from, to, range). Skipped (flagged for follow-up): - summary_controller.rb:27 uses params[:user] vs params[:user_id] -- looks like a controller bug, not a doc bug. - internal_spec.rb:52 test assertion may contradict controller behavior. - compatibility_spec.rb Basic auth scheme would require defining a new scheme in swagger_helper.rb. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary of the problem
The generated OpenAPI docs included browser-only and Slack webhook routes, and several API endpoints had incorrect auth/security metadata.
Describe your changes
swagger/v1/swagger.yamlfrom the updated rswag specs.Validation:
docker compose exec web env RAILS_ENV=test bin/rails rswag:specs:swaggerize(114 examples, 0 failures)Screenshots / Media
Not included; this changes generated API documentation.