Speakeasy Logo
Skip to Content

Editing Your SDK Docs

Speakeasy-managed SDKs include a README.md file that contains at least the following sections by default:

  • ## Summary: A brief introduction based on the info and externalDocs attributes defined in the OpenAPI document.
  • ## Table of Contents: A list of links to all available sections in the README.
  • ## SDK Installation: An installation snippet based on the package name provided in the gen.yaml file.
  • ## SDK Example Usage: An example usage snippet based on the first operation in the OpenAPI document.
  • ## SDK Available Operations: Links to documentation that covers all the SDK’s methods.

Here’s what it looks like put together:

You can enhance your README by adding content before or after any of the three main sections (SDK Installation, SDK Example Usage, and SDK Available Options). The generator will not overwrite any content you have added to the README.md file. The generator will automatically keep the content within the walled-off sections between the <!-- Start ... [tag] --> and <!-- End ... [tag] --> comments, but the rest is up to you to maintain.

If you would like to take over the management of automatically generated sections, you can do the following:

  1. Remove the <!-- Start ... [tag] --> section comment.
  2. Find the matching <!-- End ... [tag] --> comment and change it to <!-- No ... [tag] -->, which marks that section as managed by you. (This step is important. If you only remove the “Start” comment, the section may be re-inserted as described below.)
  3. Edit the content between those comments as you see fit.

If you change your mind at any time and want to go back to having Speakeasy manage a section, you can either delete the <!-- No ... [tag] --> comment from the file, or replace it with <!-- Start ... [tag] --><!-- End ... [tag] -->, and the next generation will re-insert the Speakeasy-managed content into your file.

Speakeasy may provide additional sections as new features are released or as you alter your SDK configuration by changing your OpenAPI specification and gen.yaml configuration. These new sections will be inserted above the comment named <!-- Placeholder for Future Speakeasy SDK Sections -->. (The placeholder heading will always be present in the file, and if you remove it, it will be added again just below the last README section.) Any missing sections will be inserted here during generation, so if you do not want a section inserted, be sure to follow the steps above to convert it to a <!-- No ... [tag] --> section rather than removing it entirely.

Usage Examples

Main Usage section

By default, USAGE.md and the SDK Example Usage section in the main README.md file will showcase a usage example from a random operation in the OpenAPI document. You can specify one or more operations to be used as the main usage example(s) by setting the x-speakeasy-usage-example: true extension to any operation in the OpenAPI document.

The x-speakeasy-usage-example extension can be further configured to associate each usage snippet with a custom header, description, and relative positioning.

Key
Description
The title text to be used for the usage example (an empty string indicates no title).
Description
The description for the usage example (an empty string indicates no description).
Description
Usage examples are sorted from lowest to highest based on the
value. Usage examples that share a
value will be sorted in the order they appear in the document.

This may be particularly useful for guiding users through a specific set of instructions or a “getting started” section. For example:

This YAML will result in the following being added to the README.md and USAGE.md files:

Table of Contents

To generate a more detailed Table of Contents, you can edit the value of the $toc-max-depth parameter in your README.md and subheadings will get updated upon regeneration:

To ensure custom headings are properly referenced when manually adding sections to your README.md file, the basic markdown syntax should be respected:

Feature sections

Specific usage snippets can also be selected for other sections in the main README.md, provided they meet the requirements to showcase the feature at play. To do so, use the x-speakeasy-usage-example extension and specify a list of section tags (referring to <-- Start Section [tag] --> placeholders).

For example, if you wish to select an operation for both the Override Server URL Per-Operation and the Retries sections, you can use the following:

The supported tags and their associated conditions are listed in this table:

README section
Global Parameters
Sub-section
tag
global-parameters
Conditions for selection to be effective
One of the
must originate from
.
Event Streaming
Sub-section
tag
eventstream
Conditions for selection to be effective
One of the response must use the
content type.
Pagination
Sub-section
tag
pagination
Conditions for selection to be effective
must be set for the operation.
Retries
Sub-section
tag
retries
Conditions for selection to be effective
must be set for the operation.
Error Handling
Sub-section
tag
errors
Conditions for selection to be effective
One of the responses must be an error with custom content data.
Client Server Selection
Sub-section
Per-Client
tag
server
Conditions for selection to be effective
must not be set at the operation level.
Operation Server Selection
Sub-section
Per-Operation
tag
server
Conditions for selection to be effective
Operation must define its own
array.
Client Authentication
Sub-section
Per-Client
tag
security
Conditions for selection to be effective
must not be set for the operation.
Operation Authentication
Sub-section
Per-Operation
tag
security
Conditions for selection to be effective
Operation must define its own
array.
SDK Example Usage
Sub-section
tag
usage
Conditions for selection to be effective
None (same effect as
).

If you wish to select an operation for the main usage section as well as other sections, you can use the usage tag:

Note: The title, description, and position attributes only affect the main SDK Example Usage section.

Values

When generating usage examples, Speakeasy defaults to using any example values provided for schemas within your OpenAPI document. If no examples are present, Speakeasy will try to determine the most relevant example to generate from either the format field of a schema or the property name of a schema in an object.

For example, if the schema has format: email or is within a property called email, Speakeasy will generate a random email address as an example value.

Security Schemes

For security schemes, the OpenAPI Specification does not allow you to specify examples of the values needed to populate the security details when initializing the SDKs. To provide custom examples for these values, add the x-speakeasy-example extension to the securitySchemes in your OpenAPI document.

For example:

The x-speakeasy-example value must be a string value and will be used as the example value for the Security Scheme. If the Security Scheme is a basic auth scheme, the example value will be a key-value pair that consists of a username and password split by a ; character, such as YOUR_USERNAME;YOUR_PASSWORD.

Comments

Code Comments

As part of the SDK generation, the Speakeasy CLI will generate comments for operations and models in generated SDKs. These comments are generated from the OpenAPI specification, based on the summary or description of the operation or schema. Comments are generated in the target language docstring format.

For example, in Python, the comments will be generated as PEP 257 -compliant docstrings.

By default, comments are generated for all operations and models. To disable comment generation for your SDK, modify your gen.yaml file to disable them, like so:

Operation Comments

Comments for each method in the generated SDK will be generated from the summary or description of the Operation. For example, if you have an Operation like the following:

The generated SDK will have a method commented like so:

If both the summary and description are present, the summary will be used as the first line of the comment and the description will be used as the second line of the comment. If just the description is present, it will be used as the first line of the comment. If both are present, but you would like to omit the description as it might be too verbose, you can use the omitdescriptionifsummarypresent option in your gen.yaml file, as follows:

Model Comments

For each model in the generated SDK, comments are generated from the description of the schema. For example, if you have the following schema:

The generated SDK will have a model commented like so:

Per-SDK Comments

You can configure comments that only display in the SDK for a single language. For example, if you need the comment for the TypeScript or the Golang SDK to say something different from the others, or you want to control the documentation separately for each language, you can use the Speakeasy x-speakeasy-docs extension. Anywhere you can set the summary or description, you can also add x-speakeasy-docs with per-language text for the docs.

Consider the following parameter description:

The documentation generated for each SDK will contain different comments specific to the respective programming languages.

Class Names

By default, Speakeasy SDKs will be generated with the class name, SDK. However, you can configure a custom class name by modifying your gen.yaml file to include:

This will yield a package like this:

Last updated on