Skip to content

Commit 2300fb2

Browse files
authored
Merge pull request #105 from AndrewAllison/patch-1
Update swagger.md
2 parents 1ce37e7 + 4cc962f commit 2300fb2

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

docs/plugins/swagger.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,53 @@ new Elysia()
9595
}))
9696
.listen(8080)
9797
```
98+
99+
## Using Tags
100+
Elysia has the ability to separate the endpoints into groups by using Swaggers tag system
101+
102+
Firstly define the available tags in the swagger config object
103+
104+
```typescript
105+
app.use(
106+
swagger({
107+
documentation: {
108+
tags: [
109+
{ name: 'App', description: 'General endpoints' },
110+
{ name: 'Auth', description: 'Authentication endpoints' }
111+
]
112+
}
113+
})
114+
)
115+
```
116+
117+
Then use the details property of the endpoint configuration section to assign that endpoint to the group
118+
119+
```typescript
120+
app.get('/', () => 'Hello Elysia', {
121+
detail: {
122+
tags: ['App']
123+
}
124+
})
125+
126+
app.group('/auth', (app) =>
127+
app.post(
128+
'/sign-up',
129+
async ({ body }) =>
130+
db.user.create({
131+
data: body,
132+
select: {
133+
id: true,
134+
username: true
135+
}
136+
}),
137+
{
138+
detail: {
139+
tags: ['Auth']
140+
}
141+
}
142+
)
143+
)
144+
```
145+
146+
Which will produce a swagger page like the following
147+
<img width="1446" alt="image" src="https://github.com/elysiajs/documentation/assets/184729/8caee6c0-4262-4a5c-b225-196cf74c338b">

0 commit comments

Comments
 (0)