use mime-type application/jsonl to align with openapi 3.2

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Nicolas De Loof
2025-12-05 09:48:43 +01:00
committed by Sebastiaan van Stijn
parent b8093b76fb
commit aef5d996ce
10 changed files with 17 additions and 5 deletions

View File

@@ -17,6 +17,8 @@ keywords: "API, Docker, rcli, REST, documentation"
* `GET /info` now includes an `NRI` field. If the Node Resource Interface (NRI) * `GET /info` now includes an `NRI` field. If the Node Resource Interface (NRI)
is enabled, this field contains information describing it. is enabled, this field contains information describing it.
* `GET /events` now also supports [`application/jsonl`](https://jsonlines.org/)
when negotiating content-type.
* Deprecated: The `POST /grpc` and `POST /session` endpoints are deprecated and * Deprecated: The `POST /grpc` and `POST /session` endpoints are deprecated and
will be removed in a future version. will be removed in a future version.

View File

@@ -10463,6 +10463,7 @@ paths:
operationId: "SystemEvents" operationId: "SystemEvents"
produces: produces:
- "application/jsonl"
- "application/x-ndjson" - "application/x-ndjson"
- "application/json-seq" - "application/json-seq"
responses: responses:

View File

@@ -10,9 +10,12 @@ const (
// MediaTypeJSON is the MIME-Type for JSON objects. // MediaTypeJSON is the MIME-Type for JSON objects.
MediaTypeJSON = "application/json" MediaTypeJSON = "application/json"
// MediaTypeNDJSON is the MIME-Type for Newline Delimited JSON objects streams. // MediaTypeNDJSON is the MIME-Type for Newline Delimited JSON objects streams (https://github.com/ndjson/ndjson-spec).
MediaTypeNDJSON = "application/x-ndjson" MediaTypeNDJSON = "application/x-ndjson"
// MediaTypeJSONLines is the MIME-Type for JSONLines objects streams (https://jsonlines.org/).
MediaTypeJSONLines = "application/jsonl"
// MediaTypeJSONSequence is the MIME-Type for JSON Text Sequences (RFC7464). // MediaTypeJSONSequence is the MIME-Type for JSON Text Sequences (RFC7464).
MediaTypeJSONSequence = "application/json-seq" MediaTypeJSONSequence = "application/json-seq"
) )

View File

@@ -17,7 +17,7 @@ func NewJSONStreamDecoder(r io.Reader, contentType string) DecoderFn {
switch contentType { switch contentType {
case types.MediaTypeJSONSequence: case types.MediaTypeJSONSequence:
return json.NewDecoder(NewRSFilterReader(r)).Decode return json.NewDecoder(NewRSFilterReader(r)).Decode
case types.MediaTypeJSON, types.MediaTypeNDJSON: case types.MediaTypeJSON, types.MediaTypeNDJSON, types.MediaTypeJSONLines:
fallthrough fallthrough
default: default:
return json.NewDecoder(r).Decode return json.NewDecoder(r).Decode

View File

@@ -46,6 +46,7 @@ func (cli *Client) Events(ctx context.Context, options EventsListOptions) Events
headers := http.Header{} headers := http.Header{}
headers.Add("Accept", types.MediaTypeJSONSequence) headers.Add("Accept", types.MediaTypeJSONSequence)
headers.Add("Accept", types.MediaTypeJSONLines)
headers.Add("Accept", types.MediaTypeNDJSON) headers.Add("Accept", types.MediaTypeNDJSON)
resp, err := cli.get(ctx, "/events", query, headers) resp, err := cli.get(ctx, "/events", query, headers)
if err != nil { if err != nil {

View File

@@ -21,7 +21,7 @@ func NewJSONStreamEncoder(w io.Writer, contentType string) EncoderFn {
json: jsonEncoder, json: jsonEncoder,
} }
return jseq.Encode return jseq.Encode
case types.MediaTypeNDJSON, types.MediaTypeJSON: case types.MediaTypeNDJSON, types.MediaTypeJSON, types.MediaTypeJSONLines:
fallthrough fallthrough
default: default:
return jsonEncoder.Encode return jsonEncoder.Encode

View File

@@ -311,6 +311,7 @@ func (s *systemRouter) getEvents(ctx context.Context, w http.ResponseWriter, r *
} }
contentType := httputil.NegotiateContentType(r, []string{ contentType := httputil.NegotiateContentType(r, []string{
types.MediaTypeJSONLines,
types.MediaTypeNDJSON, types.MediaTypeNDJSON,
types.MediaTypeJSONSequence, types.MediaTypeJSONSequence,
}, types.MediaTypeJSON) // output isn't actually JSON but API used to this content-type }, types.MediaTypeJSON) // output isn't actually JSON but API used to this content-type

View File

@@ -10,9 +10,12 @@ const (
// MediaTypeJSON is the MIME-Type for JSON objects. // MediaTypeJSON is the MIME-Type for JSON objects.
MediaTypeJSON = "application/json" MediaTypeJSON = "application/json"
// MediaTypeNDJSON is the MIME-Type for Newline Delimited JSON objects streams. // MediaTypeNDJSON is the MIME-Type for Newline Delimited JSON objects streams (https://github.com/ndjson/ndjson-spec).
MediaTypeNDJSON = "application/x-ndjson" MediaTypeNDJSON = "application/x-ndjson"
// MediaTypeJSONLines is the MIME-Type for JSONLines objects streams (https://jsonlines.org/).
MediaTypeJSONLines = "application/jsonl"
// MediaTypeJSONSequence is the MIME-Type for JSON Text Sequences (RFC7464). // MediaTypeJSONSequence is the MIME-Type for JSON Text Sequences (RFC7464).
MediaTypeJSONSequence = "application/json-seq" MediaTypeJSONSequence = "application/json-seq"
) )

View File

@@ -17,7 +17,7 @@ func NewJSONStreamDecoder(r io.Reader, contentType string) DecoderFn {
switch contentType { switch contentType {
case types.MediaTypeJSONSequence: case types.MediaTypeJSONSequence:
return json.NewDecoder(NewRSFilterReader(r)).Decode return json.NewDecoder(NewRSFilterReader(r)).Decode
case types.MediaTypeJSON, types.MediaTypeNDJSON: case types.MediaTypeJSON, types.MediaTypeNDJSON, types.MediaTypeJSONLines:
fallthrough fallthrough
default: default:
return json.NewDecoder(r).Decode return json.NewDecoder(r).Decode

View File

@@ -46,6 +46,7 @@ func (cli *Client) Events(ctx context.Context, options EventsListOptions) Events
headers := http.Header{} headers := http.Header{}
headers.Add("Accept", types.MediaTypeJSONSequence) headers.Add("Accept", types.MediaTypeJSONSequence)
headers.Add("Accept", types.MediaTypeJSONLines)
headers.Add("Accept", types.MediaTypeNDJSON) headers.Add("Accept", types.MediaTypeNDJSON)
resp, err := cli.get(ctx, "/events", query, headers) resp, err := cli.get(ctx, "/events", query, headers)
if err != nil { if err != nil {