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
Copy file name to clipboardExpand all lines: openapi/content/jsonl.mdx
+31-2Lines changed: 31 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,8 @@ title: "Jsonl in OpenAPI best practices"
3
3
description: "Comprehensive guide to Jsonl in OpenAPI. Best practices for API design, documentation, and implementation."
4
4
---
5
5
6
+
import { Callout } from"@/mdx/components";
7
+
6
8
# JSONL responses in OpenAPI
7
9
8
10
JSON Lines (JSONL) is a convenient format for storing structured data that may be processed one record at a time. It's a simple format where each line is a valid JSON value, typically a JSON object or array. JSONL is particularly useful for handling large datasets, streaming data, or log files where each line represents a separate record.
@@ -28,8 +30,13 @@ JSONL offers several advantages over traditional JSON:
28
30
29
31
## Defining JSONL responses in OpenAPI documents
30
32
31
-
JSONL responses can be defined in OpenAPI by using the `application/jsonl` or `text/jsonl` MIME type. While JSONL isn't natively supported in the OpenAPI specification, you can use these content types to indicate that the response will be in JSONL format.
32
-
Here's an example of how to define a JSONL response in an OpenAPI document:
OpenAPI v3.2.0 recognizes `application/jsonl` as a sequential media type and introduces the `itemSchema` keyword for defining the structure of individual records in the stream.
35
+
</Callout>
36
+
37
+
JSONL responses can be defined in OpenAPI by using the `application/jsonl` or `text/jsonl` MIME type. In OpenAPI v3.0 and v3.1, JSONL isn't natively supported, but these content types indicate that the response will be in JSONL format. OpenAPI v3.2.0 adds native support through the `itemSchema` keyword, which defines the schema for each line in the JSONL stream.
38
+
39
+
The following example defines a JSONL response in an OpenAPI document:
33
40
34
41
```yaml filename="openapi.yaml"
35
42
paths:
@@ -79,6 +86,28 @@ components:
79
86
80
87
In this example, the `/users/export` endpoint returns user data in JSONL format. Each line of the response will be a valid JSON object representing a user, as defined by the `User` schema.
81
88
89
+
### Using itemSchema in OpenAPI 3.2
90
+
91
+
With OpenAPI v3.2.0, the `itemSchema` keyword explicitly defines the schema for each line in the JSONL stream:
92
+
93
+
```yaml filename="openapi.yaml"
94
+
paths:
95
+
/users/export:
96
+
get:
97
+
summary: Export user data in JSONL format
98
+
responses:
99
+
"200":
100
+
description: User data in JSONL format
101
+
content:
102
+
application/jsonl:
103
+
schema:
104
+
type: string
105
+
itemSchema:
106
+
$ref: "#/components/schemas/User"
107
+
```
108
+
109
+
The `schema` describes the overall stream, while `itemSchema` defines the structure of each individual JSON object per line. This allows tooling to generate typed deserialization for each record in the stream.
110
+
82
111
## Client-side handling of JSONL responses
83
112
84
113
When working with JSONL responses, clients need to process the data line by line. Here's an example of how to handle JSONL responses using a python SDK generated by Speakeasy:
Copy file name to clipboardExpand all lines: openapi/content/server-sent-events.mdx
+42-2Lines changed: 42 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: "Server Sent Events in OpenAPI best practices"
3
3
description: "Comprehensive guide to Server Sent Events in OpenAPI. Best practices for API design, documentation, and implementation."
4
4
---
5
5
6
-
import { Table } from"@/mdx/components";
6
+
import { Callout, Table } from"@/mdx/components";
7
7
8
8
# Server-sent events in OpenAPI
9
9
@@ -65,7 +65,11 @@ SSE is ideal for simple, efficient, one-way server-to-client communication scena
65
65
66
66
## Defining SSE in OpenAPI documents
67
67
68
-
Server-sent events (SSE) are not natively supported in OpenAPI but can be represented as an endpoint using the `text/event-stream` MIME type to indicate the data format.
OpenAPI v3.2.0 introduces the `itemSchema` keyword for `text/event-stream` media types, providing first-class support for defining the structure of individual streamed events. See the [itemSchema section](#defining-sse-with-itemschema-in-openapi-32) below.
70
+
</Callout>
71
+
72
+
In OpenAPI v3.0 and v3.1, server-sent events (SSE) are not natively supported but can be represented as an endpoint using the `text/event-stream` MIME type to indicate the data format. OpenAPI v3.2.0 adds first-class support for SSE with the `itemSchema` keyword.
69
73
70
74
The event stream format is a UTF-8-encoded text stream with messages separated by a newline (`\n`). Each message may include up to four fields:
71
75
@@ -147,6 +151,42 @@ eventSource.onerror = function (error) {
147
151
};
148
152
```
149
153
154
+
## Defining SSE with itemSchema in OpenAPI 3.2
155
+
156
+
OpenAPI v3.2.0 introduces the `itemSchema` keyword, which defines the schema for individual events within a `text/event-stream` response. Instead of describing the entire stream as one schema, `itemSchema` describes the structure of each event delivered over the stream.
157
+
158
+
```yaml filename="openapi.yaml"
159
+
paths:
160
+
/stock-updates:
161
+
get:
162
+
tags:
163
+
- ServerSentEvents
164
+
summary: Subscribe to real-time stock market updates
165
+
responses:
166
+
"200":
167
+
description: Stream of real-time stock updates
168
+
content:
169
+
text/event-stream:
170
+
schema:
171
+
type: string
172
+
itemSchema:
173
+
$ref: "#/components/schemas/StockUpdate"
174
+
components:
175
+
schemas:
176
+
StockUpdate:
177
+
type: object
178
+
properties:
179
+
symbol:
180
+
type: string
181
+
description: Stock ticker symbol
182
+
price:
183
+
type: string
184
+
description: Current stock price
185
+
example: "100.25"
186
+
```
187
+
188
+
In this example, the `schema` describes the overall stream as a string (the raw event stream), while `itemSchema` defines the structure of each individual event within the stream. This separation allows tooling to generate typed handlers for each event.
189
+
150
190
## Best practices for SSE design and OpenAPI integration
151
191
152
192
Here are some best practices for handling server-sent events and including them in an OpenAPI document.
Copy file name to clipboardExpand all lines: openapi/operations.mdx
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ import { Table } from "@/mdx/components";
8
8
9
9
An operation object describes a single API operation within a path, including all its possible inputs and outputs and the configuration required to make a successful request.
10
10
11
-
Each operation object corresponds to an HTTP verb, such as `get`, `post`, or `delete`.
11
+
Each operation object corresponds to an HTTP method, such as `get`, `post`, `delete`, or `query` (introduced in OpenAPI v3.2.0).
12
12
13
13
Example:
14
14
@@ -133,3 +133,5 @@ paths:
133
133
/>
134
134
135
135
The above order of fields is recommended for defining the fields in the document to help set the stage for the operation and provide a clear understanding of what it does.
136
+
137
+
OpenAPI v3.2.0 also introduces the [`query` method and `additionalOperations`](/openapi/paths#openapi-32-path-features) for defining the `QUERY` HTTP method and non-standard HTTP methods as Operation Objects.
Copy file name to clipboardExpand all lines: openapi/paths.mdx
+89Lines changed: 89 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -111,6 +111,8 @@ components:
111
111
{ field: "`head`", type: "[Operation Object](/openapi/paths/operations)", required: "", description: "An operation associated with the [`HEAD` HTTP method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD)." },
112
112
{ field: "`patch`", type: "[Operation Object](/openapi/paths/operations)", required: "", description: "An operation associated with the [`PATCH` HTTP method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH)." },
113
113
{ field: "`trace`", type: "[Operation Object](/openapi/paths/operations)", required: "", description: "An operation associated with the [`TRACE` HTTP method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/TRACE)." },
114
+
{ field: "`query`", type: "[Operation Object](/openapi/paths/operations)", required: "", description: "An operation associated with the `QUERY` HTTP method. Safe and idempotent, like `GET`, but allows a request body for complex queries. Available in OpenAPI v3.2.0+." },
115
+
{ field: "`additionalOperations`", type: "Map[String, [Operation Object](/openapi/paths/operations)]", required: "", description: "A map of non-standard HTTP methods to Operation Objects, enabling documentation of custom methods beyond those defined by the specification. Available in OpenAPI v3.2.0+." },
114
116
{ field: "`x-*`", type: "[Extensions](/openapi/extensions)", required: "", description: "Any number of extension fields can be added to the Path Item Object that can be used by tooling and vendors." }
115
117
]}
116
118
columns={[
@@ -122,3 +124,90 @@ components:
122
124
/>
123
125
124
126
The order of fields above is recommended but is not significant to the order in which the endpoints should be used.
127
+
128
+
## OpenAPI 3.2 path features
129
+
130
+
OpenAPI 3.2.0 introduces several new capabilities for path items.
131
+
132
+
### The QUERY HTTP method
133
+
134
+
The `QUERY` method is a safe, idempotent HTTP method that allows clients to send query criteria in the request body rather than encoding complex parameters in the URL. This is useful for operations that require structured or lengthy query parameters that exceed practical URL length limits.
135
+
136
+
```yaml
137
+
paths:
138
+
/drinks:
139
+
query:
140
+
operationId: searchDrinks
141
+
summary: Search for drinks with complex criteria
142
+
requestBody:
143
+
required: true
144
+
content:
145
+
application/json:
146
+
schema:
147
+
type: object
148
+
properties:
149
+
ingredients:
150
+
type: array
151
+
items:
152
+
type: string
153
+
minRating:
154
+
type: number
155
+
responses:
156
+
"200":
157
+
description: A list of matching drinks
158
+
content:
159
+
application/json:
160
+
schema:
161
+
type: array
162
+
items:
163
+
$ref: "#/components/schemas/Drink"
164
+
```
165
+
166
+
### Additional operations
167
+
168
+
The `additionalOperations` field allows defining non-standard HTTP methods as Operation Objects. This is useful for APIs that use custom HTTP methods beyond the standard set.
169
+
170
+
```yaml
171
+
paths:
172
+
/drinks/{drinkId}:
173
+
additionalOperations:
174
+
BREW:
175
+
operationId: brewDrink
176
+
summary: Brew a specific drink
177
+
parameters:
178
+
- name: drinkId
179
+
in: path
180
+
required: true
181
+
schema:
182
+
type: string
183
+
responses:
184
+
"200":
185
+
description: Drink brewed successfully
186
+
```
187
+
188
+
### The querystring field
189
+
190
+
OpenAPI 3.2.0 also introduces the `querystring` field on Operation Objects, which allows defining all query parameters as a single Schema Object instead of listing individual `parameters` with `in: query`. This simplifies the definition of operations with many query parameters or complex query structures.
{ field: "`description`", type: "String", required: "", description: "Human-readable information. This may contain [CommonMark syntax](https://spec.commonmark.org/) to provide a rich description." },
25
-
{ field: "`flows`", type: "Map[{key}, [OAuth Flow Object](#oauth-flow-object)]", required: "✅", description: "An object containing configuration for the available OAuth 2 flows. Valid keys are `implicit`, `password`, `clientCredentials`, and `authorizationCode`." },
25
+
{ field: "`flows`", type: "Map[{key}, [OAuth Flow Object](#oauth-flow-object)]", required: "✅", description: "An object containing configuration for the available OAuth 2 flows. Valid keys are `implicit`, `password`, `clientCredentials`, `authorizationCode`, and `deviceAuthorization` (OpenAPI v3.2.0+)." },
26
26
{ field: "`x-*`", type: "[Extensions](/openapi/extensions)", required: "", description: "Any number of extension fields can be added to the Security Scheme Object to be used by tooling and vendors." }
27
27
]}
28
28
columns={[
@@ -52,12 +52,13 @@ security:
52
52
53
53
The value of the [OAuth Flows Object](https://spec.openapis.org/oas/v3.1.0#oauth-flows-object) is a map of [OAuth Flow Objects](https://spec.openapis.org/oas/v3.1.0#oauth-flow-object).
54
54
55
-
The OpenAPI Specification 3.1 supports the following four OAuth Flow Objects:
55
+
The OpenAPI Specification supports the following OAuth Flow Objects:
56
56
57
57
- The [Client Credentials](#the-client-credentials-flow) flow (using `clientCredentials`, previously `application` in OpenAPI 2.0)
58
58
- The [Authorization Code](#the-authorization-code-flow) flow (using `authorizationCode`, previously `accessCode` in OpenAPI 2.0)
59
59
- The [Password](#the-password-flow) flow (using `password`)
60
60
- The [Implicit](#the-implicit-flow) flow (using `implicit`)
61
+
- The [Device Authorization](#the-device-authorization-flow) flow (using `deviceAuthorization`, available in OpenAPI v3.2.0+)
61
62
62
63
Each OAuth Flow Object has its own configuration parameters, so let's look at them individually.
63
64
@@ -346,6 +347,62 @@ OAuth 2.1 is a simplified version of OAuth 2 that combines its best practices an
346
347
347
348
For more information on the changes and improvements made in OAuth 2.1, refer to [the OAuth 2.1 specification](https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-13).
348
349
349
-
**Device Authorization** is a new OAuth flow (also called a grant) that is not yet supported in the OpenAPI Specification 3.1. It will be added in the OpenAPI Specification 3.2, which is currently in development.
350
+
### The Device Authorizationflow
350
351
351
-
For more information on the Device Authorization grant, take a look at the specification for the [OAuth 2.0 Device Authorization grant](https://datatracker.ietf.org/doc/html/rfc8628).
352
+
The Device Authorization flow (also called the Device Authorization grant) is designed for devices with limited input capabilities, such as smart TVs, kiosks, and IoT devices. Instead of entering credentials directly, the device displays a code that the user enters on a separate device with a full browser. OpenAPI v3.2.0 adds support for this flow using the `deviceAuthorization` key.
353
+
354
+
For more information on the Device Authorization grant, refer to the specification for the [OAuth 2.0 Device Authorization grant](https://datatracker.ietf.org/doc/html/rfc8628).
355
+
356
+
<Table
357
+
data={[
358
+
{ field: "`deviceAuthorizationUrl`", type: "String", required: "✅", description: "The device authorization URL to be used for this flow." },
359
+
{ field: "`tokenUrl`", type: "String", required: "✅", description: "The token URL to be used for this flow." },
360
+
{ field: "`refreshUrl`", type: "String", required: "", description: "The URL to be used for refreshing the token. No refresh URL means the token is not refreshable." },
361
+
{ field: "`scopes`", type: "Map[String, String]", required: "✅", description: "The available scopes for the OAuth 2 flow, with a description for each scope. Although the specification requires this field, it can be an empty object." },
362
+
{ field: "`x-*`", type: "[Extensions](/openapi/extensions)", required: "", description: "Any number of extension fields can be added to an OAuth Flow Object to be used by tooling and vendors to add additional metadata and functionality to the OpenAPI Specification." }
363
+
]}
364
+
columns={[
365
+
{ key: "field", header: "Field" },
366
+
{ key: "type", header: "Type" },
367
+
{ key: "required", header: "Required" },
368
+
{ key: "description", header: "Description" }
369
+
]}
370
+
/>
371
+
372
+
The following example shows an OAuth 2 security scheme using the `deviceAuthorization` flow:
OpenAPI v3.2.0 adds the `oauth2MetadataUrl` field to the OAuth Flow Object. This field provides a URL pointing to the OAuth 2.0 Authorization Server Metadata document ([RFC 8414](https://datatracker.ietf.org/doc/html/rfc8414)), enabling clients to automatically discover OAuth 2.0 endpoint configuration.
0 commit comments