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
Revert #403, back to #359 with a single commit
Old commits list:
- "oas: default example was wrong""
- "copy oas 3.1 with oas 3.2 changes""
- "more about tag kind and parent""
- "security scheme deprecation""
- "response description is optional""
- "response no content means no content""
- "security schemes can be references now too""
- "removed trailing slash""
- "use newer rfc relative ref pointer links""
- "more about tags, oauth2, and server names""
- "guide: pagination""
- "quick punt at streaming""
- "fix broken link""
- "improved json streaming guide""
- "new and improved json streaming guide""
- "couple more tweaks""
- "link to new spec""
Copy file name to clipboardExpand all lines: src/_guides/openapi/specification/v3.1/documentation/grouping-operations-with-tags.md
+72-48Lines changed: 72 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,22 +15,26 @@ Typically, OpenAPI tags are used to group related endpoints in a meaningful way,
15
15
16
16
```yaml
17
17
tags:
18
-
- name: Stations
18
+
- name: stations
19
+
summary: Stations
19
20
description: |
20
21
Find and filter train stations across Europe, including their location
21
22
and local timezone.
22
23
externalDocs:
23
24
description: Read more
24
25
url: http://docs.example.com/guides/stations
25
-
- name: Trips
26
-
description: |
26
+
- name: trips
27
+
summary: Trips
28
+
description: |
27
29
Timetables and routes for train trips between stations, including pricing
28
30
and availability.
29
-
- name: Bookings
31
+
- name: bookings
32
+
summary: Bookings
30
33
description: |
31
34
Create and manage bookings for train trips, including passenger details
32
35
and optional extras.
33
-
- name: Payments
36
+
- name: payments
37
+
summary: Payments
34
38
description: |
35
39
Pay for bookings using a card or bank account, and view payment
36
40
status and history.
@@ -40,20 +44,28 @@ tags:
40
44
> before the expiry date
41
45
```
42
46
47
+
The `name` property is required and must be unique across all tags in the document. It is used to reference the tag in the `tags` property of an endpoint, and is generally considered as a variable name for the tag.
48
+
49
+
OpenAPI v3.2 introduced the `summary` property, which is a human-readable short description of the tag. Often this is just a Case Title version of the `name` but it can be anything, just keep it short so it fits nicely into API reference documentation navigation menus as that's generally what it's used for.
50
+
51
+
The `description` property can be used to provide more detailed information about the tag. This can be really in depth and fully explain what the concept means, because e.g: Account or Unit could mean infinite different things in different domains.
52
+
53
+
You can also link to external documentation using the `externalDocs` property.
54
+
55
+
## Referencing Tags in Endpoints
56
+
43
57
Once you've created these tags, you can use them to group related endpoints in your API using the `tags` property on the endpoint as follows:
44
58
45
59
```yaml
46
60
paths:
47
61
/stations:
48
62
get:
49
63
summary: Get a list of train stations
50
-
tags:
51
-
- Stations
64
+
tags: [ stations ]
52
65
/trips:
53
66
get:
54
67
summary: Get available train trips
55
-
tags:
56
-
- Trips
68
+
tags: [ trips ]
57
69
```
58
70
59
71
You can also apply multiple tags to an operation:
@@ -63,9 +75,7 @@ paths:
63
75
/bookings/{bookingId}/payment:
64
76
post:
65
77
summary: Pay for a Booking
66
-
tags:
67
-
- Bookings
68
-
- Payments
78
+
tags: [ bookings, payments ]
69
79
```
70
80
71
81
## Benefits of OpenAPI Tags
@@ -75,15 +85,17 @@ Tags are a powerful tool for improving the usability of your OpenAPI document. B
75
85
### Tags Can Describe Endpoint Groups
76
86
77
87
When specifying your tags in the root level of your API contract, you can give context to the tag using the `description` property.
88
+
78
89
Let’s take [Bump.sh API documentation](https://bump.sh/demo/doc/bump). Here is how the `Diffs` tag is created and described in [Bump.sh API Contract](https://developers.bump.sh):
79
90
80
91
```yaml
81
92
tags:
82
-
- name: Diffs
93
+
- name: diff
94
+
summary: Diffs
83
95
description: Diff summary of changes in the API
84
96
```
85
97
86
-
The documentation will show the `Diffs` property like this:
98
+
The documentation will show the `diff` tag like this:
87
99
88
100

89
101
[*See it live*](https://bump.sh/demo/doc/bump/group/endpoint-diffs)
@@ -98,7 +110,7 @@ In the code snippet below, the `externalDocs` property provides a link to a URL
98
110
99
111
```yaml
100
112
tags:
101
-
- name: Diffs
113
+
- name: diff
102
114
description: Diff summary of changes in the API
103
115
externalDocs:
104
116
description: More details about Diff
@@ -115,17 +127,23 @@ When specifying your OpenAPI or AsyncAPI tags in the root of your API contract,
115
127
116
128
```yaml
117
129
tags:
118
-
- name: Diffs
130
+
- name: diff
131
+
summary: Diffs
119
132
description: Diff summary of changes in the API
120
-
- name: Ping
133
+
- name: ping
134
+
summary: Ping
121
135
description: Monitoring status endpoints
122
-
- name: Previews
136
+
- name: preview
137
+
summary: Previews
123
138
description: Preview for documentation file
124
-
- name: Versions
139
+
- name: version
140
+
summary: Versions
125
141
description: Deploy your API contracts
126
-
- name: Validations
142
+
- name: validation
143
+
summary: Validations
127
144
description: Check & validate your API contracts
128
-
- name: Hubs
145
+
- name: hub
146
+
summary: Hubs
129
147
description: Interact with your Hubs
130
148
```
131
149
@@ -143,18 +161,19 @@ Now that you understand what tags are and their benefits, you'll see some best p
143
161
### Tag Everything
144
162
145
163
When using tags, make sure you tag all your endpoints.
146
-
Notice how all diff-related endpoints are tagged with the `Diffs` tag in this snippet:
164
+
165
+
Notice how all diff-related endpoints are tagged with the `diffs` tag in this snippet:
147
166
148
167
```yaml
149
168
paths:
150
169
/diffs:
151
170
post:
152
-
tags: [ Diffs ]
171
+
tags: [ diff ]
153
172
summary: Create a diff
154
173
[...]
155
174
/diffs/{id}:
156
175
get:
157
-
tags: [ Diffs ]
176
+
tags: [ diff ]
158
177
summary: Fetch detailed information from an existing diff
159
178
[...]
160
179
```
@@ -171,22 +190,25 @@ To ensure your endpoints remain logically grouped and ordered, always tag every
171
190
172
191
When defining the list of tags in the root of your API contract, make sure not to duplicate tag names. Since the tag's `name` property links an endpoint to a tag, duplicate names are likely to confuse developers looking at the API contract.
173
192
174
-
The code snippet below contains the root Tag Object in an API contract. Notice how the `Validations` tag has been duplicated, and the second definition contains a different description to the first:
193
+
The code snippet below contains the root Tag Object in an API contract. Notice how the `validation` tag has been duplicated, and the second definition contains a different description to the first:
175
194
176
195
```yaml
177
196
tags:
178
-
- name: Diffs
179
-
description: Diff summary of changes in the API
180
-
- name: Versions
181
-
description: Deploy your API contracts
182
-
- name: Validations
183
-
description: Check & validate your API contracts
184
-
- name: Hubs
185
-
description: Interact with your Hubs
186
-
- name: "Documentation change"
187
-
description: Check & validate your API contracts
188
-
- name: Validations
189
-
description: Validate your API status
197
+
- name: diff
198
+
summary: Diffs
199
+
description: Diff summary of changes in the API.
200
+
- name: version
201
+
summary: Versions
202
+
description: Deploy your API contracts.
203
+
- name: validation
204
+
summary: Validations
205
+
description: Check & validate your API contracts.
206
+
- name: documentation_change
207
+
summary: Documentation Change
208
+
description: Check & validate your API contracts.
209
+
- name: validation
210
+
summary: Validations
211
+
description: Validate your API status.
190
212
```
191
213
192
214
These duplicate tags would confuse anyone trying to understand your API contract, as they wouldn't know which of the two tag definitions an endpoint belongs to.
@@ -195,21 +217,23 @@ Instead, make sure you define and describe every tag only once in the root Tag O
195
217
196
218
```yaml
197
219
tags:
198
-
- name: Diffs
199
-
description: Diff summary of changes in the API
200
-
- name: Versions
201
-
description: Deploy your API contracts
202
-
- name: Validations
203
-
description: Check & validate your API contracts
204
-
- name: Hubs
205
-
description: Interact with your Hubs
206
-
- name: "Documentation change"
207
-
description: Check & validate your API contracts
220
+
- name: diff
221
+
summary: Diffs
222
+
description: Diff summary of changes in the API.
223
+
- name: version
224
+
summary: Versions
225
+
description: Deploy your API contracts.
226
+
- name: validation
227
+
summary: Validations
228
+
description: Check & validate your API contracts.
229
+
- name: documentation_change
230
+
summary: Documentation Change
231
+
description: Check & validate your API contracts.
208
232
```
209
233
210
234
### Define All Your OpenAPI Tags in the Root Tag Object
211
235
212
-
The OpenAPI specification [doesn't require you to define all your tags in the root Tag Object of your API contract](https://swagger.io/specification/#:~:text=A%20list%20of,MUST%20be%20unique). This means you can add a tag to an endpoint without listing it in the root Tag Object, but this is a bad idea. You won't be able to control what order the OpenAPI tags should appear in, and you won't be able to add a description or provide a link to external documentation for that tag. It can also confuse developers browsing your API contract as they won't see a list of all the tags used in the API contract.
236
+
The OpenAPI specification [doesn't require you to define all your tags in the root Tag Object of your API contract](https://spec.openapis.org/oas/v3.1.0#:~:text=A%20list%20of,MUST%20be%20unique). This means you can add a tag to an endpoint without listing it in the root Tag Object, but this is a bad idea. You won't be able to control what order the OpenAPI tags should appear in, and you won't be able to add a description or provide a link to external documentation for that tag. It can also confuse developers browsing your API contract as they won't see a list of all the tags used in the API contract.
213
237
214
238
As an example, consider the code snippet below where the `Previews` and the `Ping` tags has not been included in the root Tag Object:
Copy file name to clipboardExpand all lines: src/_guides/openapi/specification/v3.1/extending/overlays.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,7 +103,7 @@ actions:
103
103
104
104
These descriptions (which can be much longer and full of even more Markdown) will then show up in API Documentation, pride of place, ready to explain the concepts to the user before they get stuck into what specific endpoints are about.

Copy file name to clipboardExpand all lines: src/_guides/openapi/specification/v3.1/understanding-structure/basic-structure.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,7 +63,7 @@ Only the following fields are **required**:
63
63
- `title`- Your API probably has a name, and if not perhaps now is a good time to think of one thats useful for public consumption.
64
64
- `version`- The version of your OpenAPI document, which does not have to related to the API version, or the OpenAPI Specification version.
65
65
66
-
Updating the version number when you make changes is pretty common, and keeping it seperate from the API version at first feels a little bit odd, but soon makes sense. After all, you can fix issues with the OpenAPI document that produce no change whatsoever in the API, and vice-versa.
66
+
Updating the version number when you make changes is pretty common, and keeping it separate from the API version at first feels a little bit odd, but soon makes sense. After all, you can fix issues with the OpenAPI document that produce no change whatsoever in the API, and vice-versa.
67
67
68
68
These other fields are **optional**:
69
69
@@ -351,7 +351,7 @@ The name is often displayed to users in human-readable documentation so its best
351
351
Putting it all together, here is a simple example of an OpenAPI document:
352
352
353
353
```yaml
354
-
openapi: 3.0.3
354
+
openapi: 3.1.1
355
355
info:
356
356
title: Sample API
357
357
description: A sample API to illustrate OpenAPI concepts.
0 commit comments