OCaml library for JSONfeed parsing and creation

fmt

+2 -2
lib/attachment.mli
···
module Unknown : sig
type t = Jsont.json
-
(** Unknown/unrecognized JSON object members as a generic JSON object.
-
Useful for preserving fields from custom extensions or future spec versions. *)
+
(** Unknown/unrecognized JSON object members as a generic JSON object. Useful
+
for preserving fields from custom extensions or future spec versions. *)
val empty : t
(** [empty] is the empty list of unknown fields. *)
+2 -2
lib/author.mli
···
module Unknown : sig
type t = Jsont.json
-
(** Unknown/unrecognized JSON object members as a generic JSON object.
-
Useful for preserving fields from custom extensions or future spec versions. *)
+
(** Unknown/unrecognized JSON object members as a generic JSON object. Useful
+
for preserving fields from custom extensions or future spec versions. *)
val empty : t
(** [empty] is the empty list of unknown fields. *)
+2 -2
lib/hub.mli
···
module Unknown : sig
type t = Jsont.json
-
(** Unknown/unrecognized JSON object members as a generic JSON object.
-
Useful for preserving fields from custom extensions or future spec versions. *)
+
(** Unknown/unrecognized JSON object members as a generic JSON object. Useful
+
for preserving fields from custom extensions or future spec versions. *)
val empty : t
(** [empty] is the empty list of unknown fields. *)
+1 -3
lib/item.ml
···
| `Both (_, text) -> Some text
let equal a b = a.id = b.id
-
-
let compare a b =
-
Option.compare Ptime.compare a.date_published b.date_published
+
let compare a b = Option.compare Ptime.compare a.date_published b.date_published
let pp ppf t =
match (t.date_published, t.title) with
+2 -2
lib/item.mli
···
module Unknown : sig
type t = Jsont.json
-
(** Unknown/unrecognized JSON object members as a generic JSON object.
-
Useful for preserving fields from custom extensions or future spec versions. *)
+
(** Unknown/unrecognized JSON object members as a generic JSON object. Useful
+
for preserving fields from custom extensions or future spec versions. *)
val empty : t
(** [empty] is the empty list of unknown fields. *)
+2 -2
lib/jsonfeed.ml
···
(List.iteri (fun i author ->
if not (Author.is_valid author) then
add_error
-
(Printf.sprintf "feed author %d is invalid (needs at least one field)"
-
i)))
+
(Printf.sprintf
+
"feed author %d is invalid (needs at least one field)" i)))
feed.authors;
(* Validate items *)
+2 -1
lib/jsonfeed.mli
···
module Unknown : sig
type t = Jsont.json
(** Unknown or unrecognized JSON object members as a generic JSON object.
-
Useful for preserving fields from custom extensions or future spec versions. *)
+
Useful for preserving fields from custom extensions or future spec
+
versions. *)
val empty : t
(** [empty] is the empty list of unknown fields. *)
+2 -2
lib/reference.mli
···
module Unknown : sig
type t = Jsont.json
-
(** Unknown/unrecognized JSON object members as a generic JSON object.
-
Useful for preserving fields from custom extensions or future spec versions. *)
+
(** Unknown/unrecognized JSON object members as a generic JSON object. Useful
+
for preserving fields from custom extensions or future spec versions. *)
val empty : t
(** [empty] is the empty list of unknown fields. *)
+14 -12
test/test_jsonfeed.ml
···
| Error e ->
Alcotest.fail
(Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e))
-
| Ok author ->
+
| Ok author -> (
(* Check that unknown fields are preserved *)
let unknown = Author.unknown author in
Alcotest.(check bool)
"has unknown fields" false
(Jsonfeed.Unknown.is_empty unknown);
(* Encode and decode again *)
-
(match Jsont_bytesrw.encode_string' Author.jsont author with
+
match Jsont_bytesrw.encode_string' Author.jsont author with
| Error e ->
Alcotest.fail
(Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e))
···
| Error e ->
Alcotest.fail
(Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e))
-
| Ok item ->
+
| Ok item -> (
(* Check that unknown fields are preserved *)
let unknown = Item.unknown item in
Alcotest.(check bool)
"has unknown fields" false
(Jsonfeed.Unknown.is_empty unknown);
(* Encode and decode again *)
-
(match Jsont_bytesrw.encode_string' Item.jsont item with
+
match Jsont_bytesrw.encode_string' Item.jsont item with
| Error e ->
Alcotest.fail
(Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e))
···
| Error e ->
Alcotest.fail
(Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e))
-
| Ok feed ->
+
| Ok feed -> (
(* Check that unknown fields are preserved *)
let unknown = Jsonfeed.unknown feed in
Alcotest.(check bool)
"has unknown fields" false
(Jsonfeed.Unknown.is_empty unknown);
(* Encode and decode again *)
-
(match Jsonfeed.to_string feed with
+
match Jsonfeed.to_string feed with
| Error e ->
Alcotest.fail
(Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e))
···
(Jsonfeed.Unknown.is_empty unknown2)))
let test_hub_unknown_roundtrip () =
-
let json = {|{
+
let json =
+
{|{
"type": "WebSub",
"url": "https://example.com/hub",
"custom_field": "test"
-
}|} in
+
}|}
+
in
match Jsont_bytesrw.decode_string' Hub.jsont json with
| Error e ->
Alcotest.fail
(Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e))
-
| Ok hub ->
+
| Ok hub -> (
let unknown = Hub.unknown hub in
Alcotest.(check bool)
"has unknown fields" false
(Jsonfeed.Unknown.is_empty unknown);
-
(match Jsont_bytesrw.encode_string' Hub.jsont hub with
+
match Jsont_bytesrw.encode_string' Hub.jsont hub with
| Error e ->
Alcotest.fail
(Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e))
···
| Error e ->
Alcotest.fail
(Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e))
-
| Ok att ->
+
| Ok att -> (
let unknown = Attachment.unknown att in
Alcotest.(check bool)
"has unknown fields" false
(Jsonfeed.Unknown.is_empty unknown);
-
(match Jsont_bytesrw.encode_string' Attachment.jsont att with
+
match Jsont_bytesrw.encode_string' Attachment.jsont att with
| Error e ->
Alcotest.fail
(Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e))