@@ -4,6 +4,10 @@ import { registerSchema } from "@hyperjump/json-schema/draft-2020-12";
44import { unregisterSchema } from "@hyperjump/json-schema" ;
55import { getSchemaDescription } from "./schema-descriptions.js" ;
66import { Localization } from "./localization.js" ;
7+ import "@hyperjump/json-schema/draft-04" ;
8+ import "@hyperjump/json-schema/draft-06" ;
9+ import "@hyperjump/json-schema/draft-2019-09" ;
10+ import "@hyperjump/json-schema/draft-07" ;
711
812/**
913 * @import { OutputFormat} from "./index.d.ts"
@@ -639,7 +643,7 @@ describe("Error messages", async () => {
639643 } ] ) ;
640644 } ) ;
641645
642- test ( "format: email" , async ( ) => {
646+ test ( "format: email (draft-2020-12) " , async ( ) => {
643647 registerSchema ( {
644648 $schema : "https://json-schema.org/draft/2020-12/schema" ,
645649 format : "email"
@@ -666,6 +670,117 @@ describe("Error messages", async () => {
666670 ] ) ;
667671 } ) ;
668672
673+ test ( "format: email (draft-2019-09)" , async ( ) => {
674+ registerSchema ( {
675+ $schema : "https://json-schema.org/draft/2019-09/schema" ,
676+ format : "email"
677+ } , schemaUri ) ;
678+
679+ const instance = "not-an-email" ;
680+ const output = {
681+ valid : false ,
682+ errors : [
683+ {
684+ absoluteKeywordLocation : "https://example.com/main#/format" ,
685+ instanceLocation : "#"
686+ }
687+ ]
688+ } ;
689+
690+ const result = await betterJsonSchemaErrors ( output , schemaUri , instance ) ;
691+ expect ( result . errors ) . to . eql ( [
692+ {
693+ schemaLocation : "https://example.com/main#/format" ,
694+ instanceLocation : "#" ,
695+ message : localization . getFormatErrorMessage ( "email" )
696+ }
697+ ] ) ;
698+ } ) ;
699+
700+ test ( "format: email (draft-07)" , async ( ) => {
701+ registerSchema ( {
702+ $schema : "http://json-schema.org/draft-07/schema" ,
703+ format : "email"
704+ } , schemaUri ) ;
705+
706+ const instance = "not-an-email" ;
707+ const output = {
708+ valid : false ,
709+ errors : [
710+ {
711+ absoluteKeywordLocation : "https://example.com/main#/format" ,
712+ instanceLocation : "#"
713+ }
714+ ]
715+ } ;
716+
717+ const result = await betterJsonSchemaErrors ( output , schemaUri , instance ) ;
718+ expect ( result . errors ) . to . eql ( [
719+ {
720+ schemaLocation : "https://example.com/main#/format" ,
721+ instanceLocation : "#" ,
722+ message : localization . getFormatErrorMessage ( "email" )
723+ }
724+ ] ) ;
725+ } ) ;
726+
727+ test ( "format: email (draft-06)" , async ( ) => {
728+ registerSchema ( {
729+ $schema : "http://json-schema.org/draft-06/schema" ,
730+ format : "email"
731+ } , schemaUri ) ;
732+
733+ const instance = "not-an-email" ;
734+ const output = {
735+ valid : false ,
736+ errors : [
737+ {
738+ absoluteKeywordLocation : "https://example.com/main#/format" ,
739+ instanceLocation : "#"
740+ }
741+ ]
742+ } ;
743+
744+ const result = await betterJsonSchemaErrors ( output , schemaUri , instance ) ;
745+
746+ expect ( result . errors ) . to . eql ( [
747+ {
748+ schemaLocation : "https://example.com/main#/format" ,
749+ instanceLocation : "#" ,
750+ message : localization . getFormatErrorMessage ( "email" )
751+ }
752+ ] ) ;
753+ } ) ;
754+
755+ test ( "format: email (draft-04)" , async ( ) => {
756+
757+ registerSchema ( {
758+ $schema : "http://json-schema.org/draft-04/schema" ,
759+ format : "email"
760+ } , schemaUri ) ;
761+
762+ const instance = "not-an-email" ;
763+ const output = {
764+ valid : false ,
765+ errors : [
766+ {
767+ absoluteKeywordLocation : "https://example.com/main#/format" ,
768+ instanceLocation : "#"
769+ }
770+ ]
771+ } ;
772+
773+ const result = await betterJsonSchemaErrors ( output , schemaUri , instance ) ;
774+
775+ expect ( result . errors ) . to . eql ( [
776+ {
777+ schemaLocation : "https://example.com/main#/format" ,
778+ instanceLocation : "#" ,
779+ message : localization . getFormatErrorMessage ( "email" )
780+ }
781+ ] ) ;
782+ } ) ;
783+
669784 test ( "pattern" , async ( ) => {
670785 registerSchema ( {
671786 $schema : "https://json-schema.org/draft/2020-12/schema" ,
0 commit comments