Skip to content

Commit a1f1cff

Browse files
committed
Sync open source content 🐝 (from 845bef37211a5ab95c35642c3365ae328c2bffd3)
1 parent b1153bf commit a1f1cff

File tree

8 files changed

+226
-283
lines changed

8 files changed

+226
-283
lines changed

api-design/versioning.mdx

Lines changed: 86 additions & 147 deletions
Large diffs are not rendered by default.
Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
---
2-
title: Configuring module format
2+
title: Configuring Module Format
3+
description: "Learn to configure module formats for SDKs."
34
---
45

56
import { Callout } from "@/mdx/components";
67

7-
# Configuring Module Format
8+
# Configuring module format
89

910
Modern SDKs need to balance compatibility with performance. The `moduleFormat` option in the SDK generator allows developers to control whether an SDK is built for CommonJS (CJS), ECMAScript Modules (ESM), or both. This choice impacts bundle size, tree-shaking performance, and compatibility with Node.js and modern bundlers.
1011

11-
## How to Configure Module Format
12+
## How to configure module format
1213

13-
To configure the module format, update `gen.yaml` (which is often located in the SDK's `.speakeasy` directory) file under the `typescript` section:
14+
To configure the module format, update the `typescript` section of your `gen.yaml` file (which is often located in the SDK's `.speakeasy` directory):
1415

1516
```yaml <sdk-root>/.speakeasy/gen.yaml
1617
typescript:
@@ -19,26 +20,30 @@ typescript:
1920
# other Typescript configuration options...
2021
```
2122

22-
### Supported Options
23+
### Supported options
2324

24-
- **`"commonjs"` (default)**: Builds SDK for CommonJS. Widely supported across Node.js environments but less optimized for modern bundlers and tree-shaking.
25-
- **`"esm"`**: Builds SDK for ECMAScript Modules, the modern standard for JavaScript modules. Provides optimal tree-shaking and significantly smaller bundles when used with bundlers like Webpack, Rollup, or Vite.
26-
- **`"dual"`**: Builds SDK for both CJS and ESM formats. Provides the best of both worlds - ESM's superior tree-shaking and bundle optimization while maintaining compatibility with older CommonJS environments. The slight build time increase is often worth the flexibility and performance benefits.
25+
Select one of the supported module formats:
2726

28-
## Module Format Overview
27+
- `"commonjs"` is the default option. It builds SDKs for CommonJS. CJS is widely supported across Node.js environments, but it's less optimized for modern bundlers and tree-shaking.
28+
- `"esm"` is the modern standard for JavaScript modules. It builds SDKs for ECMAScript Modules. ESM provides optimal tree-shaking and significantly smaller bundles when used with bundlers like Webpack, Rollup, or Vite.
29+
- `"dual"` provides the best of both worlds. By building SDKs for both CJS and ESM formats, it offers ESM's superior tree-shaking and bundle optimization while maintaining compatibility with older CJS environments. The slight build time increase is often worth the flexibility and performance benefits.
2930

30-
`moduleFormat` determines the module system targeted during SDK build. It impacts:
31+
## Module format overview
3132

32-
- Node.js project compatibility,
33-
- Bundler tree-shaking capabilities,
34-
- SDK bundle size, and
35-
- Build performance.
33+
The `moduleFormat` determines the module system targeted during SDK building. It impacts:
3634

37-
### Example Outputs for Each Option
35+
- Node.js project compatibility
36+
- Bundler tree-shaking capabilities
37+
- SDK bundle size
38+
- Build performance
3839

39-
#### CommonJS (Default)
40+
### Example outputs
4041

41-
When configured with `commonjs`:
42+
Review the different outputs generated for each module format.
43+
44+
#### CJS
45+
46+
The `commonjs` module format outputs the following:
4247

4348
```javascript example.js
4449
// CommonJS import in consumer code
@@ -50,7 +55,7 @@ import { ApiError } from "petstore/errors/apierror.js";
5055

5156
#### ESM
5257

53-
When configured with `esm`:
58+
The `esm` module format outputs the following:
5459

5560
```javascript example.js
5661
// Native ESM import in consumer code
@@ -61,7 +66,7 @@ import { ApiError } from "petstore/errors/apierror.js";
6166

6267
#### Dual
6368

64-
When configured with `dual`:
69+
The `dual` module format outputs the following:
6570

6671
```javascript example.js
6772
// ESM import (no interop code)
@@ -71,33 +76,33 @@ import { ApiError } from "petstore/errors/apierror.js";
7176
const { ApiError } = require("petstore/errors/apierror.js");
7277
```
7378

74-
## How to Decide Which Format to Use
79+
## How to decide which format to use
7580

76-
**Use CommonJS (`commonjs`) if...**
81+
We recommend using CJS (`commonjs`) if:
7782

7883
- The SDK is used primarily in Node.js environments or older projects.
7984
- Bundle size optimization is not a critical requirement.
80-
- Maximum compatibility with legacy systems is required.
85+
- You require maximum compatibility with legacy systems.
8186

82-
**Use ESM (`esm`) if...**
87+
We recommend using ESM (`esm`) if:
8388

84-
- SDK consumers use modern bundlers like Vite, Webpack, or Rollup.
89+
- The SDK consumers use modern bundlers like Vite, Webpack, or Rollup.
8590
- Tree-shaking and bundle size optimization are top priorities.
8691
- The project already uses ESM throughout.
8792
- Leveraging the latest JavaScript features and tooling is important.
8893

89-
**Use Dual Mode (`dual`) if...**
94+
We recommend using both (`dual`) if:
9095

91-
- Support for both modern and legacy environments is required.
92-
- ESM's superior tree-shaking while maintaining CommonJS compatibility is desired.
93-
- The SDK will be used in diverse environments with different module requirements.
96+
- You require support for both modern and legacy environments.
97+
- You need ESM's superior tree-shaking while maintaining CJS compatibility.
98+
- The SDK is used in diverse environments with different module requirements.
9499
- Developer experience and maximum flexibility are priorities.
95100

96101
<Callout title="Recommendation" type="info">
97-
For most modern projects, the `dual` format is recommended. This ensures the SDK works seamlessly in any environment while still providing the performance benefits of ESM when used with modern bundlers.
102+
For most modern projects, the `dual` format is best. It ensures the SDK works smoothly in any environment, while still providing the performance benefits of ESM when used with modern bundlers.
98103
</Callout>
99104

100-
## Additional Reading
105+
## Additional reading
101106

102-
- [Typescript Configuration Options](/docs/gen-reference/ts-config)
103-
- [Lean SDKs with Standalone Functions](/post/standalone-functions)
107+
- [TypeScript configuration options](/docs/gen-reference/ts-config)
108+
- [Lean SDKs with standalone functions](/post/standalone-functions)

docs/guides/code-samples-without-github-actions.md

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
1+
---
2+
title: Populate Code Samples Without GitHub Actions
3+
description: "Learn to use the CLI to populate code samples without GitHub Actions."
4+
---
5+
16
# Using the CLI to populate code samples without GitHub Actions
27

38
This guide explains how to use the Speakeasy CLI to generate and publish code samples for your API documentation when you're not using GitHub Actions.
49

510
## Overview
611

7-
Speakeasy can automatically generate code samples for your OpenAPI specification and make them available via a public URL that can be integrated with documentation platforms like Scalar. While this process is typically automated with GitHub Actions, you can achieve the same result using just the CLI in your own custom workflows.
12+
Speakeasy automatically generates code samples for your OpenAPI document and makes them available via a public URL that can be integrated with documentation platforms like Scalar. While this process is typically automated with GitHub Actions, you can achieve the same result using just the Speakeasy CLI in your own custom workflow.
813

914
## Prerequisites
1015

11-
- Speakeasy CLI installed
12-
- An OpenAPI specification
13-
- A Speakeasy account and API key
14-
- **CI environment**: The generation must run from a CI environment or with the `CI_ENABLED` environment variable set to `true`
16+
To follow this guide, you need:
17+
18+
- **The Speakeasy CLI:** Install the CLI on your computer.
19+
- **An OpenAPI document:** Speakeasy generates your SDKs based on your OpenAPI document
20+
- **A Speakeasy account and API key:** Ensure you have access to the Speakeasy workspace.
21+
- **A CI environment:** The generation must run from a CI environment or with the `CI_ENABLED` environment variable set to `true`.
1522

16-
## Step-by-step process
23+
## Generating code samples with the Speakeasy CLI
1724

18-
### 1. Configure your workflow
25+
Follow these steps to populate your OpenAPI document and make it available for use with documentation platforms:
26+
27+
### Configure your workflow
1928

2029
First, set up your workflow configuration file:
2130

@@ -25,7 +34,7 @@ speakeasy configure
2534

2635
This creates a `.speakeasy/workflow.yaml` file that defines your SDK generation targets and code samples configuration.
2736

28-
### 2. Generate SDKs and code samples
37+
### Generate SDKs and code samples
2938

3039
Run the Speakeasy CLI to generate your SDKs and code samples:
3140

@@ -34,55 +43,56 @@ speakeasy run
3443
```
3544

3645
This command:
46+
3747
- Downloads or loads your OpenAPI document
3848
- Validates the OpenAPI document
3949
- Generates SDKs for your configured languages
4050
- Creates code samples for each operation in your API
4151

42-
### 3. Promote code samples to main
52+
### Promote code samples to main
4353

44-
The critical step for enabling automated code samples is to tag both your source specification and generated code samples with the `main` tag:
54+
The critical step for enabling automated code samples is to tag both your source specification (OpenAPI document) and generated code samples with the `main` tag:
4555

4656
```bash
4757
speakeasy tag promote -s my-source-name -c my-target-name -t main
4858
```
4959

50-
This command tags both the source specification (`-s my-source-name`) and the generated code samples (`-c my-target-name`) as "official" so they can be incorporated into the public URL. Similar to how the `main` branch in GitHub represents the production-ready version of your code, the `main` tag in Speakeasy indicates these are the production-ready specifications and code samples that should be publicly available. Replace `my-source-name` and `my-target-name` with the names as defined in your workflow configuration.
60+
This command tags both the source OpenAPI document (`-s my-source-name`) and the generated code samples (`-c my-target-name`) as "official" so they can be incorporated into the public URL. Similar to how the `main` branch in GitHub represents the production-ready version of your code, the `main` tag in Speakeasy indicates these are the production-ready specifications and code samples that should be publicly available. Replace `my-source-name` and `my-target-name` with the names defined in your workflow configuration.
5161

52-
### 4. Access the public URL
62+
### Access the public URL
5363

54-
Once you've tagged your code samples with `main`, Speakeasy will automatically start building a combined spec in the background. The combined spec will be available at a public URL that you can use with documentation platforms like Scalar.
64+
Once you've tagged your code samples with `main`, Speakeasy automatically starts building a combined OpenAPI document in the background. The combined document is available at a public URL that you can use with documentation platforms like Scalar.
5565

56-
To find this URL, you'll need to visit the Speakeasy dashboard and navigate to the **Docs** tab. Click on **Integrate with Docs Provider** to see the URL to the OpenAPI with code samples combined. Currently, there's no CLI command to retrieve this URL programmatically.
66+
To find this URL, open the Speakeasy workspace and navigate to the **Docs** tab. Click **Integrate with Docs Provider** to see the URL to the combined OpenAPI document with populated code samples. Currently, there's no CLI command to retrieve this URL programmatically.
5767

58-
### 5. Integrate with docs providers
68+
### Integrate with docs providers
5969

6070
Once you have the public URL, you can integrate it with various documentation providers. Speakeasy offers detailed integration guides for several popular docs platforms:
6171

62-
- [Scalar](/docs/sdk-docs/integrations/scalar) - A modern API documentation platform
63-
- [ReadMe](/docs/sdk-docs/integrations/readme) - Interactive API explorer and documentation
64-
- [Mintlify](/docs/sdk-docs/integrations/mintlify) - Developer documentation with an interactive playground
65-
- [Bump.sh](/docs/sdk-docs/integrations/bump) - Hosted API documentation and catalogs
72+
- [Scalar](/docs/sdk-docs/integrations/scalar) is a modern API documentation platform.
73+
- [ReadMe](/docs/sdk-docs/integrations/readme) offers an interactive API explorer and documentation.
74+
- [Mintlify](/docs/sdk-docs/integrations/mintlify) provides developer documentation with an interactive playground.
75+
- [Bump.sh](/docs/sdk-docs/integrations/bump) hosts API documentation and catalogs.
6676

6777
## Automating the process
6878

69-
For a fully automated workflow without GitHub Actions:
79+
Use the following steps to create a fully automated workflow without GitHub Actions:
7080

71-
1. Create a script or CI pipeline that runs `speakeasy run` to generate SDKs and code samples
72-
2. Add `speakeasy tag promote -s my-source-name -c my-target-name -t main` to tag both the source specification and generated code samples
73-
3. The public URL will automatically update with the latest code samples
81+
- Create a script or CI pipeline that runs `speakeasy run` to generate SDKs and code samples.
82+
- Add `speakeasy tag promote -s my-source-name -c my-target-name -t main` to tag both the source OpenAPI document and generated code samples.
83+
- The public URL automatically updates the OpenAPI document with the latest code samples.
7484

7585
### Why use CLI tagging instead of GitHub Actions?
7686

7787
While GitHub Actions provides a convenient way to automate code sample generation and tagging, the CLI approach offers several advantages for teams:
7888

79-
- **Platform independence**: Use any CI/CD system (Jenkins, GitLab CI, CircleCI, Azure DevOps) instead of being limited to GitHub Actions
80-
- **Custom workflows**: Integrate code sample generation into existing build processes or deployment pipelines
81-
- **Local development**: Generate and test code samples locally before pushing changes
82-
- **Private repositories**: Work with code that isn't hosted on GitHub or is in private repositories with restricted access
83-
- **Enterprise environments**: Support for organizations with specific security or compliance requirements that prevent using GitHub Actions
89+
- **Platform independence:** Use any CI/CD system (such as Jenkins, GitLab CI, CircleCI, or Azure DevOps) instead of being limited to GitHub Actions.
90+
- **Custom workflows:** Integrate code sample generation into existing build processes or deployment pipelines.
91+
- **Local development:** Generate and test code samples locally before pushing changes.
92+
- **Private repositories:** Work with code that isn't hosted on GitHub or is hosted in private repositories with restricted access.
93+
- **Enterprise environments:** Provide support for organizations with specific security or compliance requirements that prevent them from using GitHub Actions.
8494

85-
## Example workflow script
95+
### Example workflow script
8696

8797
Here's a simple bash script example that could be used in a custom CI pipeline:
8898

docs/manage/breaking-changes.mdx

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,48 @@
11
---
2-
title: Handling breaking changes in SDKs
3-
description: >
4-
Learn how to handle breaking changes in APIs when using
5-
Speakeasy-generated SDKs.
2+
title: Handling Breaking Changes in SDKs
3+
description: "Learn how to handle breaking changes in APIs when using Speakeasy-generated SDKs."
64
---
75

86
import { Callout } from "@/mdx/components";
97

108
# Handling breaking changes in SDKs
119

12-
This guide explains how to handle breaking changes in APIs when using
13-
Speakeasy-generated SDKs. Following these guidelines helps maintain backward
14-
compatibility and ensures a smooth experience for SDK users.
10+
This guide explains how to handle breaking changes in APIs when using Speakeasy-generated SDKs. Follow these guidelines to maintain backward compatibility and ensure a smooth experience for your SDK users.
1511

1612
## Safe changes
1713

1814
The following API changes are safe and won't break existing SDKs:
1915

2016
### Adding new fields
2117

22-
Adding new fields to API responses is safe because older SDK versions ignore
23-
these fields. New response fields can be added without breaking existing
24-
integrations.
18+
You can safely add new fields to API responses because older SDK versions ignore these fields. Adding new response fields doesn't break existing integrations.
2519

2620
### Adding new enum values
2721

28-
Adding new enum values is safe when enums are marked with
29-
`x-speakeasy-unknown-values` ([see enums customization doc](/docs/customize/data-model/enums#open-enums)). Older SDKs handle
30-
these new values gracefully according to the behavior specified in the
31-
extension configuration.
32-
22+
You can safely add new enum values when enums are marked with `x-speakeasy-unknown-values` (see our [Customize enums](/docs/customize/data-model/enums#open-enums) documentation). Older SDKs handle these new values gracefully according to the behavior specified in the extension configuration.
3323

3424
## Changes requiring caution
3525

36-
Some API changes require careful consideration to avoid breaking existing SDK
37-
implementations. Use the [OpenAPI diff tool](/docs/speakeasy-reference/cli/openapi/diff) to identify potential breaking
38-
changes in the API specification:
39-
40-
26+
Some API changes require careful consideration to avoid breaking existing SDK implementations. Use the [OpenAPI diff tool](/docs/speakeasy-reference/cli/openapi/diff) to identify potential breaking changes in your API specification.
4127

4228
### Deprecating required fields
4329

44-
When deprecating fields marked as required in the API specification:
45-
- Older SDKs throw validation errors if the field is missing
46-
- Make the field optional before removing it
47-
- Plan a deprecation period for implementation updates
30+
Take care when deprecating fields marked as required in the API specification. Older SDKs may throw validation errors if required fields are missing:
31+
32+
- Make the field optional before removing it.
33+
- Plan a deprecation period for implementation updates.
4834

4935
### Modifying oneOf schemas
5036

51-
Make changes to `oneOf` schemas carefully:
52-
- Adding new variants may cause type mismatch errors in older SDKs
53-
- Maintain backward compatibility with existing schema variants
54-
- Test changes thoroughly with older SDK versions
37+
Make changes to `oneOf` schemas carefully, as adding new variants may cause type mismatch errors in older SDKs:
38+
39+
- Maintain backward compatibility with existing schema variants.
40+
- Test changes thoroughly with older SDK versions.
5541

5642
## Future improvements
5743

58-
Speakeasy is developing additional features to help manage breaking changes:
44+
Speakeasy is developing additional features to help you manage breaking changes, including:
45+
5946
- SDK version upgrade prompts
6047
- Improved tooling for breaking changes
6148
- Enhanced version management capabilities

docs/sdk-testing.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: SDK contract testing
2+
title: SDK Contract Testing
33
description: "Learn how to generate and run automated testing for APIs and SDKs."
44
---
55

0 commit comments

Comments
 (0)