Skip to content

Commit 63f6cf2

Browse files
committed
docs: Update OpenAPI docs, adding descriptions and examples to everything
1 parent e03269b commit 63f6cf2

File tree

6 files changed

+118
-14
lines changed

6 files changed

+118
-14
lines changed

src/@types/modules.d.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ declare module "*.gql" {
44
}
55

66
declare module "*.tmpl" {
7-
const content: string;
8-
export default content;
7+
const text: string;
8+
export default text;
9+
}
10+
11+
declare module "*.md" {
12+
const text: string;
13+
export default text;
914
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Overview
2+
3+
As of right now, there the WXT Queue API is free to use with no authentication requirements.
4+
5+
> [!IMPORTANT]
6+
> If you want to keep it this way, **be respectful of how you use it**. Do not spam or abuse it.
7+
8+
<br/>
9+
10+
## REST vs GraphQL
11+
12+
The WXT Queue API is mostly a GraphQL API, with a few REST endpoints. This document covers all the REST endpoints, including the one used to make GraphQL requests.

src/assets/graphql-description.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
To play around with the GraphQL API, checkout the [GraphiQL Playground](/playground).

src/routes/grpahql-routes.ts

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,67 @@ export const graphqlRoutes = createApp()
1515
.post(
1616
"/api",
1717
{
18-
body: z.object({
19-
query: z.string(),
20-
variables: z.record(z.string(), z.any()).optional(),
21-
operationName: z.string().optional(),
22-
}),
23-
response: z.any(),
18+
summary: "Send Query",
19+
tags: ["GraphQL"],
20+
description:
21+
"Send a query to the GraphQL API. You can play around with queries on the [GraphiQL playground](/playground).",
22+
body: z
23+
.object({
24+
query: z.string(),
25+
variables: z.record(z.string(), z.any()).optional(),
26+
operationName: z.string().optional(),
27+
})
28+
.meta({
29+
example: {
30+
query: `query GetExtension($id: String!) {
31+
chromeExtension(id: $id) {
32+
id
33+
screenshots { rawUrl }
34+
}
35+
}`,
36+
variables: {
37+
id: "ocfdgncpifmegplaglcnglhioflaimkd",
38+
},
39+
operationName: "GetExtension",
40+
},
41+
}),
42+
response: z
43+
.object({
44+
data: z.any(),
45+
})
46+
.meta({
47+
example: {
48+
data: {
49+
chromeExtension: {
50+
id: "ocfdgncpifmegplaglcnglhioflaimkd",
51+
screenshots: [
52+
{
53+
rawUrl:
54+
"https://lh3.googleusercontent.com/GUgh0ThX2FDPNvbaumYl4DqsUhsbYiCe-Hut9FoVEnkmTrXyA-sHbMk5jmZTj_t-dDP8rAmy6X6a6GNTCn9F8zo4VYU=s1280",
55+
},
56+
{
57+
rawUrl:
58+
"https://lh3.googleusercontent.com/qRi-kO0il8W6CnWa_-7oFzCwWKwr73w607I-rpYF9MM27omsuoN0k4dkgBbBECD3vZszdTSkQnoW9sywsfvAQ_7M9Q=s1280",
59+
},
60+
],
61+
},
62+
},
63+
},
64+
}),
2465
},
2566
({ request, body }) => graphql.evaluateQuery(request.method, body),
2667
)
27-
.get("/playground", ({ set }) => {
28-
set.headers["Content-Type"] = "text/html; charset=utf-8";
29-
return PLAYGROUND_HTML;
30-
});
68+
.get(
69+
"/playground",
70+
{
71+
summary: "Playground",
72+
tags: ["GraphQL"],
73+
description:
74+
"Open the GraphiQL playground. This is where you can interact and test out the GraphQL API. It also contains the GraphQL documentation explorer.",
75+
response: z.string().meta({ contentType: "text/html" }),
76+
},
77+
({ set }) => {
78+
set.headers["Content-Type"] = "text/html; charset=utf-8";
79+
return PLAYGROUND_HTML;
80+
},
81+
);

src/routes/rest-routes.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ export const restRoutes = createApp()
99
.get(
1010
"/api/rest/chrome-extensions/:id/screenshots/:index",
1111
{
12+
summary: "Redirect to Screenshot",
13+
tags: ["Chrome Extensions"],
14+
description:
15+
"Redirect to a screenshot's URL from the Chrome Web Store listing",
1216
params: z.object({
1317
id: z.string(),
1418
index: z.coerce.number().int().min(0),
@@ -29,6 +33,10 @@ export const restRoutes = createApp()
2933
.get(
3034
"/api/rest/firefox-addons/:addonId/screenshots/:index",
3135
{
36+
summary: "Redirect to Screenshot",
37+
tags: ["Firefox Addons"],
38+
description:
39+
"Redirect to a screenshot's URL from the Firefox Addons listing.",
3240
params: z.object({
3341
addonId: z.string(),
3442
index: z.coerce.number().int().min(0),

src/server.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,24 @@ import { graphqlRoutes } from "./routes/grpahql-routes";
55
import { restRoutes } from "./routes/rest-routes";
66
import { zodSchemaAdapter } from "@aklinker1/zeta/adapters/zod-schema-adapter";
77
import { version } from "../package.json";
8+
import { z } from "zod/v4";
9+
import API_REFERENCE_DESCRIPTION from "./assets/api-reference-description.md" with { type: "text" };
10+
import GRAPHQL_DESCRIPTION from "./assets/graphql-description.md" with { type: "text" };
811

912
const app = createApp({
1013
schemaAdapter: zodSchemaAdapter,
1114
openApi: {
1215
info: {
1316
title: "WXT Queue API Reference",
1417
version,
18+
description: API_REFERENCE_DESCRIPTION,
1519
},
20+
tags: [
21+
{ name: "GraphQL", description: GRAPHQL_DESCRIPTION },
22+
{ name: "Chrome Extensions" },
23+
{ name: "Firefox Addons" },
24+
{ name: "System" },
25+
],
1626
},
1727
})
1828
.onError(({ error }) => void consola.error(error))
@@ -21,11 +31,28 @@ const app = createApp({
2131
.use(graphqlRoutes)
2232
.get(
2333
"/",
24-
{ description: "Redirect to the GraphQL Playground" },
34+
{
35+
summary: "API Docs Redirect",
36+
tags: ["System"],
37+
description: "Redirect to the API reference when visiting the root URL.",
38+
},
2539
({ set }) => {
2640
set.status = 302;
27-
set.headers.Location = "/playground";
41+
set.headers.Location = "/scalar";
42+
},
43+
)
44+
.get(
45+
"/api/health",
46+
{
47+
summary: "Health Check",
48+
tags: ["System"],
49+
description: "Used to make sure the API is up and running.",
50+
response: z.object({
51+
status: z.literal("ok"),
52+
version: z.string(),
53+
}),
2854
},
55+
() => ({ status: "ok" as const, version }),
2956
);
3057

3158
export default app;

0 commit comments

Comments
 (0)