|
1 | 1 | --- |
2 | | -title: Speakeasy |
3 | | -description: Automate your SDK usage snippets in the API playground |
| 2 | +title: "Speakeasy" |
| 3 | +description: "Automate your SDK usage snippets in the API playground" |
4 | 4 | --- |
5 | 5 |
|
6 | | -You can integrate Speakeasy-generated code snippets from your SDKs directly into your Mintlify API reference documentation. SDK usage snippets are shown in the [interactive playground](https://mintlify.com/docs/api-playground/overview) of your Mintlify-powered documentation. |
| 6 | +Autogenerated code snippets from Speakeasy SDKs can be integrated directly into Mintlify API reference documentation. SDK usage snippets are shown in the [interactive playground](/api-playground/overview) of Mintlify-powered documentation sites. |
7 | 7 |
|
8 | | -## Speakeasy SDK Repository Changes |
| 8 | + |
9 | 9 |
|
10 | | -In your Speakeasy SDK repos, add the following to the `targets` section of your `.speakeasy/workflow.yaml` file to ensure code samples are automatically produced alongside SDK generations. |
| 10 | +## Prerequisites |
11 | 11 |
|
12 | | -```yaml .speakeasy/workflow.yaml |
13 | | -targets: |
14 | | - my-target: |
15 | | - target: typescript |
16 | | - source: my-source |
17 | | - codeSamples: |
18 | | - output: codeSamples.yaml |
19 | | -``` |
20 | | -
|
21 | | -Code samples will be generated in the form of an [OpenAPI overlay file](https://www.speakeasyapi.dev/openapi/overlays) that will be used in the Mintlify docs repository. |
22 | | -
|
23 | | -## Mintlify Docs Repository Changes |
| 12 | +To integrate Mintlify with Speakeasy, you'll need the following: |
24 | 13 |
|
25 | | -The workflow files produced will automatically bundle your source OpenAPI spec and Speakeasy code samples into a single output file, `openapi.yaml`. Mintlify will use this output file when constructing your API reference. |
| 14 | + - A [Mintlify documentation repository](/quickstart#creating-the-repository). |
| 15 | + - A Speakeasy-generated SDK with a configured [automated code sample URL](https://www.speakeasy.com/docs/code-samples/automated-code-sample-urls). |
26 | 16 |
|
27 | | -### Interactive CLI Set Up |
28 | | - |
29 | | -Run the following commands to set up the `.speakeasy/workflow.yaml` and `.github/workflows/sdk_generation.yaml` files through the interactive Speakeasy CLI. |
30 | | - |
31 | | -```bash |
32 | | -speakeasy configure sources |
33 | | -speakeasy configure github |
34 | | -``` |
| 17 | +## Setting up the integration |
35 | 18 |
|
36 | | -Set up your source spec. The source spec is the OpenAPI spec that code samples will be generated for, and it's often the same specification used to power Mintlify docs. |
| 19 | +To integrate Speakeasy with Mintlify, you must get the API's combined spec public URL from the registry and update your `docs.json` configuration file. |
37 | 20 |
|
38 | | - |
| 21 | +### Get the API's combined spec public URL from the registry |
39 | 22 |
|
40 | | -Add the overlay created by Speakeasy to inject code snippets into your spec. |
| 23 | +Navigate to your [Speakeasy Dashboard](https://app.speakeasy.com) and open the **API Registry** tab. Open the `*-with-code-samples` entry for the API. |
41 | 24 |
|
42 | | - |
| 25 | + |
43 | 26 |
|
44 | | -Provide a name and path for the OpenAPI spec. This will be the final spec used by Mintlify. |
| 27 | +<Note> |
| 28 | + If the entry is not labeled **Combined Spec**, ensure that the API has an [automatic code sample URL](https://www.speakeasy.com/docs/code-samples/automated-code-sample-urls) configured. |
| 29 | +</Note> |
45 | 30 |
|
46 | | - |
| 31 | +From the registry entry's page, copy the provided public URL. |
47 | 32 |
|
48 | | -Finally, Add your `SPEAKEASY_API_KEY` as a repository secret to your Minlify repo under `Settings > Secrets & Variables > Actions`. Find the Speakeasy API key in the Speakeasy dashboard under the **API Keys** tab. |
| 33 | + |
49 | 34 |
|
50 | | -## Manual Set Up |
| 35 | +### Update your `docs.json` configuration file |
51 | 36 |
|
52 | | -Alternatively, you can manually set up the following files in your Mintlify docs repo. |
| 37 | +Add the combined spec URL to an **Anchors** or **Tabs** section in your `docs.json` file. |
53 | 38 |
|
| 39 | +Add the combined spec URL to an anchor by updating the `anchor` field in your `docs.json` file as follows: |
54 | 40 |
|
55 | | -```yaml .speakeasy/workflow.yaml |
56 | | -workflowVersion: 1.0.0 |
57 | | -sources: |
58 | | - docs-source: |
59 | | - inputs: |
60 | | - - location: {{your_api_spec}} # local or remote references supported |
61 | | - overlays: |
62 | | - - location: https://raw.githubusercontent.com/{{your_sdk_repo_1}}/codeSamples.yaml |
63 | | - - location: https://raw.githubusercontent.com/{{your_sdk_repo_2}}/codeSamples.yaml |
64 | | - - location: https://raw.githubusercontent.com/{{your_sdk_repo_3}}/codeSamples.yaml |
65 | | - output: openapi.yaml |
66 | | -targets: {} |
| 41 | +```json docs.json |
| 42 | +{ |
| 43 | + "anchors": [ |
| 44 | + { |
| 45 | + "name": "API Reference", |
| 46 | + // !mark |
| 47 | + "openapi": "SPEAKEASY_COMBINED_SPEC_URL", |
| 48 | + "url": "api-reference", |
| 49 | + "icon": "square-terminal" |
| 50 | + } |
| 51 | + ] |
| 52 | +} |
67 | 53 | ``` |
68 | 54 |
|
69 | | -```yaml .speakeasy/workflows/sdk_generation.yaml |
70 | | -name: Generate |
71 | | -permissions: |
72 | | - checks: write |
73 | | - contents: write |
74 | | - pull-requests: write |
75 | | - statuses: write |
76 | | -"on": |
77 | | - workflow_dispatch: |
78 | | - inputs: |
79 | | - force: |
80 | | - description: Force generation of SDKs |
81 | | - type: boolean |
82 | | - default: false |
83 | | - schedule: |
84 | | - - cron: 0 0 * * * |
85 | | -jobs: |
86 | | - generate: |
87 | | - uses: speakeasy-api/sdk-generation-action/.github/workflows/workflow-executor.yaml@v15 |
88 | | - with: |
89 | | - force: ${{ github.event.inputs.force }} |
90 | | - mode: pr |
91 | | - speakeasy_version: latest |
92 | | - secrets: |
93 | | - github_access_token: ${{ secrets.GITHUB_TOKEN }} |
94 | | - speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }} |
| 55 | +Add the combined spec URL to a tab by updating the `tab` field in the `docs.json` file as follows: |
| 56 | + |
| 57 | +```json docs.json |
| 58 | +{ |
| 59 | + "tabs": [ |
| 60 | + { |
| 61 | + "name": "API Reference", |
| 62 | + "url": "api-reference", |
| 63 | + // !mark |
| 64 | + "openapi": "SPEAKEASY_COMBINED_SPEC_URL" |
| 65 | + } |
| 66 | + ] |
| 67 | +} |
95 | 68 | ``` |
96 | 69 |
|
97 | | -Finally, make sure you add your `SPEAKEASY_API_KEY` as a repository secret to your Minlify repo under `Settings > Secrets & Variables > Actions`. Find the Speakeasy API key in the Speakeasy dashboard under the **API Keys** tab. |
| 70 | +Speakeasy-generated code snippets can now be viewed in your API docs and interacted with in the playground. |
0 commit comments