diff --git a/fern/products/api-def/openapi/extensions/examples.mdx b/fern/products/api-def/openapi/extensions/examples.mdx index de29099778..3f915df5fb 100644 --- a/fern/products/api-def/openapi/extensions/examples.mdx +++ b/fern/products/api-def/openapi/extensions/examples.mdx @@ -6,16 +6,16 @@ og:title: OpenAPI request + response examples --- - -Fern generates realistic examples automatically using [AI-generated examples](/learn/docs/ai-features/ai-examples), enabled by default. Use `x-fern-examples` to manually define specific example values. Manual examples take priority over AI-generated ones. You can also [disable AI examples entirely](/learn/docs/configuration/site-level-settings#ai-examplesenabled). - +Fern generates realistic examples automatically using [AI-generated examples](/learn/docs/ai-features/ai-examples), enabled by default. Use `x-fern-examples` to manually define specific values, associate request and response pairs that OpenAPI's separate example fields can't link, or define multiple named examples for an endpoint. -Use `x-fern-examples` to associate specific request and response pairs or define multiple named examples for an endpoint. OpenAPI has several example fields, but provides no way to link a request with its corresponding response. +Manual examples take priority over AI-generated ones, and you can [disable AI examples entirely](/learn/docs/configuration/site-level-settings#ai-examplesenabled). ## Structure `x-fern-examples` is an array. Each element can contain `path-parameters`, `query-parameters`, `headers`, `request`, and `response` values that are all associated. Optionally, add a `name` field to provide a descriptive label. +The `request` and `response` values use different shapes: + - `request` holds the request body properties directly. - `response` requires a nested `body` key containing the response body properties. @@ -32,8 +32,8 @@ paths: x-fern-examples: - name: Get user 1234 # Optional descriptive label headers: - custom_api_key: "capi_12345" # header defined using x-global-header extension - userpool_id: "pool_67890" # header defined using x-global-header extension + custom_api_key: "capi_12345" # header defined using x-fern-global-headers extension + userpool_id: "pool_67890" # header defined using x-fern-global-headers extension path-parameters: userId: user-1234 response: @@ -64,6 +64,13 @@ 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: + +- `sdk` — for a language that maps to a Fern-supported SDK tab: `curl`, `python`, `javascript`, `typescript`, `go`, `ruby`, `csharp`, `java`, `js`, `node`, `ts`, `nodets`, `golang`, `dotnet`, `jvm`, `c#`. +- `language` — for any other language, or when you want to include an `install` command. + + + ```yaml title="openapi.yml" {11-16} paths: /users/{userId}: @@ -82,6 +89,30 @@ paths: client.users.get("user-1234") ``` + + +```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 diff --git a/fern/translations/zh/products/api-def/openapi/extensions/examples.mdx b/fern/translations/zh/products/api-def/openapi/extensions/examples.mdx index 6e894bc5ec..34b37d95b9 100644 --- a/fern/translations/zh/products/api-def/openapi/extensions/examples.mdx +++ b/fern/translations/zh/products/api-def/openapi/extensions/examples.mdx @@ -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}: @@ -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"); ``` \ No newline at end of file