You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Learn to configure module formats for SDKs."
3
4
---
4
5
5
6
import { Callout } from"@/mdx/components";
6
7
7
-
# Configuring Module Format
8
+
# Configuring module format
8
9
9
10
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.
10
11
11
-
## How to Configure Module Format
12
+
## How to configure module format
12
13
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):
14
15
15
16
```yaml <sdk-root>/.speakeasy/gen.yaml
16
17
typescript:
@@ -19,26 +20,30 @@ typescript:
19
20
# other Typescript configuration options...
20
21
```
21
22
22
-
### Supported Options
23
+
### Supported options
23
24
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:
27
26
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.
29
30
30
-
`moduleFormat` determines the module system targeted during SDK build. It impacts:
31
+
## Module format overview
31
32
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:
36
34
37
-
### Example Outputs for Each Option
35
+
- Node.js project compatibility
36
+
- Bundler tree-shaking capabilities
37
+
- SDK bundle size
38
+
- Build performance
38
39
39
-
#### CommonJS (Default)
40
+
###Example outputs
40
41
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:
42
47
43
48
```javascript example.js
44
49
// CommonJS import in consumer code
@@ -50,7 +55,7 @@ import { ApiError } from "petstore/errors/apierror.js";
50
55
51
56
#### ESM
52
57
53
-
When configured with `esm`:
58
+
The `esm` module format outputs the following:
54
59
55
60
```javascript example.js
56
61
// Native ESM import in consumer code
@@ -61,7 +66,7 @@ import { ApiError } from "petstore/errors/apierror.js";
61
66
62
67
#### Dual
63
68
64
-
When configured with `dual`:
69
+
The `dual` module format outputs the following:
65
70
66
71
```javascript example.js
67
72
// ESM import (no interop code)
@@ -71,33 +76,33 @@ import { ApiError } from "petstore/errors/apierror.js";
- The SDK is used primarily in Node.js environments or older projects.
79
84
- Bundle size optimization is not a critical requirement.
80
-
-Maximum compatibility with legacy systems is required.
85
+
-You require maximum compatibility with legacy systems.
81
86
82
-
**Use ESM (`esm`) if...**
87
+
We recommend using ESM (`esm`) if:
83
88
84
-
- SDK consumers use modern bundlers like Vite, Webpack, or Rollup.
89
+
-The SDK consumers use modern bundlers like Vite, Webpack, or Rollup.
85
90
- Tree-shaking and bundle size optimization are top priorities.
86
91
- The project already uses ESM throughout.
87
92
- Leveraging the latest JavaScript features and tooling is important.
88
93
89
-
**Use Dual Mode (`dual`) if...**
94
+
We recommend using both (`dual`) if:
90
95
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.
94
99
- Developer experience and maximum flexibility are priorities.
95
100
96
101
<Callouttitle="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.
Copy file name to clipboardExpand all lines: docs/guides/code-samples-without-github-actions.md
+39-29Lines changed: 39 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff 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
+
1
6
# Using the CLI to populate code samples without GitHub Actions
2
7
3
8
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.
4
9
5
10
## Overview
6
11
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.
8
13
9
14
## Prerequisites
10
15
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`.
15
22
16
-
## Step-by-step process
23
+
## Generating code samples with the Speakeasy CLI
17
24
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
19
28
20
29
First, set up your workflow configuration file:
21
30
@@ -25,7 +34,7 @@ speakeasy configure
25
34
26
35
This creates a `.speakeasy/workflow.yaml` file that defines your SDK generation targets and code samples configuration.
27
36
28
-
### 2. Generate SDKs and code samples
37
+
### Generate SDKs and code samples
29
38
30
39
Run the Speakeasy CLI to generate your SDKs and code samples:
31
40
@@ -34,55 +43,56 @@ speakeasy run
34
43
```
35
44
36
45
This command:
46
+
37
47
- Downloads or loads your OpenAPI document
38
48
- Validates the OpenAPI document
39
49
- Generates SDKs for your configured languages
40
50
- Creates code samples for each operation in your API
41
51
42
-
### 3. Promote code samples to main
52
+
### Promote code samples to main
43
53
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:
45
55
46
56
```bash
47
57
speakeasy tag promote -s my-source-name -c my-target-name -t main
48
58
```
49
59
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.
51
61
52
-
### 4. Access the public URL
62
+
### Access the public URL
53
63
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.
55
65
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.
57
67
58
-
### 5. Integrate with docs providers
68
+
### Integrate with docs providers
59
69
60
70
Once you have the public URL, you can integrate it with various documentation providers. Speakeasy offers detailed integration guides for several popular docs platforms:
61
71
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.
66
76
67
77
## Automating the process
68
78
69
-
For a fully automated workflow without GitHub Actions:
79
+
Use the following steps to create a fully automated workflow without GitHub Actions:
70
80
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.
74
84
75
85
### Why use CLI tagging instead of GitHub Actions?
76
86
77
87
While GitHub Actions provides a convenient way to automate code sample generation and tagging, the CLI approach offers several advantages for teams:
78
88
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.
84
94
85
-
## Example workflow script
95
+
###Example workflow script
86
96
87
97
Here's a simple bash script example that could be used in a custom CI pipeline:
Copy file name to clipboardExpand all lines: docs/manage/breaking-changes.mdx
+16-29Lines changed: 16 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,61 +1,48 @@
1
1
---
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."
6
4
---
7
5
8
6
import { Callout } from"@/mdx/components";
9
7
10
8
# Handling breaking changes in SDKs
11
9
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.
15
11
16
12
## Safe changes
17
13
18
14
The following API changes are safe and won't break existing SDKs:
19
15
20
16
### Adding new fields
21
17
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.
25
19
26
20
### Adding new enum values
27
21
28
-
Adding new enum values is safe when enums are marked with
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.
33
23
34
24
## Changes requiring caution
35
25
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.
41
27
42
28
### Deprecating required fields
43
29
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.
48
34
49
35
### Modifying oneOf schemas
50
36
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.
55
41
56
42
## Future improvements
57
43
58
-
Speakeasy is developing additional features to help manage breaking changes:
44
+
Speakeasy is developing additional features to help you manage breaking changes, including:
0 commit comments