Skip to content

Commit 02f3635

Browse files
committed
OpenAPI v3.2 guide
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""
1 parent a9f2713 commit 02f3635

39 files changed

+7299
-53
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
collection_name: guides
2+
root: /guides/openapi/specification/v3.2
3+
resources:
4+
- type: category
5+
label: Introduction to OpenAPI
6+
items:
7+
- label: What is OpenAPI?
8+
link: /introduction/what-is-openapi/
9+
- label: History and Evolution of OpenAPI
10+
link: /introduction/history/
11+
- label: Benefits of Using OpenAPI
12+
link: /introduction/benefits/
13+
- type: category
14+
label: Understanding OpenAPI Structure
15+
items:
16+
- label: Basic Structure
17+
link: /understanding-structure/basic-structure/
18+
- label: Defining API Servers
19+
link: /understanding-structure/api-servers/
20+
- label: Paths and Operations
21+
link: /understanding-structure/paths-operations/
22+
- label: Parameters (Path, Query, Header, and Cookie)
23+
link: /understanding-structure/parameters/
24+
- label: Parameter Serialization
25+
link: /understanding-structure/parameter-serialization/
26+
- label: HTTP Requests
27+
link: /understanding-structure/http-requests/
28+
- label: HTTP Responses
29+
link: /understanding-structure/http-responses/
30+
- label: Components Section
31+
link: /understanding-structure/components/
32+
- type: category
33+
label: Defining Data Models
34+
items:
35+
- label: Schema and Data Types
36+
link: /data-models/schema-and-data-types/
37+
- label: JSON Schema in OpenAPI
38+
link: /data-models/json-schema/
39+
- label: Examples and Default Values
40+
link: /data-models/examples/
41+
- label: Schema Composition
42+
link: /data-models/schema-composition/
43+
- label: Representing XML
44+
link: /data-models/representing-xml/
45+
- type: category
46+
label: Advanced OpenAPI Specification
47+
items:
48+
- label: Splitting OpenAPI into Multiple Documents
49+
link: /advanced/splitting-documents-with-ref/
50+
- label: Multipart Form Data
51+
link: /advanced/multipart-form-data/
52+
- label: Pagination
53+
link: /advanced/pagination/
54+
- label: File Uploads
55+
link: /advanced/file-uploads/
56+
- label: Supporting Multiple Content Types
57+
link: /advanced/multiple-content-types/
58+
- label: Handling Error Formats
59+
link: /advanced/error-formats/
60+
- label: Security (Authentication and Authorization)
61+
link: /advanced/security/
62+
- label: Callbacks and Webhooks
63+
link: /advanced/callbacks-webhooks/
64+
- label: JSON Streaming
65+
link: /advanced/json-streaming/
66+
- type: category
67+
label: Documenting APIs
68+
items:
69+
- label: Adding Descriptions and Summaries
70+
link: /documentation/descriptions-and-summaries/
71+
- label: Grouping Operations with Tags
72+
link: /documentation/grouping-operations-with-tags/
73+
- label: Linking to External Documentation
74+
link: /documentation/external-documentation/
75+
- type: category
76+
label: Extending OpenAPI
77+
items:
78+
- label: Custom Extensions and Vendor Extensions
79+
link: /extending/extensions/
80+
- label: Enriching OpenAPI with Overlays
81+
link: /extending/overlays/
82+
- label: The Perfect Modern OpenAPI Workflow
83+
link: /the-perfect-modern-openapi-workflow/
84+
- label: The Cheat Sheet
85+
link: /cheatsheet/

src/_guides/openapi/specification/v3.1/data-models/schema-and-data-types.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,14 @@ Setting a `default` lets people and code know what to do when a value has not be
220220

221221
```
222222
type: string
223+
default: pending
223224
enum:
224225
- pending
225226
- fulfilled
226227
- archived
227228
```
228229
229-
230-
230+
This is useful for properties that have a common or expected value, allowing you to avoid having to specify it every time.
231231
232232
### minimum & maximum
233233

src/_guides/openapi/specification/v3.1/documentation/grouping-operations-with-tags.md

Lines changed: 72 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,26 @@ Typically, OpenAPI tags are used to group related endpoints in a meaningful way,
1515

1616
```yaml
1717
tags:
18-
- name: Stations
18+
- name: stations
19+
summary: Stations
1920
description: |
2021
Find and filter train stations across Europe, including their location
2122
and local timezone.
2223
externalDocs:
2324
description: Read more
2425
url: http://docs.example.com/guides/stations
25-
- name: Trips
26-
description: |
26+
- name: trips
27+
summary: Trips
28+
description: |
2729
Timetables and routes for train trips between stations, including pricing
2830
and availability.
29-
- name: Bookings
31+
- name: bookings
32+
summary: Bookings
3033
description: |
3134
Create and manage bookings for train trips, including passenger details
3235
and optional extras.
33-
- name: Payments
36+
- name: payments
37+
summary: Payments
3438
description: |
3539
Pay for bookings using a card or bank account, and view payment
3640
status and history.
@@ -40,20 +44,28 @@ tags:
4044
> before the expiry date
4145
```
4246
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+
4357
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:
4458

4559
```yaml
4660
paths:
4761
/stations:
4862
get:
4963
summary: Get a list of train stations
50-
tags:
51-
- Stations
64+
tags: [ stations ]
5265
/trips:
5366
get:
5467
summary: Get available train trips
55-
tags:
56-
- Trips
68+
tags: [ trips ]
5769
```
5870

5971
You can also apply multiple tags to an operation:
@@ -63,9 +75,7 @@ paths:
6375
/bookings/{bookingId}/payment:
6476
post:
6577
summary: Pay for a Booking
66-
tags:
67-
- Bookings
68-
- Payments
78+
tags: [ bookings, payments ]
6979
```
7080

7181
## Benefits of OpenAPI Tags
@@ -75,15 +85,17 @@ Tags are a powerful tool for improving the usability of your OpenAPI document. B
7585
### Tags Can Describe Endpoint Groups
7686

7787
When specifying your tags in the root level of your API contract, you can give context to the tag using the `description` property.
88+
7889
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):
7990

8091
```yaml
8192
tags:
82-
- name: Diffs
93+
- name: diff
94+
summary: Diffs
8395
description: Diff summary of changes in the API
8496
```
8597

86-
The documentation will show the `Diffs` property like this:
98+
The documentation will show the `diff` tag like this:
8799

88100
![Diff attribute in the generated API documentation](/images/guides/diff_attribute.png)
89101
[*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
98110

99111
```yaml
100112
tags:
101-
- name: Diffs
113+
- name: diff
102114
description: Diff summary of changes in the API
103115
externalDocs:
104116
description: More details about Diff
@@ -115,17 +127,23 @@ When specifying your OpenAPI or AsyncAPI tags in the root of your API contract,
115127

116128
```yaml
117129
tags:
118-
- name: Diffs
130+
- name: diff
131+
summary: Diffs
119132
description: Diff summary of changes in the API
120-
- name: Ping
133+
- name: ping
134+
summary: Ping
121135
description: Monitoring status endpoints
122-
- name: Previews
136+
- name: preview
137+
summary: Previews
123138
description: Preview for documentation file
124-
- name: Versions
139+
- name: version
140+
summary: Versions
125141
description: Deploy your API contracts
126-
- name: Validations
142+
- name: validation
143+
summary: Validations
127144
description: Check & validate your API contracts
128-
- name: Hubs
145+
- name: hub
146+
summary: Hubs
129147
description: Interact with your Hubs
130148
```
131149

@@ -143,18 +161,19 @@ Now that you understand what tags are and their benefits, you'll see some best p
143161
### Tag Everything
144162

145163
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:
147166

148167
```yaml
149168
paths:
150169
/diffs:
151170
post:
152-
tags: [ Diffs ]
171+
tags: [ diff ]
153172
summary: Create a diff
154173
[...]
155174
/diffs/{id}:
156175
get:
157-
tags: [ Diffs ]
176+
tags: [ diff ]
158177
summary: Fetch detailed information from an existing diff
159178
[...]
160179
```
@@ -171,22 +190,25 @@ To ensure your endpoints remain logically grouped and ordered, always tag every
171190

172191
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.
173192

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:
175194

176195
```yaml
177196
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.
190212
```
191213

192214
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
195217

196218
```yaml
197219
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.
208232
```
209233

210234
### Define All Your OpenAPI Tags in the Root Tag Object
211235

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.
213237

214238
As an example, consider the code snippet below where the `Previews` and the `Ping` tags has not been included in the root Tag Object:
215239

src/_guides/openapi/specification/v3.1/extending/overlays.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ actions:
103103
104104
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.
105105
106-
![Untitled](/images/guides/efficient-tech-writing-process/bump-tag-description.png)
106+
![A screenshot of Bump.sh generated API documentation on the Operations tag page, with the Markdown from the above example rendered as HTML including a link to the contact us page.](/images/guides/efficient-tech-writing-process/bump-tag-description.png)
107107
108108
Here’s the tag description rendered in Bump.sh.
109109

src/_guides/openapi/specification/v3.1/understanding-structure/basic-structure.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Only the following fields are **required**:
6363
- `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.
6464
- `version` - The version of your OpenAPI document, which does not have to related to the API version, or the OpenAPI Specification version.
6565

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.
6767

6868
These other fields are **optional**:
6969

@@ -351,7 +351,7 @@ The name is often displayed to users in human-readable documentation so its best
351351
Putting it all together, here is a simple example of an OpenAPI document:
352352

353353
```yaml
354-
openapi: 3.0.3
354+
openapi: 3.1.1
355355
info:
356356
title: Sample API
357357
description: A sample API to illustrate OpenAPI concepts.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sidebar_version: "v3.1"
2+
sidebar_name: openapi_v3-1

0 commit comments

Comments
 (0)