Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions fern/products/api-def/openapi/extensions/examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ paths:

Fern generators automatically add SDK code samples. To specify custom code samples for an example, use `code-samples`.

Each code sample uses one of two keys to identify the language:

| Key | Value | Use when |
|-----|-------|----------|
| `sdk` | One of the supported SDK languages: `curl`, `python`, `javascript`, `typescript`, `go`, `ruby`, `csharp`, `java`, `js`, `node`, `ts`, `nodets`, `golang`, `dotnet`, `jvm`, `c#` | The sample maps to a Fern-supported SDK language tab |
| `language` | Any string | The sample is for a language not in the supported list, or you want to include an `install` command |

Using `sdk`:

```yaml title="openapi.yml" {11-16}
paths:
/users/{userId}:
Expand All @@ -83,6 +92,29 @@ paths:
client.users.get("user-1234")
```

Using `language`:

```yaml title="openapi.yml" {11-18}
paths:
/users/{userId}:
get:
x-fern-examples:
- path-parameters:
userId: user-1234
response:
body:
name: Foo
ssn: 1234
code-samples:
- language: php
install: composer require acme/sdk
code: |
use Acme\Client;

$client = new Client();
$client->users->get("user-1234");
```

## Convert to native OpenAPI examples

To make `x-fern-examples` work with non-Fern OpenAPI tools, run [`fern api enrich`](/learn/cli-api-reference/cli-reference/commands#fern-api-enrich) to convert them into native OpenAPI example fields.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ paths:

Fern 生成器会自动添加 SDK 代码示例。如果您想为示例指定自定义代码示例,请使用 `code-samples`。

每个代码示例使用以下两个键之一来标识语言:

| 键 | 值 | 使用场景 |
|-----|-------|----------|
| `sdk` | 支持的 SDK 语言之一:`curl`、`python`、`javascript`、`typescript`、`go`、`ruby`、`csharp`、`java`、`js`、`node`、`ts`、`nodets`、`golang`、`dotnet`、`jvm`、`c#` | 代码示例对应 Fern 支持的 SDK 语言标签 |
| `language` | 任意字符串 | 代码示例的语言不在支持列表中,或您需要包含 `install` 命令 |

使用 `sdk`:

```yaml title="openapi.yml" {11-16}
paths:
/users/{userId}:
Expand All @@ -79,4 +88,27 @@ paths:
import { UserClient } from "...";

client.users.get("user-1234")
```

使用 `language`:

```yaml title="openapi.yml" {11-18}
paths:
/users/{userId}:
get:
x-fern-examples:
- path-parameters:
userId: user-1234
response:
body:
name: Foo
ssn: 1234
code-samples:
- language: php
install: composer require acme/sdk
code: |
use Acme\Client;

$client = new Client();
$client->users->get("user-1234");
```
Loading