Skip to content

Commit 05ea706

Browse files
Jon SylaJon Syla
authored andcommitted
added API definition. redirects are TODO
1 parent 3683069 commit 05ea706

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4718
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
title: Environments
3+
description: List environments like production, staging, and development.
4+
---
5+
6+
You can specify the environments where your server is deployed.
7+
8+
## Single URL environments
9+
10+
```yaml title="api.yml"
11+
name: api
12+
environments:
13+
Production: https://www.yoursite.com
14+
Staging:
15+
docs: This staging environment is helpful for testing!
16+
url: https://www.staging.yoursite.com
17+
```
18+
19+
## Multiple URLs per environment
20+
21+
You can specify multiple URLs per environment. This is helpful if you have a
22+
microservice architecture, and you want a single SDK to interact with multiple
23+
servers.
24+
25+
```yaml title="api.yml"
26+
environments:
27+
Production:
28+
urls:
29+
Auth: https://auth.yoursite.com
30+
Plants: https://plants.yoursite.com
31+
Staging:
32+
urls:
33+
Auth: https://auth.staging.yoursite.com
34+
Plants: https://plants.staging.yoursite.com
35+
```
36+
37+
If you choose to use this feature, you must specify a `url` for each service you define:
38+
39+
```yaml title="auth.yml"
40+
service:
41+
url: Auth
42+
base-path: /auth
43+
...
44+
```
45+
46+
## Default environment
47+
48+
You can also provide a default environment:
49+
50+
```yaml title="api.yml"
51+
name: api
52+
environments:
53+
Production: https://www.yoursite.com
54+
Staging:
55+
docs: This staging environment is helpful for testing!
56+
url: https://www.staging.yoursite.com
57+
default-environment: Production
58+
```
59+
60+
<Note> By providing a default environment, the generated SDK will be setup to hit that URL out-of-the-box. </Note>
61+
62+
## Base path
63+
If you would like all of your endpoints to be prefixed with a path, use `base-path`.
64+
65+
In the example below, every endpoint is prefixed with a `/v1`:
66+
```yaml title="api.yml"
67+
name: api
68+
base-path: /v1
69+
```
70+
71+
## Audiences
72+
73+
If you have listed environments that you want to filter, you can leverage audiences.
74+
75+
```yaml title="api.yml"
76+
audiences:
77+
- public
78+
79+
environments:
80+
Dev:
81+
url: https://api.dev.buildwithfern.com
82+
Prod:
83+
url: https://api.buildwithfern.com
84+
audiences:
85+
- external
86+
```
87+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: Errors
3+
description: Specify error types and schemas
4+
---
5+
6+
In order to generate SDKs idiomatically, Fern needs to know how to differentiate
7+
between different errors when parsing an endpoint response.
8+
9+
### Discriminate by status code
10+
11+
You can specify Fern to discriminate by status code. This means on each
12+
endpoint, every error that's listed must have a different HTTP status code.
13+
14+
<CodeBlock title="api.yml">
15+
```yaml
16+
name: api
17+
error-discrimination:
18+
strategy: status-code
19+
```
20+
</CodeBlock>
21+
22+
### Discriminate by error name
23+
24+
You can specify Fern to discriminate by error name. If you select this strategy,
25+
then Fern will assume that every error response has an extra property denoting
26+
the error name.
27+
28+
If you use Fern to generate server-side code, then this option provides
29+
the most flexibility. Otherwise, you'll probably want to use the status code
30+
discrimination strategy.
31+
32+
<CodeBlock title="api.yml">
33+
```yaml
34+
name: api
35+
error-discrimination:
36+
strategy: property
37+
property-name: errorName
38+
```
39+
</CodeBlock>
40+
41+
### Global errors
42+
43+
You can import and list errors that will be thrown by every endpoint.
44+
45+
<CodeBlock title="api.yml">
46+
```yaml
47+
imports:
48+
commons: commons.yml
49+
50+
errors:
51+
- commons.NotFoundError
52+
- commons.BadRequestError
53+
```
54+
</CodeBlock>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: Global Configuration
3+
description: Specify global headers, path parameters or query parameters meant to be included on every request.
4+
---
5+
6+
The `api.yml` configuration supports global configuration like headers and path parameters.
7+
8+
## Global headers
9+
10+
You can specify headers that are meant to be included on every request:
11+
12+
<CodeBlock title="api.yml">
13+
```yaml
14+
name: api
15+
headers:
16+
X-App-Id: string
17+
```
18+
</CodeBlock>
19+
20+
## Global path parameters
21+
22+
You can specify path parameters that are meant to be included on every request:
23+
24+
<CodeBlock title="api.yml">
25+
```yaml
26+
name: api
27+
base-path: /{userId}/{orgId}
28+
path-parameters:
29+
userId: string
30+
orgId: string
31+
```
32+
</CodeBlock>
33+
34+
### Overriding the base path
35+
36+
If you have certain endpoints that do not live at the configured `base-path`, you can
37+
override the `base-path` at the endpoint level.
38+
39+
```yml imdb.yml {5}
40+
service:
41+
endpoints:
42+
getMovie:
43+
method: POST
44+
base-path: "override/{arg}"
45+
path: "movies/{movieId}"
46+
path-parameters:
47+
arg: string
48+
```
49+
50+
## Global query parameters
51+
52+
You cannot yet specify query parameters that are meant to be included on every request.
53+
If you'd like to see this feature, please upvote [this issue](https://github.com/fern-api/fern/issues/2930).
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: The api.yml configuration file
3+
description: The api.yml file contains general API configuration when using the Fern Definition format.
4+
---
5+
6+
A `fern/` folder has a special file called `api.yml`, which includes all the API-wide configuration.
7+
8+
```bash {5}
9+
fern/
10+
├─ fern.config.json
11+
├─ generators.yml
12+
└─ definition/
13+
├─ api.yml
14+
├─ pet.yml
15+
├─ store.yml
16+
└─ user.yml
17+
```
18+
19+
## API name
20+
21+
This name is used to uniquely identify your API in your organization. If you just have one API, then `api` is a sufficient name.
22+
23+
<CodeBlock title="api.yml">
24+
```yaml
25+
name: api
26+
```
27+
</CodeBlock>
28+
29+
## API description
30+
31+
You can define a top level API description. This description will come through in the OpenAPI Specification and Postman collection.
32+
33+
<CodeBlock title="api.yml">
34+
```yaml {2-4}
35+
name: api
36+
docs: |
37+
## Header
38+
This API provides access to...
39+
```
40+
</CodeBlock>
41+
42+
## API version
43+
44+
You can define your header-based API versioning scheme, such as an `X-API-Version`. The supported versions
45+
and default value are specified like so:
46+
47+
<CodeBlock title="api.yml">
48+
```yaml
49+
version:
50+
header: X-API-Version
51+
default: "2.0.0"
52+
values:
53+
- "1.0.0"
54+
- "2.0.0"
55+
- "latest"
56+
```
57+
</CodeBlock>
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
title: Audiences in Fern Definition
3+
subtitle: Use audiences in your Fern Definition to segment your API for different groups of consumers.
4+
---
5+
6+
Audiences are a useful tool for segmenting your API for different consumers. You can configure your Fern Docs to publish documentation specific to an `Audience`. You can use [audiences in your OpenAPI Specification](/learn/api-definition/openapi/audiences), too.
7+
8+
Common examples of audiences include:
9+
10+
- Internal consumers (e.g., frontend developers who use the API)
11+
- Beta testers
12+
- Customers
13+
14+
By default, if no audience is specified, it will be accessible to all consumers.
15+
16+
## Configuration
17+
18+
The Fern Definition has a first-class concept for marking different endpoints, types, and properties for different audiences.
19+
20+
To use audiences in your Fern Definition, add them to `api.yml`.
21+
22+
In the example below, we have created audiences for `internal`, `beta`, and `customer` groups:
23+
24+
```yaml title='api.yml' {2-5}
25+
name: api
26+
audiences:
27+
- internal
28+
- beta
29+
- customers
30+
```
31+
32+
## Audiences for endpoints
33+
34+
To mark an endpoint for a particular consumer, add an `audience` with the relevant groups.
35+
36+
In this example, the `sendEmail` endpoint is only available to internal consumers:
37+
38+
```yaml title='user.yml' {6-7}
39+
service:
40+
base-path: /users
41+
auth: true
42+
endpoints:
43+
sendEmail:
44+
audiences:
45+
- internal
46+
path: /send-email
47+
...
48+
```
49+
50+
## Audiences for types
51+
52+
Types can also be marked for different audiences.
53+
54+
In this example, the `Email` type is available to internal and beta consumers:
55+
56+
```yaml title='user.yml' {5-7}
57+
Email:
58+
properties:
59+
subject: string
60+
body: optional<string>
61+
audiences:
62+
- internal
63+
- beta
64+
```
65+
66+
## Audiences for properties
67+
68+
Properties of a type can also be marked for different audiences.
69+
70+
In this example, the `to` property is available to beta consumers only:
71+
72+
```yaml title='user.yml' {8-9}
73+
Email:
74+
properties:
75+
subject: string
76+
body: optional<string>
77+
to:
78+
type: string
79+
docs: The recipient of the email
80+
audiences:
81+
- beta
82+
```
83+
84+
## Audiences for SDKs
85+
86+
In `generators.yml`, you can apply audience filters so that only certain
87+
endpoints are passed to the generators.
88+
89+
The following example configures the SDKs to filter for `customers`:
90+
91+
```yaml title='generators.yml' {3-4}
92+
groups:
93+
external:
94+
audiences:
95+
- customers
96+
generators:
97+
...
98+
```
99+
100+
## Audiences with docs
101+
102+
If generating Fern Docs, update your `docs.yml` configuration to include your audiences.
103+
104+
The following example shows how to configure your `docs.yml` to publish documentation for the `customers` audience:
105+
106+
<CodeBlock title='docs.yml'>
107+
```yaml {3-4}
108+
navigation:
109+
- api: API Reference
110+
audiences:
111+
- customers
112+
```
113+
</CodeBlock>

0 commit comments

Comments
 (0)