docs: OpenAPI examples for usage endpoints - #860
Merged
greatest0fallt1me merged 1 commit intoJul 27, 2026
Conversation
Add named OpenAPI 3.1 example payloads for all usage endpoint responses: GET /api/usage - 200: withEvents, withBuckets, empty, withCursorPagination - 400: invalidDateRange, invalidGroupBy, invalidCursor - 401: missingToken, expiredToken - 500: internalError GET /api/usage/sse - 200 text/event-stream: connected, usageEvent - 401: missingToken GET /api/usage/by-endpoint - 200: topEndpoints, filteredByApi, empty (replaces single anonymous example) - 400: invalidDateRange, invalidLimit, invalidDate - 401: missingToken - 500: internalError Also extends UsageResponse schema with pagination and requestId fields that are present in the live response but were missing from the spec. Add src/routes/usage.openapi.test.ts with 37 contract tests verifying every named example exists and has the correct structure. Closes CalloraOrg#650
|
@christy-dev4 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
LGTM ✅ solid work — thanks for taking this on! |
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.
OpenAPI Examples for Usage Endpoints
Summary
Adds named OpenAPI 3.1 example payloads to every response status code for the three usage-related API paths:
/api/usagewithEvents,withBuckets,empty,withCursorPagination(200);invalidDateRange,invalidGroupBy,invalidCursor(400);missingToken,expiredToken(401);internalError(500)/api/usage/sseconnected,usageEvent(200 text/event-stream);missingToken(401)/api/usage/by-endpointexampleon 200 onlytopEndpoints,filteredByApi,empty(200);invalidDateRange,invalidLimit,invalidDate(400);missingToken(401);internalError(500)Also extends the
UsageResponseschema withpaginationandrequestIdfields that are already present in the live API response but were missing from the spec.This is part of the GrantFox FWC26 campaign (Stellar Wave) documentation work.
What Changed
docs/openapi.jsonGET /api/usage— full named examples added200 —
withEvents— typical two-event response includingpaginationandrequestId200 —
withBuckets— response withstats.buckets(used whengroupByis supplied)200 —
empty— zero-event response with zeroed stats200 —
withCursorPagination— cursor-paginated response showingpagination.nextCursor400 —
invalidDateRange—fromafterto400 —
invalidGroupBy— unrecognisedgroupByenum value400 —
invalidCursor— malformed base64 cursor401 —
missingToken— noAuthorizationheader401 —
expiredToken— JWT token expired (TOKEN_EXPIRED)500 —
internalError— generic internal server errorGET /api/usage/sse— named examples added to both responses200 (text/event-stream) —
connected— initialevent: connectedSSE frame200 (text/event-stream) —
usageEvent—event: usageSSE frame with full event payload401 —
missingToken— standardised error envelopeGET /api/usage/by-endpoint— anonymousexamplereplaced by namedexamplesThe pre-existing anonymous
exampleon the 200 response was replaced by three named examples:200 —
topEndpoints— two endpoints ranked descending by call count200 —
filteredByApi— single endpoint result whenapiIdfilter is applied200 —
empty— emptydataarray for a period with no calls400 —
invalidDateRange,invalidLimit,invalidDate— each validator error401 —
missingToken— standardised error envelope500 —
internalError— standardised error envelopeUsageResponseschema extendedpaginationproperty (object; shape varies by pagination mode)requestIdstring propertydescriptionannotations to all existing properties for claritysrc/routes/usage.openapi.test.ts(new)37-test OpenAPI contract suite covering all three paths, verifying:
withEvents: event objects have the five required fields with correct typeswithBuckets:stats.bucketsis present and well-formedempty:eventsis[],totalCallsis0withCursorPagination:pagination.nextCursoris a non-empty stringpaginationandrequestIdsuccess: falseand typederror.code/error.messageevent: connected/event: usageby-endpointtopEndpointsitems are descending by call countUsageResponseschema definespaginationandrequestIdresponseskeys inside status-code objectsTest Results
Checklist
/api/usage/sseexampleon/api/usage/by-endpoint200 upgraded to namedexamplesUsageResponseschema extended withpaginationandrequestIddocs/openapi.jsonis valid JSON (verified)Closes #650