Skip to content

Commit 9c68897

Browse files
authored
Merge pull request moby#51668 from ndeloof/jsonl
use mime-type application/jsonl to align with openapi 3.2
2 parents b8093b7 + aef5d99 commit 9c68897

File tree

10 files changed

+17
-5
lines changed

10 files changed

+17
-5
lines changed

api/docs/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ keywords: "API, Docker, rcli, REST, documentation"
1717

1818
* `GET /info` now includes an `NRI` field. If the Node Resource Interface (NRI)
1919
is enabled, this field contains information describing it.
20+
* `GET /events` now also supports [`application/jsonl`](https://jsonlines.org/)
21+
when negotiating content-type.
2022
* Deprecated: The `POST /grpc` and `POST /session` endpoints are deprecated and
2123
will be removed in a future version.
2224

api/swagger.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10463,6 +10463,7 @@ paths:
1046310463
1046410464
operationId: "SystemEvents"
1046510465
produces:
10466+
- "application/jsonl"
1046610467
- "application/x-ndjson"
1046710468
- "application/json-seq"
1046810469
responses:

api/types/types.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ const (
1010
// MediaTypeJSON is the MIME-Type for JSON objects.
1111
MediaTypeJSON = "application/json"
1212

13-
// MediaTypeNDJSON is the MIME-Type for Newline Delimited JSON objects streams.
13+
// MediaTypeNDJSON is the MIME-Type for Newline Delimited JSON objects streams (https://github.com/ndjson/ndjson-spec).
1414
MediaTypeNDJSON = "application/x-ndjson"
1515

16+
// MediaTypeJSONLines is the MIME-Type for JSONLines objects streams (https://jsonlines.org/).
17+
MediaTypeJSONLines = "application/jsonl"
18+
1619
// MediaTypeJSONSequence is the MIME-Type for JSON Text Sequences (RFC7464).
1720
MediaTypeJSONSequence = "application/json-seq"
1821
)

client/internal/json-stream.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func NewJSONStreamDecoder(r io.Reader, contentType string) DecoderFn {
1717
switch contentType {
1818
case types.MediaTypeJSONSequence:
1919
return json.NewDecoder(NewRSFilterReader(r)).Decode
20-
case types.MediaTypeJSON, types.MediaTypeNDJSON:
20+
case types.MediaTypeJSON, types.MediaTypeNDJSON, types.MediaTypeJSONLines:
2121
fallthrough
2222
default:
2323
return json.NewDecoder(r).Decode

client/system_events.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func (cli *Client) Events(ctx context.Context, options EventsListOptions) Events
4646

4747
headers := http.Header{}
4848
headers.Add("Accept", types.MediaTypeJSONSequence)
49+
headers.Add("Accept", types.MediaTypeJSONLines)
4950
headers.Add("Accept", types.MediaTypeNDJSON)
5051
resp, err := cli.get(ctx, "/events", query, headers)
5152
if err != nil {

daemon/server/httputils/json-seq.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func NewJSONStreamEncoder(w io.Writer, contentType string) EncoderFn {
2121
json: jsonEncoder,
2222
}
2323
return jseq.Encode
24-
case types.MediaTypeNDJSON, types.MediaTypeJSON:
24+
case types.MediaTypeNDJSON, types.MediaTypeJSON, types.MediaTypeJSONLines:
2525
fallthrough
2626
default:
2727
return jsonEncoder.Encode

daemon/server/router/system/system_routes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ func (s *systemRouter) getEvents(ctx context.Context, w http.ResponseWriter, r *
311311
}
312312

313313
contentType := httputil.NegotiateContentType(r, []string{
314+
types.MediaTypeJSONLines,
314315
types.MediaTypeNDJSON,
315316
types.MediaTypeJSONSequence,
316317
}, types.MediaTypeJSON) // output isn't actually JSON but API used to this content-type

vendor/github.com/moby/moby/api/types/types.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/moby/moby/client/internal/json-stream.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/moby/moby/client/system_events.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)