Skip to main content

Generate Readmes

The SDK Generator will generate a README.md file and attempt to keep it up to date with the latest changes to the SDK. A README.md file will be generated from scratch if one does not exist. If one does exist, the generator will attempt to update it with the latest changes to the SDK. The generator will not overwrite any changes you have made to the README.md file.

The README.md file will contain various sections as seen in the example below:

# github.com/client-sdk

<!-- Start SDK Installation -->
## SDK Installation
```bash
go get github.com/client-sdk
```
<!-- End SDK Installation -->

<!-- Start SDK Example Usage -->
## SDK Example Usage
```go
package main
<!-- End SDK Example Usage -->

import (
"context"
"fmt"
"log"
"os"

"github.com/client-sdk"
"github.com/client-sdk/pkg/models/shared"
"github.com/client-sdk/pkg/models/operations"
)

func main() {
ctx := context.Background()

opts := []sdk.SDKOption{
sdk.WithSecurity(shared.Security{
APIKey: shared.SchemeAPIKey{
APIKey: "YOUR_API_KEY",
},
}),
}

s := sdk.New(opts...)

res, err := s.ListPets(ctx)
if err != nil {
log.Fatal(err)
}

if res.Pets != nil {
// handle response
}
}
```

<!-- Start SDK Available Operations -->
## SDK Available Operations
* `ListPets` - List all pets
<!-- End SDK Available Operations -->

The README can be modified by adding additional content before or after any of the three main sections (and their content) above:

  • ## SDK Installation - A 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 - A list of all the generated operations from the OpenAPI document.

The generator will not overwrite any content you have added to the README.md file. The generator will only update the content within the three main sections above.

If your would like to modify any of the autogenerated sections above, and not have them overwritten on the next generation you can remove the <!-- Start {SECTION_NAME} --> and <!-- End {SECTION_NAME} --> comments from the README.md file. The generator will only overwrite the content between these comments.

Usage Examples

The SDK Generator by default will generate a usage example from a random operation in the OpenAPI document. If you would like to specify a specific operation to use as the usage example, you can add the x-speakeasy-usage-example extension to the operation in the OpenAPI document, and the same extension to a response content object to use as the example response. For example:

paths:
/pets:
get:
x-speakeasy-usage-example: true
summary: List all pets
operationId: ListPets
tags:
- pets
responses:
'200':
description: A paged array of pets
content:
application/json:
x-speakeasy-usage-example: true
schema:
$ref: '#/components/schemas/Pets'