-
Notifications
You must be signed in to change notification settings - Fork 4
Add code snippet package documentation (coming soon feature) #2100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
devin-ai-integration
wants to merge
4
commits into
main
Choose a base branch
from
devin/1763474448-code-snippet-package-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+204
−1
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5da3a55
Add code snippet package documentation page
devin-ai-integration[bot] 6e6df6e
Fix MDX parse error in CLI changelog and add Docs changelog entry
devin-ai-integration[bot] afbc1de
Update package name from @fern-api/code-snippet to @fern-api/components
devin-ai-integration[bot] 9173225
Update framework examples: remove Docusaurus/GitBook, add Vite/Gatsby…
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ## Code snippet package (coming soon) | ||
|
|
||
| A new standalone npm package will allow you to embed Fern-generated API route documentation directly into your existing documentation site, regardless of whether you use Fern for your full documentation. | ||
|
|
||
| The code snippet package provides a lightweight React component that fetches and renders API route information from your Fern API definition, enabling you to maintain your API definitions in Fern while embedding interactive API documentation into documentation sites built with other platforms like Docusaurus, GitBook, or custom solutions. | ||
|
|
||
| [Learn more](/learn/docs/developer-tools/code-snippet-package) about the code snippet package. | ||
194 changes: 194 additions & 0 deletions
194
fern/products/docs/pages/developer-tools/code-snippet-package.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| --- | ||
| title: Code snippet package | ||
| description: Embed Fern API routes into your existing documentation with a standalone package | ||
| --- | ||
|
|
||
| <Callout intent="info"> | ||
| This feature is coming soon. Check back for updates on availability. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| </Callout> | ||
|
|
||
| The code snippet package is a standalone npm package that allows you to embed Fern-generated API route documentation directly into your existing documentation site, regardless of whether you use Fern for your full documentation. | ||
|
|
||
| ## How it works | ||
|
|
||
| The code snippet package provides a lightweight React component that fetches and renders API route information from your Fern API definition. This enables you to maintain your API definitions in Fern while embedding interactive API documentation into sites built with React frameworks like Next.js, Gatsby, or custom solutions. | ||
|
|
||
| When you use the code snippet package, it displays: | ||
|
|
||
| - HTTP method and endpoint path | ||
| - Request parameters and body schema | ||
| - Response schema and examples | ||
| - Authentication requirements | ||
| - Code examples in multiple languages | ||
|
|
||
| The package automatically stays in sync with your API definition, ensuring your embedded documentation remains up-to-date whenever you update your API specification. | ||
|
|
||
| ## Use cases | ||
|
|
||
| The code snippet package is useful when you: | ||
|
|
||
| - Have existing documentation infrastructure you want to keep | ||
| - Need to embed API documentation in multiple places (docs site, blog posts, internal wikis) | ||
| - Want Fern's API definition management without migrating your entire documentation | ||
| - Need to show specific API routes in context within longer guides or tutorials | ||
|
|
||
| ## Installation | ||
|
|
||
| Install the package from npm: | ||
|
|
||
| ```bash | ||
| npm install @fern-api/components | ||
| ``` | ||
|
|
||
| Or with other package managers: | ||
|
|
||
| <CodeBlocks> | ||
| ```bash title="pnpm" | ||
| pnpm add @fern-api/components | ||
| ``` | ||
|
|
||
| ```bash title="yarn" | ||
| yarn add @fern-api/components | ||
| ``` | ||
| </CodeBlocks> | ||
|
|
||
| ## Usage | ||
|
|
||
| Import the component and provide your API endpoint details: | ||
|
|
||
| ```tsx | ||
| import { FernApiRoute } from '@fern-api/components'; | ||
|
|
||
| function MyDocPage() { | ||
| return ( | ||
| <div> | ||
| <h1>Create a plant</h1> | ||
| <p>Use this endpoint to add a new plant to your collection.</p> | ||
|
|
||
| <FernApiRoute | ||
| apiName="plantstore" | ||
| endpoint="POST /plants/{plantId}" | ||
| fernToken="your-fern-token" | ||
| /> | ||
| </div> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| The `FernApiRoute` component accepts the following props: | ||
|
|
||
| <ParamField path="apiName" type="string" required> | ||
| The name of your API as defined in your Fern configuration | ||
| </ParamField> | ||
|
|
||
| <ParamField path="endpoint" type="string" required> | ||
| The HTTP method and path of the endpoint to display (e.g., `"POST /plants/{plantId}"`) | ||
| </ParamField> | ||
|
|
||
| <ParamField path="fernToken" type="string" required> | ||
| Your Fern API token for authentication | ||
| </ParamField> | ||
|
|
||
| <ParamField path="theme" type="'light' | 'dark' | 'auto'" default="auto"> | ||
| Color theme for the embedded component | ||
| </ParamField> | ||
|
|
||
| <ParamField path="showExamples" type="boolean" default={true}> | ||
| Whether to display code examples | ||
| </ParamField> | ||
|
|
||
| <ParamField path="defaultLanguage" type="string"> | ||
| Default programming language for code examples (e.g., `"typescript"`, `"python"`) | ||
| </ParamField> | ||
|
|
||
| ## Styling | ||
|
|
||
| The code snippet package uses CSS variables for theming, allowing you to customize the appearance to match your documentation site: | ||
|
|
||
| ```css | ||
| .fern-api-route { | ||
| --fern-primary-color: #008700; | ||
| --fern-background-color: #ffffff; | ||
| --fern-text-color: #111113; | ||
| --fern-border-color: #e0e1e6; | ||
| --fern-code-background: #f5f5f5; | ||
| } | ||
| ``` | ||
|
|
||
| ## Authentication | ||
|
|
||
| To use the code snippet package, you need a Fern API token. Generate one from your [Fern Dashboard](https://dashboard.buildwithfern.com/) under API Settings. | ||
|
|
||
| The token allows the package to fetch your API definition and generate the embedded documentation. Keep your token secure and avoid committing it directly in your code. Use environment variables instead: | ||
|
|
||
| ```tsx | ||
| <FernApiRoute | ||
| apiName="plantstore" | ||
| endpoint="POST /plants/{plantId}" | ||
| fernToken={process.env.FERN_TOKEN} | ||
| /> | ||
| ``` | ||
|
|
||
| ## Framework integration | ||
|
|
||
| The code snippet package works with popular React frameworks: | ||
|
|
||
| <Tabs> | ||
| <Tab title="Next.js"> | ||
| ```tsx title="components/PlantEndpoint.tsx" | ||
| 'use client'; | ||
|
|
||
| import { FernApiRoute } from '@fern-api/components'; | ||
|
|
||
| export function PlantEndpoint() { | ||
| return ( | ||
| <FernApiRoute | ||
| apiName="plantstore" | ||
| endpoint="POST /plants/{plantId}" | ||
| fernToken={process.env.NEXT_PUBLIC_FERN_TOKEN} | ||
| /> | ||
| ); | ||
| } | ||
| ``` | ||
| </Tab> | ||
|
|
||
| <Tab title="Vite"> | ||
| ```tsx title="src/components/PlantEndpoint.tsx" | ||
| import { FernApiRoute } from '@fern-api/components'; | ||
|
|
||
| export function PlantEndpoint() { | ||
| return ( | ||
| <FernApiRoute | ||
| apiName="plantstore" | ||
| endpoint="POST /plants/{plantId}" | ||
| fernToken={import.meta.env.VITE_FERN_TOKEN} | ||
| /> | ||
| ); | ||
| } | ||
| ``` | ||
| </Tab> | ||
|
|
||
| <Tab title="Gatsby"> | ||
| ```tsx title="src/components/PlantEndpoint.tsx" | ||
| import { FernApiRoute } from '@fern-api/components'; | ||
|
|
||
| export default function PlantEndpoint() { | ||
| return ( | ||
| <FernApiRoute | ||
| apiName="plantstore" | ||
| endpoint="POST /plants/{plantId}" | ||
| fernToken={process.env.GATSBY_FERN_TOKEN} | ||
| /> | ||
| ); | ||
| } | ||
| ``` | ||
| </Tab> | ||
| </Tabs> | ||
|
|
||
| ## Related resources | ||
|
|
||
| - [Generate API Reference](/docs/api-references/generate-api-ref) - Learn about Fern's full API documentation solution | ||
| - [SDK snippets](/docs/api-references/sdk-snippets) - Configure code examples in your API Reference | ||
| - [Fern API definitions](/learn/api-definitions/overview) - Define your API with OpenAPI, AsyncAPI, or Fern Definition | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[FernStyles.Current] Avoid time-relative terms like 'soon' that become outdated