Skip to content

Commit 44f859a

Browse files
committed
Sync open source content 🐝 (from dc6111f7ed20c9f27bfbd98ec6936d80f7ece581)
1 parent 68eef1d commit 44f859a

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

docs/sdks/guides/publish-specs-to-api-registry.mdx

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,110 @@ The API Registry can be used to:
8989
- Track changes to specs, view detailed change reports, and download past versions of the spec.
9090
- Create a stable public URL for sharing a particular revision of the spec.
9191
- Use the registry URI as a source for generating SDKs, for example: `registry.speakeasy.com/your-company/your-company/my-api`.
92+
93+
## Triggering downstream SDK generation
94+
95+
For teams that manage SDKs in separate repositories, the spec repo can trigger SDK generation in downstream repos when changes are made. This pattern is useful when:
96+
97+
- A central team manages the API specification
98+
- Multiple SDK repositories need to be generated from the same spec
99+
- SDK generation should be triggered automatically when the spec changes
100+
- SDK PRs should be created in downstream repos for review before merging
101+
102+
### Architecture overview
103+
104+
```
105+
┌─────────────────────────────────────────────────────────────────────────┐
106+
│ Spec Repository │
107+
│ ┌─────────────┐ ┌─────────────────────────────────────────────┐ │
108+
│ │ OpenAPI │ │ GitHub Actions Workflow │ │
109+
│ │ Spec │───▶│ 1. Runs `speakeasy run` to tag spec │ │
110+
│ │ (PR change) │ │ 2. Triggers downstream SDK workflows │ │
111+
│ └─────────────┘ │ 3. Updates PR comment with status │ │
112+
│ └─────────────────────────────────────────────┘ │
113+
└─────────────────────────────────────────────────────────────────────────┘
114+
115+
│ gh workflow run
116+
117+
┌─────────────────────────────────────────────────────────────────────────┐
118+
│ Downstream SDK Repos │
119+
│ ┌──────────────────────────┐ ┌──────────────────────────┐ │
120+
│ │ TypeScript SDK │ │ Python SDK │ │
121+
│ │ - Pulls tagged spec │ │ - Pulls tagged spec │ │
122+
│ │ - Generates SDK │ │ - Generates SDK │ │
123+
│ │ - Creates PR │ │ - Creates PR │ │
124+
│ └──────────────────────────┘ └──────────────────────────┘ │
125+
└─────────────────────────────────────────────────────────────────────────┘
126+
```
127+
128+
### Setting up downstream SDK repositories
129+
130+
Each downstream SDK repository needs a workflow that accepts `workflow_dispatch` inputs. After running `speakeasy configure github`, modify the generated workflow to accept these inputs:
131+
132+
```yaml
133+
on:
134+
workflow_dispatch:
135+
inputs:
136+
force:
137+
description: "Force SDK regeneration"
138+
required: false
139+
default: "false"
140+
feature_branch:
141+
description: "Branch for SDK changes"
142+
required: false
143+
environment:
144+
description: "Environment variables (e.g., TAG=branch-name)"
145+
required: false
146+
```
147+
148+
Pass these inputs to the workflow executor:
149+
150+
```yaml
151+
jobs:
152+
generate:
153+
uses: speakeasy-api/sdk-generation-action/.github/workflows/workflow-executor.yaml@v15
154+
with:
155+
mode: pr
156+
force: ${{ inputs.force }}
157+
feature_branch: ${{ inputs.feature_branch }}
158+
environment: ${{ inputs.environment }}
159+
secrets:
160+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
161+
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
162+
```
163+
164+
The SDK repo's `.speakeasy/workflow.yaml` should reference the registry with a `$TAG` variable:
165+
166+
```yaml
167+
sources:
168+
my-api:
169+
inputs:
170+
- location: registry.speakeasyapi.dev/your-company/your-company/my-api@$TAG
171+
```
172+
173+
### Required secrets
174+
175+
On the spec repository, configure these secrets:
176+
177+
| Secret | Description |
178+
|--------|-------------|
179+
| `SPEAKEASY_API_KEY` | Authenticates the Speakeasy CLI. Obtain from the [Speakeasy Platform](https://app.speakeasy.com) API Keys page. |
180+
| `DOWNSTREAM_SDK_TOKEN` | A fine-grained GitHub PAT with `actions: write`, `contents: write`, and `pull-requests: write` permissions on all downstream SDK repos. |
181+
182+
On each downstream SDK repository:
183+
184+
| Secret | Description |
185+
|--------|-------------|
186+
| `SPEAKEASY_API_KEY` | Authenticates the Speakeasy CLI. Can be the same key as the spec repo or a separate key. |
187+
188+
### Example implementation
189+
190+
A complete working example is available in the [examples-downstream-spec-repo](https://github.com/speakeasy-api/examples-downstream-spec-repo) repository, which triggers SDK generation in:
191+
192+
- [examples-downstream-spec-sdk-typescript](https://github.com/speakeasy-api/examples-downstream-spec-sdk-typescript)
193+
- [examples-downstream-spec-sdk-python](https://github.com/speakeasy-api/examples-downstream-spec-sdk-python)
194+
195+
The example includes workflows that:
196+
- Trigger SDK generation when a PR is opened on the spec repo
197+
- Update the spec PR with comments showing generation status and links to SDK PRs
198+
- Automatically merge or close SDK PRs when the spec PR is merged or closed

0 commit comments

Comments
 (0)