You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: fern/products/sdks/guides/filter-your-endpoints-audiences.mdx
+215-2Lines changed: 215 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,219 @@ title: Filter Your Endpoints (Audiences)
3
3
description: Guide to filtering your API endpoints using audiences.
4
4
---
5
5
6
-
Learn how to use audiences to filter which endpoints are included in your SDKs and documentation.
6
+
Use audiences to generate tailored SDKs for different groups of API consumers. Common examples of audiences include:
7
+
- Internal consumers (e.g., frontend developers who use the API)
8
+
- Beta testers
9
+
- Customers
7
10
8
-
<Warning>Docs are coming soon for this page.<br/><br/>Please [book a demo](https://buildwithfern.com/book-demo) or [reach out to us](https://buildwithfern.com/book-demo) to get set up with this feature. </Warning>
11
+
For both the Fern Definition and OpenAPI spec, configuring audiences involves:
12
+
1. Marking your API elements with audience tags.
13
+
1. Applying filters in `generators.yml`. Without filtering configuration, all endpoints will
14
+
be included in your SDK regardless of their audience tags.
15
+
16
+
17
+
<Tabs>
18
+
<Tabtitle="Fern Definition">
19
+
20
+
Configuring audiences in a Fern Definition involves:
21
+
22
+
1. Explicitly defining audiences in `api.yml`.
23
+
1. Configuring audiences for specific endpoints, types, and properties.
24
+
1. Apply audience filters to your SDK so only certain endpoints are passed to the generators.
25
+
26
+
<Steps>
27
+
### Defining audiences
28
+
29
+
Audiences are explicitly declared in Fern Definition.
30
+
To use audiences in your Fern Definition, add them to `api.yml`.
31
+
32
+
In the example below, we have created audiences for `internal`, `beta`, and `customer` groups:
33
+
34
+
```yaml title='api.yml' {2-5}
35
+
name: api
36
+
audiences:
37
+
- internal
38
+
- beta
39
+
- customers
40
+
```
41
+
### Apply audiences to your endpoints, types, and properties
42
+
43
+
Once you've defined audiences, mark endpoints, types, or properties for a
44
+
particular consumer by adding an `audience` with the relevant groups.
45
+
46
+
<AccordionGroup>
47
+
<Accordion title="Endpoints">
48
+
49
+
In this example, the `sendEmail` endpoint is only available to internal consumers:
50
+
51
+
```yaml title='user.yml' {6-7}
52
+
service:
53
+
base-path: /users
54
+
auth: true
55
+
endpoints:
56
+
sendEmail:
57
+
audiences:
58
+
- internal
59
+
path: /send-email
60
+
...
61
+
```
62
+
</Accordion>
63
+
<Accordion title="Types">
64
+
65
+
Types can also be marked for different audiences.
66
+
67
+
In this example, the `Email` type is available to internal and beta consumers:
68
+
69
+
```yaml title='user.yml' {5-7}
70
+
Email:
71
+
properties:
72
+
subject: string
73
+
body: optional<string>
74
+
audiences:
75
+
- internal
76
+
- beta
77
+
```
78
+
</Accordion>
79
+
<Accordion title="Properties">
80
+
In this example, the `to` property is available to beta consumers only:
81
+
82
+
```yaml title='user.yml' {8-9}
83
+
Email:
84
+
properties:
85
+
subject: string
86
+
body: optional<string>
87
+
to:
88
+
type: string
89
+
docs: The recipient of the email
90
+
audiences:
91
+
- beta
92
+
```
93
+
</Accordion>
94
+
</AccordionGroup>
95
+
96
+
### Set up SDK filters in `generators.yml`
97
+
98
+
In `generators.yml`, you can apply audience filters so that only certain
99
+
endpoints are passed to the generators.
100
+
101
+
The following example configures the SDKs to filter for `customers`:
102
+
103
+
```yaml title='generators.yml' {3-4}
104
+
groups:
105
+
external:
106
+
audiences:
107
+
- customers
108
+
generators:
109
+
...
110
+
```
111
+
</Steps>
112
+
</Tab>
113
+
<Tab title="OpenAPI">
114
+
115
+
Configuring audiences in an OpenAPI spec involves:
116
+
117
+
1. Configuring audience extensions for specific servers, endpoints, schemas, and properties.
118
+
1. Apply audience filters to your SDK so only certain endpoints are passed to the generators.
119
+
120
+
<Note>
121
+
Unlike the Fern Definition, OpenAPI doesn't have a central audience declaration.
122
+
</Note>
123
+
124
+
<Steps>
125
+
### Define audiences
126
+
127
+
OpenAPI uses `x-fern-audiences` to filter to servers, endpoints, schemas and properties.
128
+
129
+
<AccordionGroup>
130
+
<Accordion title="Servers">
131
+
To mark a server with a particular audience, add the `x-fern-server-name` and `x-fern-audiences` extension to the relevant server.
132
+
133
+
In the example below, the `Production` server is only available to public consumers:
134
+
135
+
```yaml title="openapi.yml" {3-5}
136
+
servers:
137
+
- url: https://api.com
138
+
x-fern-server-name: Production
139
+
x-fern-audiences:
140
+
- public
141
+
```
142
+
</Accordion>
143
+
<Accordion title="Endpoints">
144
+
To mark an endpoint with a particular audience, add the `x-fern-audiences` extension to the relevant endpoint.
145
+
146
+
In the example below, the `POST /users/sendEmail` endpoint is only available to public consumers:
147
+
148
+
```yaml title="openapi.yml" {4-5}
149
+
paths:
150
+
/users/sendEmail:
151
+
post:
152
+
x-fern-audiences:
153
+
- public
154
+
operationId: send_email
155
+
```
156
+
</Accordion>
157
+
<Accordion title="Schemas">
158
+
Schemas can be marked for different audiences, as well.
159
+
160
+
In this example, the `Email` type is available to both public and beta customers.
161
+
162
+
```yaml title="openapi.yml" {13-15}
163
+
components:
164
+
schemas:
165
+
Email:
166
+
title: Email
167
+
type: object
168
+
properties:
169
+
subject:
170
+
type: string
171
+
body:
172
+
type: string
173
+
to:
174
+
type: string
175
+
x-fern-audiences:
176
+
- public
177
+
- beta
178
+
```
179
+
</Accordion>
180
+
<Accordion title="Properties">
181
+
In this example, the `to` property is available to beta customers only.
182
+
183
+
```yaml title="openapi.yml" {13-17}
184
+
components:
185
+
schemas:
186
+
Email:
187
+
title: Email
188
+
type: object
189
+
properties:
190
+
subject:
191
+
type: string
192
+
body:
193
+
type: string
194
+
to:
195
+
type: string
196
+
x-fern-audiences:
197
+
- beta
198
+
```
199
+
</Accordion>
200
+
201
+
</AccordionGroup>
202
+
203
+
### Set up SDK filters in `generators.yml`
204
+
205
+
In `generators.yml`, you can apply audience filters so that only certain
206
+
endpoints are passed to the generators.
207
+
208
+
The following example configures the SDK to filter to the `public` audience:
0 commit comments