Skip to content

Commit c2670c9

Browse files
authored
feat(api): add AsyncAPI example (#95)
1 parent 6e1d073 commit c2670c9

2 files changed

Lines changed: 241 additions & 0 deletions

File tree

fern/asyncapi.yaml

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
asyncapi: 3.0.0
2+
info:
3+
title: Plant Store AsyncAPI
4+
version: 1.0.0
5+
description: |
6+
Real-time WebSocket companion to the Plant Store API.
7+
Subscribe to plant lifecycle events via WebSocket connection.
8+
9+
defaultContentType: application/json
10+
11+
servers:
12+
plantStoreWebsocket:
13+
host: ws.plantstore.dev
14+
protocol: wss
15+
description: WebSocket server for Plant Store real-time events.
16+
17+
channels:
18+
plantEvents:
19+
address: /ws/plants
20+
title: Plant events WebSocket
21+
description: |
22+
Connect to receive real-time plant lifecycle events.
23+
Subscribe to specific event types or receive all events.
24+
parameters:
25+
Authorization:
26+
description: Bearer token for authentication.
27+
location: $message.header#/Authorization
28+
eventTypes:
29+
description: |
30+
Comma-separated list of event types to subscribe to.
31+
Valid values: plant.created, plant.updated, plant.status.changed
32+
If omitted, all events are delivered.
33+
location: $message.payload#/eventTypes
34+
plantId:
35+
description: Filter events for a specific plant ID.
36+
location: $message.payload#/plantId
37+
servers:
38+
- $ref: "#/servers/plantStoreWebsocket"
39+
messages:
40+
plantCreated:
41+
$ref: "#/components/messages/PlantCreated"
42+
plantUpdated:
43+
$ref: "#/components/messages/PlantUpdated"
44+
plantStatusChanged:
45+
$ref: "#/components/messages/PlantStatusChanged"
46+
subscribeRequest:
47+
$ref: "#/components/messages/SubscribeRequest"
48+
49+
operations:
50+
subscribe:
51+
action: send
52+
channel:
53+
$ref: "#/channels/plantEvents"
54+
messages:
55+
- $ref: "#/channels/plantEvents/messages/subscribeRequest"
56+
description: Send a subscription request to filter events.
57+
58+
receivePlantEvents:
59+
action: receive
60+
channel:
61+
$ref: "#/channels/plantEvents"
62+
messages:
63+
- $ref: "#/channels/plantEvents/messages/plantCreated"
64+
- $ref: "#/channels/plantEvents/messages/plantUpdated"
65+
- $ref: "#/channels/plantEvents/messages/plantStatusChanged"
66+
description: Receive plant lifecycle events from the server.
67+
68+
components:
69+
messages:
70+
SubscribeRequest:
71+
name: SubscribeRequest
72+
title: Subscribe to event types
73+
payload:
74+
$ref: "#/components/schemas/SubscribeRequestPayload"
75+
examples:
76+
- name: subscribeToCreated
77+
payload:
78+
action: subscribe
79+
eventTypes:
80+
- plant.created
81+
- plant.updated
82+
83+
PlantCreated:
84+
name: PlantCreated
85+
title: Plant created event
86+
payload:
87+
$ref: "#/components/schemas/PlantEventEnvelope"
88+
examples:
89+
- name: fernCreated
90+
payload:
91+
type: plant.created
92+
occurredAt: "2026-02-09T14:12:00Z"
93+
data:
94+
id: 101
95+
name: Fern
96+
status: available
97+
tags:
98+
- green
99+
- leafy
100+
101+
PlantUpdated:
102+
name: PlantUpdated
103+
title: Plant updated event
104+
payload:
105+
$ref: "#/components/schemas/PlantEventEnvelope"
106+
examples:
107+
- name: fernUpdated
108+
payload:
109+
type: plant.updated
110+
occurredAt: "2026-02-09T14:20:00Z"
111+
data:
112+
id: 101
113+
name: Fern
114+
status: sold
115+
tags:
116+
- green
117+
- leafy
118+
119+
PlantStatusChanged:
120+
name: PlantStatusChanged
121+
title: Plant status changed event
122+
payload:
123+
$ref: "#/components/schemas/PlantStatusChangedEnvelope"
124+
examples:
125+
- name: statusChange
126+
payload:
127+
type: plant.status.changed
128+
occurredAt: "2026-02-09T14:21:00Z"
129+
plantId: 101
130+
previousStatus: available
131+
newStatus: sold
132+
133+
schemas:
134+
SubscribeRequestPayload:
135+
type: object
136+
additionalProperties: false
137+
required:
138+
- action
139+
properties:
140+
action:
141+
type: string
142+
enum:
143+
- subscribe
144+
- unsubscribe
145+
eventTypes:
146+
type: array
147+
items:
148+
type: string
149+
enum:
150+
- plant.created
151+
- plant.updated
152+
- plant.status.changed
153+
plantId:
154+
type: integer
155+
description: Filter events for a specific plant ID.
156+
157+
Plant:
158+
type: object
159+
additionalProperties: false
160+
properties:
161+
name:
162+
type: string
163+
category:
164+
type: string
165+
tags:
166+
type: array
167+
items:
168+
type: string
169+
status:
170+
type: string
171+
enum:
172+
- available
173+
- pending
174+
- sold
175+
176+
PlantResponse:
177+
type: object
178+
additionalProperties: false
179+
properties:
180+
id:
181+
type: integer
182+
name:
183+
type: string
184+
status:
185+
type: string
186+
tags:
187+
type: array
188+
items:
189+
type: string
190+
191+
PlantEventEnvelope:
192+
type: object
193+
additionalProperties: false
194+
required:
195+
- type
196+
- occurredAt
197+
- data
198+
properties:
199+
type:
200+
type: string
201+
enum:
202+
- plant.created
203+
- plant.updated
204+
occurredAt:
205+
type: string
206+
format: date-time
207+
data:
208+
$ref: "#/components/schemas/PlantResponse"
209+
210+
PlantStatusChangedEnvelope:
211+
type: object
212+
additionalProperties: false
213+
required:
214+
- type
215+
- occurredAt
216+
- plantId
217+
- previousStatus
218+
- newStatus
219+
properties:
220+
type:
221+
type: string
222+
enum:
223+
- plant.status.changed
224+
occurredAt:
225+
type: string
226+
format: date-time
227+
plantId:
228+
type: integer
229+
previousStatus:
230+
type: string
231+
enum:
232+
- available
233+
- pending
234+
- sold
235+
newStatus:
236+
type: string
237+
enum:
238+
- available
239+
- pending
240+
- sold

fern/generators.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
api:
33
specs:
44
- openapi: openapi.yaml
5+
- asyncapi: asyncapi.yaml

0 commit comments

Comments
 (0)