Customize Methods
Change Method Names
Speakeasy uses your OpenAPI schema to infer names for class types, methods, and parameters. However, you can override these names to tailor the generated SDK to your preferences.
The x-speakeasy-name-override
extension can be used to override the name of a class, method, or parameter. We'll detail the various locations
this extension can be placed in your OpenAPI schema to override these names at different scopes (globally vs per operation/parameter) in the following sections.
The x-speakeasy-name-override
extension may override the generated name for a method generated from an operation.
This extension may be used globally if placed at the root of the OpenAPI schema, where all methods with an operationId
that matches the provided
operationId
regex will be overridden with methodNameOverride
.
openapi: 3.1.0
info:
title: Test
version: 0.0.1
servers:
- url: https://httpbin.org
security:
- basicAuth: []
x-speakeasy-name-override:
- operationId: ^get.*
methodNameOverride: get
- operationId: ^post.*
methodNameOverride: create
paths:
/test:
get:
operationId: getTest
responses:
"200":
description: OK
post:
operationId: postTest
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/Test"
responses:
"200":
description: OK
Since getTest
and postTest
match the ^get.*
and ^post.*
regexes defined by the global x-speakeasy-name-override
extension, these method names
will be generated as get
and create
, respectively.
Alternatively, x-speakeasy-name-override
may be used at the operation level, where it will override the generated name for the method pertaining
only to that operation. This can be combined with the global extension above and will take precedence over it. Consider the same schema shown above but
with an operation-level extension added to the get
operation:
---
get:
operationId: getTest
x-speakeasy-name-override: getRandomTest
responses:
"200":
description: OK
Now, postTest
will still be generated as create
as before, but getTest
will be generated as getRandomTest
.
Exclude Methods From SDK
When generating an SDK you may want to exclude certain methods from being included in your SDK. This is can be indicated on the spec with the x-speakeasy-ignore
extension.
Here is an example with several instances of x-speakeasy-ignore: true
being used across the specification.
paths:
/test:
get:
x-speakeasy-ignore: true
operationId: getTest
responses:
"200":
description: OK
Deprecate Methods
You can deprecate methods in your SDK by using the deprecated
field in your OpenAPI schema. This will add a deprecated
annotation to the generated method and add a ⚠️ Deprecated
label to the SDK docs.
paths:
/test:
get:
operationId: listUsers
deprecated: true
responses:
"200":
description: OK
tags:
- Test
/**
* @deprecated this method will be removed in a future release, please migrate away from it as soon as possible
*/
async listuser(config?: AxiosRequestConfig): Promise<operations.ListUsersResponse> {
...
}