Skip to main content

Customize Class Name & Namespaces

Class Name

By default The Speakeasy SDKs will be generated with the Class Name SDK. However a custom class name can be configured by modifying the root of your gen.yaml file to include:

sdkclassname: "myClassName"

Yields a package like:

package petshop

import (
"net/http"

"openapi/pkg/utils"
)

var ServerList = []string{
"http://petstore.speakeasy.io/v1",
}

type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}

type PetShop struct {
Pets *Pets

_defaultClient HTTPClient
_securityClient HTTPClient

_serverURL string
_language string
_sdkVersion string
_genVersion string
}

Namespaces

The Speakeasy CLI, as part of its SDK generation, will generate namespaces which you can use to group related operations. These namespaces are generated from the OpenAPI specification and are based on the tags associated to the operations in the spec.

By default namespaces will be generated for all tags in the spec. To disable namespace generation for your SDK, modify your gen.yaml file to disable them like so:

# ...
tagnamespacingdisabled: true

Operation Tags

Namespaces are generated for each tag specified at the root level of the OpenAPI spec. If an operation does not have an associated tag, then it will be added to the root sdk class of the generated client library. In the case where multiple tags are associated, the operation will appear as a method in multiple classes. The example below shows one method added to a namespace, and another left to the default class:

paths:
/stores:
get:
operationId: listStores
summary: List all stores
description: Get a list of all stores in the system
responses:
"200":
description: A list of stores
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Store"
/pets:
get:
operationId: listPets
summary: List all pets
description: Get a list of all pets in the system
tags:
- pets
responses:
"200":
description: A list of pets
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Pet"
tags:
- name: pets
description: Everything about Pets

The generated SDK will have methods invocable like so:

// ListPets - List all pets
// Get a list of all pets in the system
sdk.Pets.ListPets()
sdk.ListStores()