hackatime/spec/requests/api/summary_spec.rb
Tom (Deployor) 8d0215ff0f
feat: added actual api docs (rswag) + ci enforcement (#846)
* feat: add API documentation and CI checks

- Add Rswag for automated API documentation generation
- Add Swagger specs for all endpoints
- Add CI step to enforce that swagger.yaml stays in sync with code
- Add static test keys in seeds.rb for easier testing
- Update AGENTS.md and README.md to support this

* Merge branch 'main' of https://github.com/deployor/hackatime

* Merge branch 'main' into main

* Deprecations! Yay! :)

* It was wan addicent i swear linter! Dont hurt me

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Copilot..... we love you! Also this project is open and so are api docs meant to be if another AI reads ts!

* Merge branch 'main' of https://github.com/deployor/hackatime

* Merge branch 'main' into main

* Merge branch 'main' into main

* Update app/controllers/api/admin/v1/admin_controller.rb

If you say so

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update spec/requests/api/v1/my_spec.rb

I guessss?

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Failed my own CI wow.... EMBARRASSINGGGG

* Merge branch 'main' into main

* Merge branch 'main' into main

* clarify wording on internal/revoke

* Merge branch 'main' into main

* update swagger docs
2026-01-27 01:05:49 -05:00

73 lines
2.8 KiB
Ruby

require 'swagger_helper'
RSpec.describe 'Api::Summary', type: :request do
path '/api/summary' do
get('Get WakaTime-compatible summary') do
tags 'WakaTime Compatibility'
description 'Returns a summary of coding activity in a format compatible with WakaTime clients. This endpoint supports querying by date range, interval, or specific user (admin/privileged only).'
security [ Bearer: [], ApiKeyAuth: [] ]
produces 'application/json'
parameter name: :start, in: :query, type: :string, format: :date, description: 'Start date (YYYY-MM-DD)'
parameter name: :end, in: :query, type: :string, format: :date, description: 'End date (YYYY-MM-DD)'
parameter name: :interval, in: :query, type: :string, description: 'Interval (e.g. today, yesterday, week, month)'
parameter name: :project, in: :query, type: :string, description: 'Project name (optional)'
parameter name: :user, in: :query, type: :string, description: 'Slack UID of the user (optional, for admin use)'
response(200, 'successful') do
let(:Authorization) { "Bearer dev-api-key-12345" }
let(:api_key) { "dev-api-key-12345" }
let(:start) { '2023-01-01' }
let(:end) { '2023-01-31' }
let(:interval) { nil }
let(:project) { nil }
let(:user) { nil }
schema type: :object,
properties: {
user_id: { type: :string, nullable: true },
from: { type: :string, format: :date_time },
to: { type: :string, format: :date_time },
projects: {
type: :array,
items: {
type: :object,
properties: {
key: { type: :string },
total: { type: :number }
}
}
},
languages: {
type: :array,
items: {
type: :object,
properties: {
key: { type: :string },
total: { type: :number }
}
}
},
editors: { type: :object, nullable: true },
operating_systems: { type: :object, nullable: true },
machines: { type: :object, nullable: true },
categories: { type: :object, nullable: true },
branches: { type: :object, nullable: true },
entities: { type: :object, nullable: true },
labels: { type: :object, nullable: true }
}
run_test!
end
response(400, 'bad request') do
let(:Authorization) { "Bearer dev-api-key-12345" }
let(:api_key) { "dev-api-key-12345" }
let(:start) { 'invalid-date' }
let(:end) { '2023-01-31' }
let(:interval) { nil }
let(:project) { nil }
let(:user) { nil }
run_test!
end
end
end
end