Skip to content

Commit 00c3e2a

Browse files
committed
Sync open source content 🐝 (from 0d054534890b40fd8cd7123e992e93d3be4e9ba7)
1 parent 832966f commit 00c3e2a

File tree

1 file changed

+155
-0
lines changed

1 file changed

+155
-0
lines changed

docs/docs-md/getting-started.mdx

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
---
2+
title: Getting Started
3+
description: Learn how to get up and running with Docs MD
4+
hidden: true
5+
---
6+
7+
import { Callout } from "@/mdx/components";
8+
9+
# Getting Started with Docs MD
10+
11+
## Installation
12+
13+
Install docs from npm with:
14+
15+
```bash
16+
npm install @speakeasy-api/docs-md
17+
```
18+
19+
<Callout title="Warning for pnpm users" type="warning">
20+
If you use pnpm, you'll need to either run `pnpm add jotai motion` or `pnpm i --shamefully-hoist` to pick up some transient dependencies currently needed at the root of `node_modules`
21+
22+
This step is part of a temporary mechanism for getting sidebar styling to inherit properly, and will be removed before the public beta in July.
23+
24+
</Callout>
25+
26+
## Configuration
27+
28+
The first step in configuration is to create a file named `speakeasy.config.mjs`. This file can live anywhere, but convention is to put it beside other configuration files (e.g. `package.json`, `eslint.config.js`, etc.). Start by specifying the path to your OpenAPI spec file:
29+
30+
```ts
31+
export default {
32+
spec: "./my-openapi-spec.yaml",
33+
};
34+
```
35+
36+
The next step in configuration configuration of docs looks a little different for [Docusaurus](#docusaurus) vs [Nextra](#nextra). See the relevant section below for instructions.
37+
38+
Once core configuration is complete, check out [Try It Now](#try-it-now) for instructions on configuring live-querying of your backend from the docs.
39+
40+
### Docusaurus
41+
42+
For Docusaurus, you'll want to add this information to your speakeasy config file:
43+
44+
```ts
45+
export default {
46+
spec: "./my-openapi-spec.yaml",
47+
output: {
48+
framework: "docusaurus",
49+
pageOutDir: "./docs/api",
50+
componentOutDir: "./src/components/speakeasy",
51+
},
52+
};
53+
```
54+
55+
Let's go over what these properties do:
56+
57+
- `framework` tells docs to run some Docusaurus specific compilation, such as configuring `_category_.json` files for pages
58+
- `pageOutDir` sets the directory where we'll put `.mdx` files that represents a page
59+
- Assuming you are using the classic preset in `docusaurus.config.js` and have configured the docs option, then you want to pick somewhere in the `docs/` folder
60+
- We automatically configure `_category_.json` files for generated docs, so that these pages properly show up in the left sidebar nav
61+
- `componentOutDir` set the directory where we'll put supporting code
62+
- This code does not represent a page, and so should not go in the `docs/` folder
63+
64+
### Nextra
65+
66+
For Nextra, you'll want to add this information to your speakeasy config file
67+
68+
```ts
69+
export default {
70+
spec: "./my-openapi-spec.yaml",
71+
output: {
72+
framework: "nextra",
73+
pageOutDir: "./src/app/api",
74+
componentOutDir: "./src/components/speakeasy",
75+
},
76+
};
77+
```
78+
79+
Let's go over what these properties do:
80+
81+
- `framework` tells docs to run some Nextra specific compilation, such as configuring `_meta.ts` files for pages
82+
- `pageOutDir` sets the directory where we'll put `.mdx` files that represents a page
83+
- Assuming you are using the [documentation theme](https://nextra.site/docs/docs-theme/start), then you'll want to pick somewhere in `src/app`.
84+
- IMPORTANT: make sure _not_ to have a [route group](https://nextjs.org/docs/app/api-reference/file-conventions/route-groups) in the path to generated docs. Experimentation has shown that this breaks the left sidebar
85+
- We automatically configure `_meta.ts` files for generated docs, so that these pages properly show up in the left sidebar nav
86+
- `componentOutDir` set the directory where we'll put supporting code
87+
- This code does not represent a page, and so should not go in the `src/app` folder
88+
89+
### Common Display options
90+
91+
You can tweak how docs are displayed with the following properties:
92+
93+
- `showSchemasInNav`: whether or not to generate links to schemas in the left sidebar nav. Default `true`
94+
- `maxTypeSignatureLineLength`: controls when inline type signatures wrap into multiple lines. Default `80`
95+
- If you notice weird wrapping issues with inline type signatures, try increasing or decreasing this value. Otherwise, we recommend not setting this value
96+
- `maxSchemaNesting`: controls how deeply to nest schemas before breaking deeper schemas into the right popout
97+
98+
## Try It Now
99+
100+
If you would like to use the Try It Now feature, which allows users to live-query your backend using TypeScript code samples, you'll first need your SDK published to npm.
101+
102+
<Callout title="Note" type="info">
103+
We will add support for Try It Now without needing the SDK published to npm
104+
before docs reaches General Availability in August.
105+
</Callout>
106+
107+
To configure Try It Now, add the following to your `speakeasy.config.mjs` file:
108+
109+
```ts
110+
export default {
111+
...
112+
tryItNow: {
113+
npmPackageName: 'my-awesome-npm-package',
114+
sdkClassName: 'MyAwesomeClassName'
115+
}
116+
};
117+
```
118+
119+
Let's break down what these two properties do:
120+
121+
- `npmPackageName` is the name of the package containing a published version of your SDK
122+
- This name is what you would use with `npm install my-awesome-npm-package`
123+
- `sdkClassName` is the name of the main export from the npm package
124+
- This name is what you would use with `import { MyAwesomeClassName } from 'my-awesome-npm-package'`
125+
126+
<Callout title="Note" type="info">
127+
The current implementation of Try It Now is very new and has some rough edges.
128+
We'll work to polish this feature considerably before General Availability in
129+
August.
130+
</Callout>
131+
132+
<Callout title="Warning" type="warning">
133+
When enabling Try It Now, the spec used to build the npm package and the spec
134+
pointed to by `spec` in the config file *must* match, including overlays.
135+
Otherwise, code samples most likely will not run correctly due to naming
136+
mismatches.
137+
</Callout>
138+
139+
## Building
140+
141+
To build docs pages, add this to the `scripts` section of your `package.json`:
142+
143+
```json
144+
"build-api-docs": "docs-md",
145+
"prebuild": "npm run build-api-docs"
146+
```
147+
148+
Then, when you run `npm run build-api-docs` or `npm run build`, files in `pageOutDir` and `componentOutDir` will be update. This command supports a few flags:
149+
150+
- `-C` / `--clean`: delete the contents of page and component out directories
151+
- This flag is useful for removing pages that no longer exist, e.g. because you renamed an operation tag
152+
- `-c` / `--config`: specify the configuration file to use
153+
- By default, we look for the config file in directory that the command is run from, e.g. the same folder that `package.json` is in when building docs with npm scripts
154+
155+
Once docs files have been built, you can use the standard Docusaurus or Nextra scripts for previewing or building the site, e.g. `npm run dev` or `npm run build`.

0 commit comments

Comments
 (0)