@@ -1756,6 +1756,120 @@ describe("Error messages", async () => {
17561756 ] ) ;
17571757 } ) ;
17581758
1759+ test ( "can be a number and integer at the same time" , async ( ) => {
1760+ registerSchema ( {
1761+ $schema : "https://json-schema.org/draft/2020-12/schema" ,
1762+ allOf : [
1763+ { type : "number" } ,
1764+ { type : "integer" }
1765+ ]
1766+ } , schemaUri ) ;
1767+
1768+ const instance = "foo" ;
1769+
1770+ /** @type OutputFormat */
1771+ const output = {
1772+ valid : false ,
1773+ errors : [
1774+ {
1775+ absoluteKeywordLocation : "https://example.com/main#/allOf/0/type" ,
1776+ instanceLocation : "#"
1777+ } ,
1778+ {
1779+ absoluteKeywordLocation : "https://example.com/main#/allOf/1/type" ,
1780+ instanceLocation : "#"
1781+ }
1782+ ]
1783+ } ;
1784+
1785+ const result = await betterJsonSchemaErrors ( output , schemaUri , instance ) ;
1786+
1787+ expect ( result . errors ) . to . eql ( [
1788+ {
1789+ message : localization . getTypeErrorMessage ( "integer" , "string" ) ,
1790+ instanceLocation : "#" ,
1791+ schemaLocation : [
1792+ "https://example.com/main#/allOf/0/type" ,
1793+ "https://example.com/main#/allOf/1/type"
1794+ ]
1795+ }
1796+ ] ) ;
1797+ } ) ;
1798+
1799+ test ( "can be a number and integer at the same time - pass" , async ( ) => {
1800+ registerSchema ( {
1801+ $schema : "https://json-schema.org/draft/2020-12/schema" ,
1802+ allOf : [
1803+ { type : "number" } ,
1804+ { type : "integer" }
1805+ ] ,
1806+ maximum : 5
1807+ } , schemaUri ) ;
1808+
1809+ const instance = 15 ;
1810+
1811+ /** @type OutputFormat */
1812+ const output = {
1813+ valid : false ,
1814+ errors : [
1815+ {
1816+ absoluteKeywordLocation : "https://example.com/main#/maximum" ,
1817+ instanceLocation : "#"
1818+ }
1819+ ]
1820+ } ;
1821+
1822+ const result = await betterJsonSchemaErrors ( output , schemaUri , instance ) ;
1823+
1824+ expect ( result . errors ) . to . eql ( [
1825+ {
1826+ message : localization . getNumberErrorMessage ( { maximum : 5 } ) ,
1827+ instanceLocation : "#" ,
1828+ schemaLocation : "https://example.com/main#/maximum"
1829+ }
1830+ ] ) ;
1831+ } ) ;
1832+
1833+ test ( "there should be one type message per schema" , async ( ) => {
1834+ registerSchema ( {
1835+ $schema : "https://json-schema.org/draft/2020-12/schema" ,
1836+ allOf : [
1837+ { type : "number" } ,
1838+ { type : "number" }
1839+ ]
1840+ } , schemaUri ) ;
1841+
1842+ const instance = "foo" ;
1843+
1844+ /** @type OutputFormat */
1845+ const output = {
1846+ valid : false ,
1847+ errors : [
1848+ {
1849+ absoluteKeywordLocation : "https://example.com/main#/allOf/0/type" ,
1850+ instanceLocation : "#"
1851+ } ,
1852+ {
1853+ absoluteKeywordLocation : "https://example.com/main#/allOf/1/type" ,
1854+ instanceLocation : "#"
1855+ }
1856+ ]
1857+ } ;
1858+
1859+ const result = await betterJsonSchemaErrors ( output , schemaUri , instance ) ;
1860+
1861+ expect ( result . errors ) . to . eql ( [
1862+ {
1863+ message : localization . getTypeErrorMessage ( [ "number" ] , "string" ) ,
1864+ instanceLocation : "#" ,
1865+ schemaLocation : [
1866+ "https://example.com/main#/allOf/0/type" ,
1867+ "https://example.com/main#/allOf/1/type"
1868+ ]
1869+ }
1870+ ] ) ;
1871+ } ) ;
1872+
17591873 test ( "normalized output for a failing 'contains' keyword" , async ( ) => {
17601874 registerSchema ( {
17611875 $schema : "https://json-schema.org/draft/2020-12/schema" ,
0 commit comments