Skip to content

Commit c8d5391

Browse files
committed
add API docs
1 parent baf391b commit c8d5391

File tree

15 files changed

+772
-91
lines changed

15 files changed

+772
-91
lines changed

app/[[...path]]/page.tsx

Lines changed: 37 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,20 @@ import {getMDXComponent} from 'mdx-bundler/client';
33
import {Metadata} from 'next';
44
import {notFound} from 'next/navigation';
55

6-
import {Breadcrumbs} from 'sentry-docs/components/breadcrumbs';
7-
import {CodeContextProvider} from 'sentry-docs/components/codeContext';
8-
import {GitHubCTA} from 'sentry-docs/components/githubCta';
9-
import {Header} from 'sentry-docs/components/header';
6+
import {apiCategories} from 'sentry-docs/build/resolveOpenAPI';
7+
import {ApiCategoryPage} from 'sentry-docs/components/apiCategoryPage';
8+
import {ApiPage} from 'sentry-docs/components/apiPage';
9+
import {DocPage} from 'sentry-docs/components/docPage';
1010
import {Home} from 'sentry-docs/components/home';
1111
import {Include} from 'sentry-docs/components/include';
12-
import {Navbar} from 'sentry-docs/components/navbar';
1312
import {PlatformContent} from 'sentry-docs/components/platformContent';
14-
import {PlatformSdkDetail} from 'sentry-docs/components/platformSdkDetail';
15-
import {ServerSidebar} from 'sentry-docs/components/serverSidebar';
16-
import {TableOfContents} from 'sentry-docs/components/tableOfContents';
17-
import {docsRootNode, getCurrentPlatformOrGuide, nodeForPath} from 'sentry-docs/docTree';
18-
import {allDocsFrontMatter, getFileBySlug} from 'sentry-docs/mdx';
13+
import {getDocsRootNode, nodeForPath} from 'sentry-docs/docTree';
14+
import {getDocsFrontMatter, getFileBySlug} from 'sentry-docs/mdx';
1915
import {mdxComponents} from 'sentry-docs/mdxComponents';
20-
import {serverContext, setServerContext} from 'sentry-docs/serverContext';
16+
import {setServerContext} from 'sentry-docs/serverContext';
2117

22-
export function generateStaticParams() {
23-
const docs = allDocsFrontMatter;
18+
export async function generateStaticParams() {
19+
const docs = await getDocsFrontMatter();
2420
const paths = docs.map(doc => {
2521
let path = doc.slug.split('/');
2622
if (path[path.length - 1] === 'index') {
@@ -39,68 +35,12 @@ export const dynamic = 'force-static';
3935
const mdxComponentsWithWrapper = mdxComponents(
4036
{Include, PlatformContent},
4137
({children, frontMatter, toc}) => (
42-
<Layout frontMatter={frontMatter} toc={toc}>
38+
<DocPage frontMatter={frontMatter} toc={toc}>
4339
{children}
44-
</Layout>
40+
</DocPage>
4541
)
4642
);
4743

48-
function Layout({children, frontMatter, toc}) {
49-
const {rootNode, path} = serverContext();
50-
const platformOrGuide = rootNode && getCurrentPlatformOrGuide(rootNode, path);
51-
const hasToc = !frontMatter.notoc || !!platformOrGuide;
52-
53-
return (
54-
<div className="document-wrapper">
55-
<div className="sidebar">
56-
<Header />
57-
58-
<div
59-
className="d-md-flex flex-column align-items-stretch collapse navbar-collapse"
60-
id="sidebar"
61-
>
62-
<div className="toc">
63-
<div className="text-white p-3">
64-
<ServerSidebar />
65-
</div>
66-
</div>
67-
</div>
68-
<div className="d-sm-none d-block" id="navbar-menu" />
69-
</div>
70-
<main role="main" className="px-0">
71-
<div className="flex-grow-1">
72-
<div className="d-block navbar-right-half">
73-
<Navbar />
74-
</div>
75-
76-
<section className="pt-3 px-3 content-max prose">
77-
<div className="pb-3">
78-
<Breadcrumbs />
79-
</div>
80-
<div className="row">
81-
<div className={hasToc ? 'col-sm-8 col-md-12 col-lg-8 col-xl-9' : 'col-12'}>
82-
<h1 className="mb-3">{frontMatter.title}</h1>
83-
<div id="main">
84-
<CodeContextProvider>{children}</CodeContextProvider>
85-
</div>
86-
<GitHubCTA />
87-
</div>
88-
{hasToc && (
89-
<div className="col-sm-4 col-md-12 col-lg-4 col-xl-3">
90-
<div className="page-nav">
91-
<PlatformSdkDetail />
92-
<TableOfContents toc={toc} />
93-
</div>
94-
</div>
95-
)}
96-
</div>
97-
</section>
98-
</div>
99-
</main>
100-
</div>
101-
);
102-
}
103-
10444
function MDXLayoutRenderer({mdxSource, ...rest}) {
10545
const MDXLayout = useMemo(() => getMDXComponent(mdxSource), [mdxSource]);
10646
return <MDXLayout components={mdxComponentsWithWrapper} {...rest} />;
@@ -112,13 +52,35 @@ export default async function Page({params}) {
11252
}
11353

11454
// get frontmatter of all docs in tree
115-
const docs = allDocsFrontMatter;
116-
const rootNode = docsRootNode;
55+
const docs = await getDocsFrontMatter();
56+
const rootNode = await getDocsRootNode();
11757
if (!rootNode) {
11858
console.warn('no root node');
11959
return notFound();
12060
}
12161

62+
// TODO(mjq): Remove this hacky second call to setServerContext.
63+
setServerContext({
64+
rootNode,
65+
path: params.path,
66+
toc: [],
67+
frontmatter: {},
68+
});
69+
70+
if (params.path[0] === 'api' && params.path.length > 1) {
71+
const categories = await apiCategories();
72+
const category = categories.find(c => c.slug === params.path[1]);
73+
if (category) {
74+
if (params.path.length === 2) {
75+
return <ApiCategoryPage category={category} />;
76+
}
77+
const api = category.apis.find(a => a.slug === params.path[2]);
78+
if (api) {
79+
return <ApiPage api={api} />;
80+
}
81+
}
82+
}
83+
12284
const pageNode = nodeForPath(rootNode, params.path);
12385
if (!pageNode) {
12486
console.warn('no page node', params.path);
@@ -162,10 +124,10 @@ type MetadataProps = {
162124
};
163125
};
164126

165-
export function generateMetadata({params}: MetadataProps): Metadata {
127+
export async function generateMetadata({params}: MetadataProps): Promise<Metadata> {
166128
let title = 'Home';
167129

168-
const rootNode = docsRootNode;
130+
const rootNode = await getDocsRootNode();
169131
if (rootNode && params.path) {
170132
const pageNode = nodeForPath(rootNode, params.path);
171133
if (pageNode) {

app/not-found.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import 'prism-sentry/index.css';
33
import {Header} from 'sentry-docs/components/header';
44
import {Navbar} from 'sentry-docs/components/navbar';
55
import {productSidebar} from 'sentry-docs/components/serverSidebar';
6-
import {docsRootNode} from 'sentry-docs/docTree';
6+
import {getDocsRootNode} from 'sentry-docs/docTree';
77

88
import 'sentry-docs/styles/screen.scss';
99

10-
export default function NotFound() {
11-
const rootNode = docsRootNode;
10+
export default async function NotFound() {
11+
const rootNode = await getDocsRootNode();
12+
1213
const sidebar = rootNode && productSidebar(rootNode);
1314
return (
1415
<div className="document-wrapper">

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"next": "14.0.1",
3333
"platformicons": "^5.9.2",
3434
"prism-sentry": "^1.0.2",
35+
"prismjs": "^1.27.0",
3536
"query-string": "^6.13.1",
3637
"react": "^18",
3738
"react-bootstrap": "^1.6.7",

public/favicon.ico

21.3 KB
Binary file not shown.

src/build/open-api/types.ts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
export type RequestBodySchema = {
2+
properties: {
3+
[key: string]: {description: string; type: string};
4+
};
5+
required: string[];
6+
type: string;
7+
};
8+
9+
export type Parameter = {
10+
description: string;
11+
in: string;
12+
name: string;
13+
required: boolean;
14+
schema: {
15+
enum: string[];
16+
format: string;
17+
type: string;
18+
items?: {[key: string]: {}};
19+
};
20+
};
21+
22+
type Markdown = {
23+
childMdx: {
24+
body: string;
25+
};
26+
};
27+
28+
type Tag = {
29+
description: string;
30+
externalDocs: {
31+
description: string;
32+
url: string;
33+
};
34+
name: string;
35+
};
36+
37+
export type DeRefedOpenAPI = {
38+
paths: {
39+
[key: string]: {
40+
[key: string]: {
41+
operationId: string;
42+
parameters: Parameter[];
43+
requestBody: {
44+
content: {
45+
'application/json': {
46+
example: any;
47+
schema: RequestBodySchema;
48+
};
49+
};
50+
required: boolean;
51+
};
52+
responses: {
53+
[key: string]: {
54+
content: {
55+
'application/json': {
56+
example: any;
57+
schema: any;
58+
};
59+
};
60+
description: string;
61+
};
62+
};
63+
summary: string;
64+
tags: string[];
65+
description?: string;
66+
security?: any;
67+
};
68+
};
69+
};
70+
tags: Tag[];
71+
};
72+
73+
export type ResponseContent = {
74+
content_type: string;
75+
example: string;
76+
examples: string;
77+
schema: string;
78+
};
79+
80+
export type Response = {
81+
content: ResponseContent | null;
82+
description: string;
83+
status_code: string;
84+
};
85+
86+
export type RequestBody = {
87+
content: {
88+
content_type: string;
89+
example: string;
90+
schema: string;
91+
};
92+
required: boolean;
93+
};
94+
95+
export type OpenApiPath = {
96+
apiPath: string;
97+
description: string;
98+
method: string;
99+
operationId: string;
100+
parameters: Parameter[];
101+
readableUrl: string;
102+
requestBody: RequestBody | null;
103+
responses: Response[];
104+
security: {[key: string]: string[]}[];
105+
summary: string | null;
106+
tags: string[];
107+
};
108+
109+
export type OpenAPI = {
110+
childOpenApiPathDescription: Markdown;
111+
childrenOpenApiBodyParameter: (Parameter & Markdown)[];
112+
childrenOpenApiPathParameter: (Parameter & Markdown)[];
113+
id: string;
114+
path: OpenApiPath;
115+
};

0 commit comments

Comments
 (0)