Skip to content

Commit bebe6b7

Browse files
author
Rajat
committed
openapi doc in doc site
1 parent 79a4a82 commit bebe6b7

3 files changed

Lines changed: 50 additions & 23 deletions

File tree

apps/docs/app/(home)/[[...slug]]/page.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@ import {
77
} from "fumadocs-ui/page";
88
import { createRelativeLink } from "fumadocs-ui/mdx";
99
import { notFound, redirect } from "next/navigation";
10+
import { APIPage } from "@/components/api-page";
1011
import { getMDXComponents } from "@/mdx-components";
1112

12-
const API_REFERENCE_INDEX = "/api-reference/listContacts";
13+
const API_REFERENCE_INDEX = "/api-reference/contacts/get";
1314

1415
export default async function Page(props: {
1516
params: Promise<{ slug?: string[] }>;
1617
}) {
1718
const params = await props.params;
18-
process.stderr.write(
19-
`Rendering docs slug: ${(params.slug ?? []).join("/") || "index"}\n`,
20-
);
2119
const slugPath = params.slug?.join("/");
2220

2321
if (slugPath === "api-reference" || slugPath === "rest-api") {
@@ -27,6 +25,18 @@ export default async function Page(props: {
2725
const page = source.getPage(params.slug);
2826
if (!page) notFound();
2927

28+
if (page.data.type === "openapi") {
29+
return (
30+
<DocsPage full>
31+
<DocsTitle>{page.data.title}</DocsTitle>
32+
<DocsDescription>{page.data.description}</DocsDescription>
33+
<DocsBody>
34+
<APIPage {...page.data.getAPIPageProps()} />
35+
</DocsBody>
36+
</DocsPage>
37+
);
38+
}
39+
3040
const MDXContent = page.data.body;
3141

3242
return (
@@ -54,7 +64,12 @@ export async function generateStaticParams() {
5464
}
5565
const bySlug = new Map<string, { slug?: string[] }>();
5666

57-
for (const param of [{ slug: [] as string[] }, ...params]) {
67+
for (const param of [
68+
{ slug: [] as string[] },
69+
...params,
70+
{ slug: ["api-reference"] },
71+
{ slug: ["rest-api"] },
72+
]) {
5873
bySlug.set((param.slug ?? []).join("/"), param);
5974
}
6075

apps/docs/lib/openapi.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,58 +24,60 @@ const openApiDocument = generateOpenApi(
2424
tags: [
2525
{
2626
name: "Contacts",
27-
description: "Manage contacts and segmentation.",
27+
description: "Manage contacts (subscribers).",
28+
},
29+
{
30+
name: "Segments",
31+
description:
32+
"Saved, named, reusable contact filters - build a filter once, reuse it across broadcasts and sequences.",
2833
},
2934
{ name: "Templates", description: "Reusable email templates." },
3035
{
3136
name: "Sequences",
3237
description:
33-
"Broadcasts and multi-step, event-triggered sequences.",
38+
"Broadcasts (one-off) and sequences (multi-step, event-triggered).",
3439
},
3540
{
3641
name: "Settings",
3742
description:
38-
"Per-team settings, including SMTP configuration and test sends.",
43+
"Per-team settings, including email sending provider (SMTP) configuration and test sends.",
3944
},
4045
{
4146
name: "Teams",
4247
description:
43-
"Team management, API keys, and server-to-server provisioning.",
48+
"Team management (list/create/rename/delete), per-team API keys, and server-to-server provisioning.",
4449
},
4550
],
4651
components: {
4752
securitySchemes: {
48-
OAuth2: {
49-
type: "oauth2",
50-
flows: {
51-
authorizationCode: {
52-
authorizationUrl: "/oauth/authorize",
53-
tokenUrl: "/oauth/token",
54-
scopes: {},
55-
},
56-
},
57-
},
5853
apiKeyAuth: {
5954
type: "apiKey",
6055
in: "header",
6156
name: "x-sendlit-apikey",
6257
},
58+
bearerAuth: {
59+
type: "http",
60+
scheme: "bearer",
61+
bearerFormat: "JWT",
62+
},
6363
provisioningSecretAuth: {
6464
type: "apiKey",
6565
in: "header",
6666
name: "X-Sendlit-Provisioning-Secret",
6767
},
6868
},
6969
},
70-
security: [{ OAuth2: [] }, { apiKeyAuth: [] }],
70+
security: [{ apiKeyAuth: [] }, { bearerAuth: [] }],
7171
},
7272
{
73-
setOperationId: true,
7473
operationMapper: (operation, route) => {
7574
const path = (route as { path?: string }).path;
7675

7776
return {
7877
...operation,
78+
tags: (route.metadata as { tag?: string } | undefined)?.tag
79+
? [(route.metadata as { tag: string }).tag]
80+
: operation.tags,
7981
security:
8082
path === "/provisioning/teams"
8183
? [{ provisioningSecretAuth: [] }]

apps/docs/lib/source.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import { createElement } from "react";
22
import { icons } from "lucide-react";
3-
import { loader } from "fumadocs-core/source";
3+
import { loader, multiple } from "fumadocs-core/source";
4+
import { openapiPlugin, openapiSource } from "fumadocs-openapi/server";
45
import { docs } from "../.source/server";
6+
import { openapi } from "@/lib/openapi";
7+
8+
const apiSource: any = await openapiSource(openapi, {
9+
baseDir: "api-reference",
10+
});
511

612
export const source: any = loader({
713
baseUrl: "/",
8-
source: docs.toFumadocsSource() as any,
14+
source: multiple({
15+
docs: docs.toFumadocsSource() as any,
16+
openapi: apiSource,
17+
}) as any,
18+
plugins: [openapiPlugin()],
919
icon(icon) {
1020
if (icon && icon in icons) {
1121
return createElement(icons[icon as keyof typeof icons]);

0 commit comments

Comments
 (0)