Skip to content
Merged
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
25 changes: 10 additions & 15 deletions fern/products/api-def/ferndef-pages/export-openapi.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@ title: Export from Fern Definition to OpenAPI
description: Export your Fern Definition files to OpenAPI using Fern's OpenAPI generator.
---

To prevent lock-in to the Fern Definition format, we provide a generator that will export your Fern Def files to OpenAPI 3.1.
This lets you switch to using OpenAPI at any time, or use your API definition with OpenAPI tools.
To convert your Fern Definition to OpenAPI, use the `fern-openapi` generator.
To prevent lock-in to the Fern Definition format, you can export your API definition to OpenAPI 3.1 at any time [using the `fern export` command](/cli-api-reference/cli-reference/commands#fern-export).

Update your `generators.yml` file:
If you have multiple APIs defined in your `fern/apis/` folder, use `--api` to specify which API to export.

<CodeBlock title="generators.yml">
```yaml
- name: fernapi/fern-openapi
version: 0.0.31
config:
format: yaml # options are yaml or json
output:
location: local-file-system
path: ../openapi # relative path to output location
```
</CodeBlock>
<CodeBlock title="terminal">
```bash
fern export path/to/openapi.yml
fern export path/to/openapi.json

# Specify API to export
fern export --api public-api path/to/openapi.yml
```
</CodeBlock>
28 changes: 28 additions & 0 deletions fern/products/cli-api-reference/pages/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ hideOnThisPage: true
| [`fern upgrade`](#fern-upgrade) | Update Fern CLI & generators to latest versions |
| [`fern login`](#fern-login) | Login to Fern CLI via GitHub or Google |
| [`fern logout`](#fern-logout) | Log out of the Fern CLI |
| [`fern export`](#fern-export) | Export an OpenAPI spec for your API |

## Documentation Commands

Expand Down Expand Up @@ -140,6 +141,33 @@ hideOnThisPage: true
</Tip>
</Accordion>

<Accordion title="fern export">

Use `fern export` to generate an OpenAPI spec for your API.

This command is useful when you've defined your API in a format other than OpenAPI (such as the [Fern Definition](/api-definitions/ferndef/overview)) and need to export it as an OpenAPI spec for integration with other tools or services.


<CodeBlock title="terminal">
```bash
fern export [--api <api>] path/to/openapi.yml
fern export [--api <api>] path/to/openapi.json
```
</CodeBlock>

### api

Use `--api` to specify which API to export when you have multiple APIs defined in your `fern/apis/` folder.

<CodeBlock title="terminal">
```bash
fern export --api public-api path/to/openapi.yml
fern export --api public-api path/to/openapi.json
```
</CodeBlock>

</Accordion>

<Accordion title="fern generate">
Use `fern generate` to run the Fern compiler and create SDKs for your API.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
You can initialize your fern folder with either a Fern Definition or OpenAPI specification.

<Tip>
You can always convert a Fern Definition to OpenAPI or OpenAPI to a Fern Definition later on.
You can always convert a [Fern Definition to OpenAPI](/api-definitions/ferndef/export-openapi) or OpenAPI to a Fern Definition later on.
</Tip>