OCaml library for JSONfeed parsing and creation

fmt

+29 -28
+2 -2
lib/attachment.mli
··· 19 19 20 20 module Unknown : sig 21 21 type t = Jsont.json 22 - (** Unknown/unrecognized JSON object members as a generic JSON object. 23 - Useful for preserving fields from custom extensions or future spec versions. *) 22 + (** Unknown/unrecognized JSON object members as a generic JSON object. Useful 23 + for preserving fields from custom extensions or future spec versions. *) 24 24 25 25 val empty : t 26 26 (** [empty] is the empty list of unknown fields. *)
+2 -2
lib/author.mli
··· 18 18 19 19 module Unknown : sig 20 20 type t = Jsont.json 21 - (** Unknown/unrecognized JSON object members as a generic JSON object. 22 - Useful for preserving fields from custom extensions or future spec versions. *) 21 + (** Unknown/unrecognized JSON object members as a generic JSON object. Useful 22 + for preserving fields from custom extensions or future spec versions. *) 23 23 24 24 val empty : t 25 25 (** [empty] is the empty list of unknown fields. *)
+2 -2
lib/hub.mli
··· 18 18 19 19 module Unknown : sig 20 20 type t = Jsont.json 21 - (** Unknown/unrecognized JSON object members as a generic JSON object. 22 - Useful for preserving fields from custom extensions or future spec versions. *) 21 + (** Unknown/unrecognized JSON object members as a generic JSON object. Useful 22 + for preserving fields from custom extensions or future spec versions. *) 23 23 24 24 val empty : t 25 25 (** [empty] is the empty list of unknown fields. *)
+1 -3
lib/item.ml
··· 83 83 | `Both (_, text) -> Some text 84 84 85 85 let equal a b = a.id = b.id 86 - 87 - let compare a b = 88 - Option.compare Ptime.compare a.date_published b.date_published 86 + let compare a b = Option.compare Ptime.compare a.date_published b.date_published 89 87 90 88 let pp ppf t = 91 89 match (t.date_published, t.title) with
+2 -2
lib/item.mli
··· 28 28 29 29 module Unknown : sig 30 30 type t = Jsont.json 31 - (** Unknown/unrecognized JSON object members as a generic JSON object. 32 - Useful for preserving fields from custom extensions or future spec versions. *) 31 + (** Unknown/unrecognized JSON object members as a generic JSON object. Useful 32 + for preserving fields from custom extensions or future spec versions. *) 33 33 34 34 val empty : t 35 35 (** [empty] is the empty list of unknown fields. *)
+2 -2
lib/jsonfeed.ml
··· 167 167 (List.iteri (fun i author -> 168 168 if not (Author.is_valid author) then 169 169 add_error 170 - (Printf.sprintf "feed author %d is invalid (needs at least one field)" 171 - i))) 170 + (Printf.sprintf 171 + "feed author %d is invalid (needs at least one field)" i))) 172 172 feed.authors; 173 173 174 174 (* Validate items *)
+2 -1
lib/jsonfeed.mli
··· 19 19 module Unknown : sig 20 20 type t = Jsont.json 21 21 (** Unknown or unrecognized JSON object members as a generic JSON object. 22 - Useful for preserving fields from custom extensions or future spec versions. *) 22 + Useful for preserving fields from custom extensions or future spec 23 + versions. *) 23 24 24 25 val empty : t 25 26 (** [empty] is the empty list of unknown fields. *)
+2 -2
lib/reference.mli
··· 20 20 21 21 module Unknown : sig 22 22 type t = Jsont.json 23 - (** Unknown/unrecognized JSON object members as a generic JSON object. 24 - Useful for preserving fields from custom extensions or future spec versions. *) 23 + (** Unknown/unrecognized JSON object members as a generic JSON object. Useful 24 + for preserving fields from custom extensions or future spec versions. *) 25 25 26 26 val empty : t 27 27 (** [empty] is the empty list of unknown fields. *)
+14 -12
test/test_jsonfeed.ml
··· 384 384 | Error e -> 385 385 Alcotest.fail 386 386 (Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e)) 387 - | Ok author -> 387 + | Ok author -> ( 388 388 (* Check that unknown fields are preserved *) 389 389 let unknown = Author.unknown author in 390 390 Alcotest.(check bool) 391 391 "has unknown fields" false 392 392 (Jsonfeed.Unknown.is_empty unknown); 393 393 (* Encode and decode again *) 394 - (match Jsont_bytesrw.encode_string' Author.jsont author with 394 + match Jsont_bytesrw.encode_string' Author.jsont author with 395 395 | Error e -> 396 396 Alcotest.fail 397 397 (Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e)) ··· 420 420 | Error e -> 421 421 Alcotest.fail 422 422 (Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e)) 423 - | Ok item -> 423 + | Ok item -> ( 424 424 (* Check that unknown fields are preserved *) 425 425 let unknown = Item.unknown item in 426 426 Alcotest.(check bool) 427 427 "has unknown fields" false 428 428 (Jsonfeed.Unknown.is_empty unknown); 429 429 (* Encode and decode again *) 430 - (match Jsont_bytesrw.encode_string' Item.jsont item with 430 + match Jsont_bytesrw.encode_string' Item.jsont item with 431 431 | Error e -> 432 432 Alcotest.fail 433 433 (Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e)) ··· 456 456 | Error e -> 457 457 Alcotest.fail 458 458 (Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e)) 459 - | Ok feed -> 459 + | Ok feed -> ( 460 460 (* Check that unknown fields are preserved *) 461 461 let unknown = Jsonfeed.unknown feed in 462 462 Alcotest.(check bool) 463 463 "has unknown fields" false 464 464 (Jsonfeed.Unknown.is_empty unknown); 465 465 (* Encode and decode again *) 466 - (match Jsonfeed.to_string feed with 466 + match Jsonfeed.to_string feed with 467 467 | Error e -> 468 468 Alcotest.fail 469 469 (Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e)) ··· 479 479 (Jsonfeed.Unknown.is_empty unknown2))) 480 480 481 481 let test_hub_unknown_roundtrip () = 482 - let json = {|{ 482 + let json = 483 + {|{ 483 484 "type": "WebSub", 484 485 "url": "https://example.com/hub", 485 486 "custom_field": "test" 486 - }|} in 487 + }|} 488 + in 487 489 match Jsont_bytesrw.decode_string' Hub.jsont json with 488 490 | Error e -> 489 491 Alcotest.fail 490 492 (Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e)) 491 - | Ok hub -> 493 + | Ok hub -> ( 492 494 let unknown = Hub.unknown hub in 493 495 Alcotest.(check bool) 494 496 "has unknown fields" false 495 497 (Jsonfeed.Unknown.is_empty unknown); 496 - (match Jsont_bytesrw.encode_string' Hub.jsont hub with 498 + match Jsont_bytesrw.encode_string' Hub.jsont hub with 497 499 | Error e -> 498 500 Alcotest.fail 499 501 (Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e)) ··· 520 522 | Error e -> 521 523 Alcotest.fail 522 524 (Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e)) 523 - | Ok att -> 525 + | Ok att -> ( 524 526 let unknown = Attachment.unknown att in 525 527 Alcotest.(check bool) 526 528 "has unknown fields" false 527 529 (Jsonfeed.Unknown.is_empty unknown); 528 - (match Jsont_bytesrw.encode_string' Attachment.jsont att with 530 + match Jsont_bytesrw.encode_string' Attachment.jsont att with 529 531 | Error e -> 530 532 Alcotest.fail 531 533 (Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e))