SDK Method Names

Use x-fern-sdk-method-name to customize SDK method names for operations

View as Markdown

By default, Fern generates SDK method names based on your operation names in AsyncAPI. You can override this behavior using the x-fern-sdk-method-name extension.

Customize operation method names

Use x-fern-sdk-method-name to specify custom method names for your operations:

asyncapi.yml
1operations:
2 subscribeToUserEvents:
3 action: receive
4 channel:
5 $ref: '#/channels/user~1events'
6 x-fern-sdk-method-name: onUserEvent
7 summary: Subscribe to user events
8 publishOrderUpdate:
9 action: send
10 channel:
11 $ref: '#/channels/order~1updates'
12 x-fern-sdk-method-name: sendOrderUpdate
13 summary: Publish order update

This will generate SDK methods like:

1// Instead of client.subscribeToUserEvents()
2client.onUserEvent((event) => {
3 // Handle user event
4});
5
6// Instead of client.publishOrderUpdate()
7client.sendOrderUpdate(orderData);

Method naming conventions

Follow these conventions when naming SDK methods:

Subscribe operations

Use descriptive names that indicate the action:

asyncapi.yml
1operations:
2 subscribeToNotifications:
3 action: receive
4 x-fern-sdk-method-name: onNotification
5 # Generates: client.onNotification()
6
7 subscribeToOrderUpdates:
8 action: receive
9 x-fern-sdk-method-name: watchOrders
10 # Generates: client.watchOrders()

Publish operations

Use action-oriented names:

asyncapi.yml
1operations:
2 publishUserSignup:
3 action: send
4 x-fern-sdk-method-name: createUser
5 # Generates: client.createUser()
6
7 publishNotification:
8 action: send
9 x-fern-sdk-method-name: notify
10 # Generates: client.notify()

Language-specific method names

You can specify different method names for different programming languages:

asyncapi.yml
1operations:
2 subscribeToEvents:
3 action: receive
4 channel:
5 $ref: '#/channels/events'
6 x-fern-sdk-method-name:
7 python: on_event
8 typescript: onEvent
9 go: OnEvent
10 java: onEvent
11 csharp: OnEvent

This ensures method names follow the conventions of each target language.