@@ -1443,6 +1443,46 @@ def test_json_schema_title_and_description():
1443
1443
}
1444
1444
1445
1445
1446
+ def test_json_schema_title_in_or ():
1447
+ s = Schema (
1448
+ {
1449
+ "test" : Or (
1450
+ Schema (
1451
+ "option1" , name = "Option 1" , description = "This is the first option"
1452
+ ),
1453
+ Schema (
1454
+ "option2" ,
1455
+ name = "Option 2" ,
1456
+ description = "This is the second option" ,
1457
+ ),
1458
+ )
1459
+ }
1460
+ )
1461
+ assert s .json_schema ("my-id" ) == {
1462
+ "$schema" : "http://json-schema.org/draft-07/schema#" ,
1463
+ "$id" : "my-id" ,
1464
+ "properties" : {
1465
+ "test" : {
1466
+ "anyOf" : [
1467
+ {
1468
+ "const" : "option1" ,
1469
+ "title" : "Option 1" ,
1470
+ "description" : "This is the first option" ,
1471
+ },
1472
+ {
1473
+ "const" : "option2" ,
1474
+ "title" : "Option 2" ,
1475
+ "description" : "This is the second option" ,
1476
+ },
1477
+ ]
1478
+ }
1479
+ },
1480
+ "required" : ["test" ],
1481
+ "additionalProperties" : False ,
1482
+ "type" : "object" ,
1483
+ }
1484
+
1485
+
1446
1486
def test_json_schema_description_nested ():
1447
1487
s = Schema (
1448
1488
{
@@ -1588,8 +1628,16 @@ def test_json_schema_ref_in_list():
1588
1628
1589
1629
assert generated_json_schema == {
1590
1630
"definitions" : {
1591
- "Inner test" : {"items" : {"type" : "string" }, "type" : "array" },
1592
- "Inner test2" : {"items" : {"type" : "string" }, "type" : "array" },
1631
+ "Inner test" : {
1632
+ "items" : {"type" : "string" },
1633
+ "type" : "array" ,
1634
+ "title" : "Inner test" ,
1635
+ },
1636
+ "Inner test2" : {
1637
+ "items" : {"type" : "string" },
1638
+ "type" : "array" ,
1639
+ "title" : "Inner test2" ,
1640
+ },
1593
1641
},
1594
1642
"anyOf" : [
1595
1643
{"$ref" : "#/definitions/Inner test" },
@@ -1775,6 +1823,7 @@ def test_json_schema_definitions():
1775
1823
"definitions" : {
1776
1824
"sub_schema" : {
1777
1825
"type" : "object" ,
1826
+ "title" : "sub_schema" ,
1778
1827
"properties" : {"sub_key1" : {"type" : "integer" }},
1779
1828
"required" : ["sub_key1" ],
1780
1829
"additionalProperties" : False ,
@@ -1824,6 +1873,7 @@ def test_json_schema_definitions_and_literals():
1824
1873
"sub_key1" : {"description" : "Sub key 1" , "type" : "integer" }
1825
1874
},
1826
1875
"required" : ["sub_key1" ],
1876
+ "title" : "sub_schema" ,
1827
1877
"additionalProperties" : False ,
1828
1878
}
1829
1879
},
@@ -1855,6 +1905,7 @@ def test_json_schema_definitions_nested():
1855
1905
"definitions" : {
1856
1906
"sub_schema" : {
1857
1907
"type" : "object" ,
1908
+ "title" : "sub_schema" ,
1858
1909
"properties" : {
1859
1910
"sub_key1" : {"type" : "integer" },
1860
1911
"sub_key2" : {"$ref" : "#/definitions/sub_sub_schema" },
@@ -1864,6 +1915,7 @@ def test_json_schema_definitions_nested():
1864
1915
},
1865
1916
"sub_sub_schema" : {
1866
1917
"type" : "object" ,
1918
+ "title" : "sub_sub_schema" ,
1867
1919
"properties" : {"sub_sub_key1" : {"type" : "integer" }},
1868
1920
"required" : ["sub_sub_key1" ],
1869
1921
"additionalProperties" : False ,
@@ -1894,6 +1946,7 @@ def test_json_schema_definitions_recursive():
1894
1946
"definitions" : {
1895
1947
"person" : {
1896
1948
"type" : "object" ,
1949
+ "title" : "person" ,
1897
1950
"properties" : {
1898
1951
"name" : {"type" : "string" },
1899
1952
"children" : {
0 commit comments