-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFern Docs.rtf
20389 lines (20388 loc) · 684 KB
/
Fern Docs.rtf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{\rtf1\ansi\ansicpg1252\cocoartf2820
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fmodern\fcharset0 Courier;}
{\colortbl;\red255\green255\blue255;\red0\green0\blue0;}
{\*\expandedcolortbl;;\cssrgb\c0\c0\c0;}
\margl1440\margr1440\vieww11520\viewh8400\viewkind0
\deftab720
\pard\pardeftab720\partightenfactor0
\f0\fs26 \cf0 \expnd0\expndtw0\kerning0
\outl0\strokewidth0 \strokec2 # Welcome\
\
> Input OpenAPI. Output SDKs and Docs.\
\
<Note>\
Our entire docs website (the one you're looking at right now!) is built using Fern. \
\
[See the source Markdown.](https://github.com/fern-api/fern/blob/main/fern/pages/welcome.mdx?plain=1)\
</Note>\
\
## Products\
\
<Cards cols=\{3\}>\
<Card title="API First Development" icon="fa-regular fa-pen" href="/learn/api-definition/introduction/what-is-an-api-definition">\
Start with an API Definition\
</Card>\
\
<Card title="Docs" icon="fa-regular fa-browser" href="/learn/docs/getting-started/quickstart">\
A beautiful documentation website\
</Card>\
\
<Card title="SDKs" icon="fa-brands fa-codepen" href="/learn/sdks/introduction/overview">\
Idiomatic client libraries\
</Card>\
</Cards>\
\
## Motivation\
\
<div>\
Stripe, Twilio, and AWS have the resources to invest in internal tooling for developer\
experience. They provide client libraries in multiple languages and developer documentation\
that stays up-to-date.\
\
We are building Fern to productize this process and make it accessible to all\
software companies.\
</div>\
\
<ButtonGroup>\
<Button href="https://buildwithfern.com/contact" intent="primary" rightIcon="arrow-right" large>\
Schedule a demo with our team!\
</Button>\
\
<Button href="https://buildwithfern.com/showcase" minimal large>\
View our showcase\
</Button>\
</ButtonGroup>\
\
\
# What is an API Definition?\
\
> Describes the contract between the API provider and API consumer\
\
<Info>\
An API Definition is a document that defines the structure of the API. It includes the **endpoints**,\
**request and response schemas**, and **authentication** requirements.\
</Info>\
\
Fern integrates with several API definition formats:\
\
<AccordionGroup>\
<Accordion title="OpenAPI (Swagger)">\
Formerly known as Swagger, [OpenAPI](https://swagger.io/specification/) is the most popular API definition format.\
OpenAPI can be used to document RESTful APIs and is defined in a YAML or JSON file.\
\
Check out an example OpenAPI Specification for the Petstore API [here](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)\
\
```yaml maxLines=\{0\}\
openapi: 3.0.2\
tags:\
- name: pet\
description: Everything about your Pets\
paths:\
/pet:\
post:\
tags:\
- pet\
summary: Add a new pet to the store\
description: Add a new pet to the store\
operationId: addPet\
requestBody:\
description: Create a new pet in the store\
required: true\
content:\
application/json:\
schema:\
$ref: '#/components/schemas/Pet'\
application/xml:\
schema:\
$ref: '#/components/schemas/Pet'\
application/x-www-form-urlencoded:\
schema:\
$ref: '#/components/schemas/Pet'\
responses:\
'200':\
description: Successful operation\
content:\
application/xml:\
schema:\
$ref: '#/components/schemas/Pet'\
application/json:\
schema:\
$ref: '#/components/schemas/Pet'\
'405':\
description: Invalid input\
components:\
schemas:\
Pet:\
required:\
- name\
- photoUrls\
properties:\
id:\
type: integer\
format: int64\
example: 10\
name:\
type: string\
example: doggie\
category:\
$ref: '#/components/schemas/Category'\
photoUrls:\
type: array\
xml:\
wrapped: true\
items:\
type: string\
xml:\
name: photoUrl\
tags:\
type: array\
xml:\
wrapped: true\
items:\
$ref: '#/components/schemas/Tag'\
xml:\
name: tag\
status:\
type: string\
description: pet status in the store\
enum:\
- available\
- pending\
- sold\
xml:\
name: pet\
type: object\
```\
</Accordion>\
\
<Accordion title="AsyncAPI">\
[AsyncAPI](https://v2.asyncapi.com/docs) is a specification for defining event-driven APIs. It is used to document APIs that use\
WebSockets, MQTT, and other messaging protocols.\
\
Check out an example AsyncAPI spec for a chat application below:\
\
```yaml maxLines=\{0\}\
asyncapi: 2.0.0\
info:\
title: Chat server\
version: 1.0.0\
\
servers:\
Production:\
url: chat.com\
protocol: ws\
\
channels:\
"/application":\
bindings:\
ws:\
query:\
type: object\
properties:\
apiKey:\
type: string\
description: The API key for the client\
minimum: 1\
bindingVersion: 0.1.0\
subscribe:\
operationId: sendMessage\
message:\
$ref: '#/components/messages/SendMessage'\
publish:\
operationId: receiveMessage\
message:\
$ref: '#/components/messages/ReceiveMessage'\
\
components:\
messages:\
SendMessage:\
payload:\
message: string\
ReceiveMessage:\
payload:\
message: string\
from: \
type: string\
description: The userId for the sender of the message\
```\
</Accordion>\
\
<Accordion title="Fern Definition">\
The Fern Definition is our take on a simpler API definition format. It is designed with **best-practices**,\
supports **both RESTful and event-driven APIs**, and is optimized for **SDK generation**.\
\
<Note>\
The Fern Definition is inspired from internal API Definition formats built at companies like\
[Amazon](https://smithy.io/2.0/index.html), [Google](https://grpc.io/), [Palantir](https://blog.palantir.com/introducing-conjure-palantirs-toolchain-for-http-json-apis-2175ec172d32),\
Twilio and Stripe. These companies **rejected** OpenAPI and built their own version.\
</Note>\
\
Check out an example Fern Definition below:\
\
```yaml maxLines=\{0\}\
types:\
MovieId: string\
\
Movie:\
properties:\
id: MovieId\
title: string\
rating:\
type: double\
docs: The rating scale is one to five stars\
\
CreateMovieRequest:\
properties:\
title: string\
rating: double\
\
service:\
auth: false\
base-path: /movies\
endpoints:\
createMovie:\
docs: Add a movie to the database\
method: POST\
path: /create-movie\
request: CreateMovieRequest\
response: MovieId\
\
getMovie:\
method: GET\
path: /\{movieId\}\
path-parameters:\
movieId: MovieId\
response: Movie\
errors:\
- MovieDoesNotExistError\
\
errors:\
MovieDoesNotExistError:\
status-code: 404\
type: MovieId\
```\
</Accordion>\
</AccordionGroup>\
\
## Why create an API Definition ?\
\
Once you have an API definition, Fern will use it as an input to generate artifacts\
like SDKs and API Reference documentation. Every time you update the API definition,\
you can regenerate these artifacts and ensure they are always up-to-date.\
\
<CardGroup cols=\{2\}>\
<Card title="SDKs" icon="brands github">\
Client libraries in multiple languages.\
</Card>\
\
<Card title="Documentation" icon="regular browser">\
A Stripe-like API documentation website.\
</Card>\
\
<Card title="Postman Collection" icon=\{<img src="https://cdn.worldvectorlogo.com/logos/postman.svg" alt="Postman logo"/>\}>\
A published Postman collection, with example request and responses.\
</Card>\
\
<Card title="Server Boilerplate" icon=\{<img src="https://cdn.worldvectorlogo.com/logos/fastapi-1.svg" alt="FastAPI logo" />\}>\
Pydantic models for FastAPI or controllers for your Spring Boot application.\
</Card>\
</CardGroup>\
\
\
# The Fern Folder\
\
> Describes the Fern folder structure\
\
Configuring fern starts with the `fern` folder. The fern folder contains your API definitions,\
generators, and your CLI version.\
\
## Directory structure\
\
When you run `fern init`, your Fern folder will be initialized with the following files:\
\
```bash\
fern/\
\uc0\u9500 \u9472 fern.config.json\
\uc0\u9500 \u9472 generators.yml\
\uc0\u9492 \u9472 definition/\
\uc0\u9500 \u9472 api.yml\
\uc0\u9492 \u9472 imdb.yml\
```\
\
If you want to initialize Fern with an OpenAPI Specification, run `fern init --openapi path/to/openapi` instead.\
\
```yaml\
fern/\
\uc0\u9500 \u9472 fern.config.json\
\uc0\u9500 \u9472 generators.yml # required on Fern version 0.41.0 and above\
\uc0\u9492 \u9472 openapi/\
\uc0\u9500 \u9472 openapi.yml\
```\
\
### `fern.config.json`\
\
Every fern folder has a single `fern.config.json` file. This file stores the organization and\
the version of the Fern CLI that you are using.\
\
```json\
\{\
"organization": "imdb",\
"version": "0.31.2"\
\}\
```\
\
Every time you run a fern CLI command, the CLI downloads itself at the correct version to ensure\
determinism.\
\
<Note>\
To upgrade the CLI, run \
\
`fern upgrade`\
\
. This will update the version field in \
\
`fern.config.json`\
\
\
</Note>\
\
### `generators.yml`\
\
The `generators.yml` file can include information about where your API specification is located, along with which generators you are using, where each package gets published, as well as configuration specific to each generator.\
\
<AccordionGroup>\
<Accordion title="generators.yml for Python + TypeScript SDKs">\
```yaml\
api: \
path: ./path/to/openapi.yml\
groups:\
public:\
generators:\
- name: fernapi/fern-python-sdk\
version: 3.0.0\
output:\
location: pypi\
package-name: imdb\
token: $\{PYPI_TOKEN\}\
github:\
repository: imdb/imdb-python\
config:\
client_class_name: imdb\
- name: fernapi/fern-typescript-node-sdk\
version: 0.31.0\
output:\
location: npm\
package-name: imdb\
token: $\{NPM_TOKEN\}\
github:\
repository: imdb/imdb-node\
config:\
namespaceExport: imdb\
```\
</Accordion>\
\
<Accordion title="generators.yml for locating an API definition">\
```yaml\
api: \
path: ./path/to/openapi.yml\
```\
</Accordion>\
</AccordionGroup>\
\
## Multiple APIs\
\
The Fern folder is capable of housing multiple API definitions. Instead of placing your API definition at the top-level, you can nest them within an `apis` folder. Be sure to include a `generators.yml` file within each API folder that specifies the location of the API definition.\
\
<Tabs>\
<Tab title="OpenAPI Definition">\
```bash\
fern/\
\uc0\u9500 \u9472 fern.config.json\
\uc0\u9500 \u9472 generators.yml\
\uc0\u9492 \u9472 apis/\
\uc0\u9492 \u9472 imdb/\
\uc0\u9500 \u9472 generators.yml\
\uc0\u9492 \u9472 openapi/\
\uc0\u9500 \u9472 openapi.yml\
\uc0\u9492 \u9472 disney/\
\uc0\u9500 \u9472 generators.yml\
\uc0\u9492 \u9472 openapi/\
\uc0\u9500 \u9472 openapi.yml\
```\
</Tab>\
\
<Tab title="Fern Definition">\
```bash\
fern/\
\uc0\u9500 \u9472 fern.config.json\
\uc0\u9500 \u9472 generators.yml\
\uc0\u9492 \u9472 apis/\
\uc0\u9492 \u9472 imdb/\
\uc0\u9500 \u9472 generators.yml\
\uc0\u9492 \u9472 definition/\
\uc0\u9500 \u9472 api.yml\
\uc0\u9492 \u9472 imdb.yml\
\uc0\u9492 \u9472 disney/\
\uc0\u9500 \u9472 generators.yml\
\uc0\u9492 \u9472 definition/\
\uc0\u9500 \u9472 api.yml\
\uc0\u9492 \u9472 disney.yml\
```\
</Tab>\
</Tabs>\
\
\
# What is an OpenAPI Specification?\
\
> OpenAPI is a standard for documenting REST APIs\
\
The OpenAPI Specification (OAS) is a framework used by developers to document REST APIs. The specification\
written in JSON or YAML and contains all of your endpoints, parameters, schemas, and authentication schemes.\
Fern is compatible with the latest OAS release, which is currently [v3.1.1](https://spec.openapis.org/#openapi-specification).\
\
<Info>\
Considering options to generate an OpenAPI spec? Get live support \
\
[here](https://fern-community.slack.com/join/shared_invite/zt-2dpftfmif-MuAegl8AfP_PK8s2tx350Q%EF%BB%BF#/shared-invite/email)\
\
\
</Info>\
\
Below is an example of an OpenAPI file:\
\
```yaml openapi.yml \
openapi: 3.0.2\
info:\
title: Petstore - OpenAPI 3.0\
description: |-\
This is a sample Pet Store Server based on the OpenAPI 3.0 specification.\
paths:\
"/pet":\
put:\
tags:\
- pet\
summary: Update an existing pet\
description: Update an existing pet by Id\
operationId: updatePet\
requestBody:\
description: Update an existent pet in the store\
content:\
application/json:\
schema:\
"$ref": "#/components/schemas/Pet"\
required: true\
responses:\
'200':\
description: Successful operation\
content:\
application/json:\
schema:\
"$ref": "#/components/schemas/Pet"\
'400':\
description: Invalid ID supplied\
'404':\
description: Pet not found\
'405':\
description: Validation exception\
security:\
- api_key\
components:\
schemas:\
Category:\
type: object\
properties:\
id:\
type: integer\
format: int64\
example: 1\
name:\
type: string\
example: Dogs\
Tag:\
type: object\
properties:\
id:\
type: integer\
format: int64\
name:\
type: string\
Pet:\
required:\
- name\
- photoUrls\
type: object\
properties:\
id:\
type: integer\
format: int64\
example: 10\
name:\
type: string\
example: doggie\
category:\
"$ref": "#/components/schemas/Category"\
photoUrls:\
type: array\
items:\
type: string\
tags:\
type: array\
items:\
"$ref": "#/components/schemas/Tag"\
status:\
type: string\
description: pet status in the store\
enum:\
- available\
- pending\
- sold\
securitySchemes:\
api_key:\
type: apiKey\
name: api_key\
in: header\
```\
\
## Setup your Fern folder\
\
Start by initializing your Fern folder with an OpenAPI spec\
\
<CodeGroup>\
```sh file\
fern init --openapi ./path/to/openapi\
```\
\
```sh url\
fern init --openapi https://host/path/to/openapi\
```\
</CodeGroup>\
\
This will initialize a directory like the following\
\
```\
fern/\
\uc0\u9500 \u9472 fern.config.json\
\uc0\u9500 \u9472 generators.yml\
\uc0\u9492 \u9472 openapi/\
\uc0\u9500 \u9472 openapi.yml\
```\
\
\
# Authentication\
\
> Model auth schemes such as bearer, basic, and api key.\
\
Configuring authentication schemes happens in the `components.securitySchemes` section of OpenAPI.\
\
```yml title="openapi.yml" \{2-3\}\
components: \
securitySchemes: \
...\
```\
\
<Note>\
To apply a security scheme across all endpoints, reference the `securityScheme` within the `security` section of your OpenAPI Specification.\
\
```yml title="openapi.yml" \{3, 5-6\}\
components: \
securitySchemes: \
AuthScheme:\
...\
security: \
- AuthScheme: []\
```\
</Note>\
\
## Bearer security scheme\
\
Start by defining a `bearer` security scheme in your `openapi.yml`:\
\
```yml title="openapi.yml" \{3-5\}\
components:\
securitySchemes:\
BearerAuth:\
type: http\
scheme: bearer\
```\
\
This will generate an SDK where the user would have to provide\
a mandatory argument called `token`.\
\
```ts index.ts\
const client = new Client(\{\
token: "ey34..."\
\})\
```\
\
If you want to control variable naming and the environment variable to scan,\
use the configuration below:\
\
```yaml title="openapi.yml" \{6-8\}\
components:\
securitySchemes:\
BearerAuth:\
type: http\
scheme: bearer\
x-fern-bearer: \
name: apiKey\
env: PLANTSTORE_API_KEY\
```\
\
The generated SDK would look like:\
\
```ts index.ts\
\
// Uses process.env.PLANTSTORE_API_KEY\
let client = new Client(); \
\
// token has been renamed to apiKey\
client = new Client(\{\
apiKey: "ey34..."\
\})\
```\
\
## Basic security scheme\
\
Start by defining a `basic` security scheme in your `openapi.yml`:\
\
```yaml title="openapi.yml" \{3-5\}\
components:\
securitySchemes:\
BasicAuth:\
type: http\
scheme: basic\
```\
\
This will generate an SDK where the user would have to provide\
a mandatory arguments called `username` and `password`.\
\
```ts index.ts\
const client = new Client(\{\
username: "joeschmoe"\
password: "ey34..."\
\})\
```\
\
If you want to control variable naming and environment variables to scan,\
use the configuration below:\
\
```yaml title="openapi.yml" \{6-12\}\
components:\
securitySchemes:\
BasicAuth:\
type: http\
scheme: basic\
x-fern-basic:\
username:\
name: clientId\
env: PLANTSTORE_CLIENT_ID\
password:\
name: clientSecret\
env: PLANTSTORE_CLIENT_SECRET\
```\
\
The generated SDK would look like:\
\
```ts index.ts\
\
// Uses process.env.PLANTSTORE_CLIENT_ID and process.env.PLANTSTORE_CLIENT_SECRET\
let client = new Client(); \
\
// parameters have been renamed\
client = new Client(\{\
clientId: "joeschmoe", \
clientSecret: "ey34..."\
\})\
```\
\
## ApiKey security scheme\
\
Start by defining an `apiKey` security scheme in your `openapi.yml`:\
\
```yml title="openapi.yml" \{3-5\}\
components: \
securitySchemes: \
ApiKey: \
type: apiKey\
in: header\
name: X_API_KEY\
```\
\
This will generate an SDK where the user would have to provide\
a mandatory argument called `apiKey`.\
\
```ts index.ts\
const client = new Client(\{\
apiKey: "ey34..."\
\})\
```\
\
If you want to control variable naming and environment variables to scan,\
use the configuration below:\
\
```yaml title="openapi.yml" \{7-10\}\
components: \
securitySchemes: \
ApiKey: \
type: apiKey\
in: header\
name: X_API_KEY\
x-fern-header:\
name: apiToken\
env: PLANTSTORE_API_KEY\
prefix: "Token " # Optional \
```\
\
The generated SDK would look like:\
\
```ts index.ts\
\
// Uses process.env.PLANTSTORE_API_KEY\
let client = new Client(); \
\
// parameters have been renamed\
client = new Client(\{\
apiToken: "ey34..."\
\})\
```\
\
## Multiple security schemes\
\
If you would like to define multiple security schemes, simply\
list them under `components.securitySchemes`. For example, if you wanted to support\
`basic` and `apiKey` security schemes, see the example below:\
\
```yaml title="openapi.yml" \{3,6\}\
components: \
securitySchemes: \
BearerAuth:\
type: http\
scheme: bearer \
ApiKey: \
type: apiKey\
in: header\
name: X_API_KEY \
```\
\
\
# HTTP JSON Endpoints\
\
> Document HTTP JSON APIs with the `application/json` content type\
\
Endpoints in OpenAPI are defined underneath the `paths` key. Below is an example of defining\
a single endpoint:\
\
```yml title="openapi.yml" maxLines=0 \{2-18\}\
paths:\
/pets:\
post:\
summary: Create a new pet\
description: Creates a new pet with the provided information\
requestBody:\
required: true\
content:\
application/json:\
schema:\
$ref: '#/components/schemas/Pet'\
responses:\
'200':\
description: User created successfully\
content:\
application/json:\
schema:\
$ref: '#/components/schemas/Pet'\
```\
\
## Examples\
\
You can provide examples of requests and responses by using the `examples` key.\
\
```yaml title="openapi.yml" \{12-17,25-30\}\
paths:\
/pets:\
post:\
summary: Create a new pet\
description: Creates a new pet with the provided information\
requestBody:\
required: true\
content:\
application/json:\
schema:\
$ref: '#/components/schemas/Pet'\
examples:\
PetExample:\
summary: This is an example of a Pet\
value: \
name: Markley\
id: 44\
responses:\
'200':\
description: A Pet object\
content:\
application/json:\
schema:\
$ref: '#/components/schemas/Pet'\
examples:\
PetExample:\
summary: This is an example of a Pet\
value: \
name: Markley\
id: 44\
```\
\
\
# Multipart File Upload\
\
> Document endpoints with the `multipart/form-data` content type\
\
Multipart requests combine one or more sets of data into a single body, separated by boundaries.\
You typically use these requests for file uploads and for transferring data of several types in a single request\
(for example, a file along with a JSON object).\
\
```yml title="openapi.yml" maxLines=0 \{12-24\}\
paths:\
/upload:\
post:\
summary: Upload a file\
description: Upload a file using multipart/form-data encoding\
operationId: uploadFile\
tags:\
- file\
requestBody:\
required: true\
content:\
multipart/form-data:\
schema:\
type: object\
properties:\
file:\
type: string\
format: binary\
description: The file to upload\
description:\
type: string\
description: A description of the file (optional)\
required:\
- file\
responses:\
"200":\
description: Successful upload\
content:\
application/json:\
schema:\
type: object\
properties:\
message:\
type: string\
fileId:\
type: string\
```\
\
Any request body that is defined with a `multipart/form-data` content type, will be\
treated as a multipart request. Within a given multipart request, a string parameter with\
`format:binary` will represent an arbitrary file.\
\
## Array of Files\
\
If your endpoint supports an array of files, then your request body must use\
an array type.\
\
```yml openapi.yml \{12-17\}\
paths:\
/upload:\
post:\
summary: Upload multiple files\
operationId: uploadFiles\
requestBody:\
content:\
multipart/form-data:\
schema:\
type: object\
properties:\
files:\
type: array\
items:\
type: string\
format: binary\
description: An array of files to upload\
```\
\
\
# Server Sent Events and Streaming APIs\
\
> Use the `x-fern-streaming` extension to model streaming endpoints\
\
<Note>\
The `x-fern-streaming` extension allows you to represent endpoints that are streaming.\
</Note>\
\
## JSON streaming\
\
If your API returns a series of `JSON` chunks as seen below\
\
```json\
\{ "text": "Hi, I am a" \}\
\{ "text": "chatbot. Do you have any"\}\
\{ "text": "questions for me"\}\
```\
\
then simply add the `x-fern-streaming: true` to your OpenAPI operation.\
\
```yaml title="openapi.yml" \{4\}\
paths:\
/logs:\
post:\
x-fern-streaming: true\
responses:\
"200":\
content:\
application/json:\
schema:\
$ref: "#/components/schemas/Chat"\
components:\
schemas:\
Chat:\
type: object\
properties:\
text:\
type: string\
```\
\
## Server sent events\
\
If your API returns server-sent-events, with the `data` and `event` keys as seen below\
\
```json\
data: \{ "text": "Hi, I am a" \}\
data: \{ "text": "chatbot. Do you have any"\}\
data: \{ "text": "questions for me"\}\
```\
\
then make sure to include `format: sse`.\
\
```yaml title="openapi.yml" \{4-5\}\
paths:\
/logs:\
post:\
x-fern-streaming: \
format: sse\
responses:\
"200":\
content:\
application/json:\
schema:\
$ref: "#/components/schemas/Chat"\
components:\
schemas:\
Chat:\
type: object\
properties:\
text:\
type: string\
```\
\
## `Stream` parameter\
\
It has become common practice for endpoints to have a `stream` parameter that\
controls whether the response is streamed or not. Fern supports this pattern in a first\
class way.\
\
Simply specify the `stream-condition` as well as the ordinary response and the streaming response:\
\
```yaml title="openapi.yml" \{4-10\}\
paths:\
/logs:\
post:\
x-fern-streaming: \
format: sse\
stream-condition: $request.stream\
response: \