diff --git a/fern/products/docs/pages/api-references/sdk-snippets.mdx b/fern/products/docs/pages/api-references/sdk-snippets.mdx index a9b238e90..a9b5886f6 100644 --- a/fern/products/docs/pages/api-references/sdk-snippets.mdx +++ b/fern/products/docs/pages/api-references/sdk-snippets.mdx @@ -20,13 +20,69 @@ Once configured, SDK snippets replace [HTTP snippets](/learn/docs/api-references ## Configuration -To configure SDK snippets, first name your SDKs in `generators.yml` and then reference that name in `docs.yml`. +Fern needs to read request examples from your API definition to generate code snippets. For OpenAPI, follow [Swagger's examples documentation](https://swagger.io/docs/specification/adding-examples/). + +Then follow the steps for the file you generate SDKs with. + + + + +With [`sdk-config.yml`](/learn/sdks/reference/sdk-config), Fern stores the snippets from each SDK build on its servers. `fern generate --docs` fetches them and adds them to your API Reference endpoints. This works for TypeScript, Python, Java, Go, Ruby, C#, and PHP SDKs. + +Requires Fern CLI version `5.188.0` or later. Run `fern upgrade` to update. -### Add examples to your API definition +### Enable snippets in `sdk-config.yml` -Fern needs to read request examples from your API definition to generate code snippets. For OpenAPI, follow [Swagger's examples documentation](https://swagger.io/docs/specification/adding-examples/). +Set `docs.snippets.enabled` to `true` at the top level, where every target inherits it, or in a single target's `docs` block. Fern finds each SDK's build by its `sdkName`, so the target needs an `sdkName` of its own or the top-level one. + + +```yaml {1, 3-5} +sdkName: plant-store +docs: + snippets: + enabled: true +targets: + - language: python + - language: typescript +``` + + +### Add the SDK version to `docs.yml` + +Under your `api:` entry, add a `snippets` entry for each language you build, with the version you're about to build. List only the languages you build. + + +```yaml {3-9} +navigation: + - api: API Reference + snippets: + python: + package: your-package-name + version: 1.2.0 + typescript: + package: your-package-name + version: 1.2.0 +``` + + +### Build the SDKs at that version + +Run `fern generate` to build the SDKs with a new [version](/learn/sdks/reference/sdk-config#sdkversion) that matches the `version` in `docs.yml`. Fern reads snippets only from a successful build made with snippets enabled, and uses the newest such build of each language with a matching `sdkName` and version. + +### Generate the docs + +Run `fern generate --docs`. The output includes a line such as `Loaded SDK snippets (python: 12, typescript: 12)` with the number of endpoint snippets read for each language, and the snippets appear in the language dropdown on each endpoint. A [code sample you wrote](/learn/api-definitions/openapi/extensions/request-response-examples#code-samples) for an endpoint in the same language takes precedence over the generated snippet. + +If Fern can't find or read the snippets for a language, the CLI logs a warning and publishes the docs without them. + + + + + + + ### Define a package name for your SDK(s) @@ -134,9 +190,7 @@ Trigger your docs generation by running `fern generate --docs` locally or in CI/ -## Additional options - -### Specify SDK versions +#### Specify SDK versions You can specify which SDK version to use when generating code snippets. @@ -151,6 +205,11 @@ navigation: ``` + + + +## Additional options + ### Set default snippet language Use the `default-language` key at the top indentation level of `docs.yml`. This setting applies to both SDK snippets and HTTP snippets. diff --git a/fern/products/sdks/reference/sdk-config-reference.mdx b/fern/products/sdks/reference/sdk-config-reference.mdx index e75bbdeff..ae73863d3 100644 --- a/fern/products/sdks/reference/sdk-config-reference.mdx +++ b/fern/products/sdks/reference/sdk-config-reference.mdx @@ -389,7 +389,7 @@ Optional package registry publication. `registry` selects the registry, and the README content and example configuration. - Standalone usage snippet generation. + Standalone usage snippet generation. Enabled snippets also appear in your docs' [API Reference](/learn/docs/api-references/sdk-snippets#enable-snippets-in-sdk-configyml). The base URL used for links to generated API Reference files. @@ -398,6 +398,18 @@ Optional package registry publication. `registry` selects the registry, and the Whether API Reference documentation is included in the SDK output. +### `snippets` + + + Whether Fern stores the snippets from each SDK build on its servers. `fern generate --docs` fetches them to show [SDK snippets in your API Reference](/learn/docs/api-references/sdk-snippets#enable-snippets-in-sdk-configyml). + + + The format of the snippets file. + + + The path of the snippets file in the generated SDK. + + ## `generation` Generation settings inherited by every target. Each target's `generation` block also accepts language-specific settings, documented on each language's configuration page.