@@ -1654,7 +1654,15 @@ func TestReflector_Reflect_deeplyEmbedded(t *testing.T) {
1654
1654
Baz float64 `json:"baz" title:"Bazzz."`
1655
1655
}
1656
1656
1657
- s , err := r .Reflect (My {})
1657
+ val := My {}
1658
+ val .DeeplyEmbedded = & DeeplyEmbedded {}
1659
+ val .Foo = "abcde"
1660
+ val .Bar = 123
1661
+ val .Baz = 4.56
1662
+
1663
+ assertjson .EqMarshal (t , `{"foo":"abcde","bar":123,"baz":4.56}` , val )
1664
+
1665
+ s , err := r .Reflect (val )
1658
1666
require .NoError (t , err )
1659
1667
1660
1668
assertjson .EqMarshal (t , `{
@@ -1667,6 +1675,96 @@ func TestReflector_Reflect_deeplyEmbedded(t *testing.T) {
1667
1675
}` , s )
1668
1676
}
1669
1677
1678
+ func TestReflector_Reflect_deeplyEmbedded_emptyJSONTags (t * testing.T ) {
1679
+ r := jsonschema.Reflector {}
1680
+
1681
+ type Embed struct {
1682
+ Foo string `json:",omitempty" minLength:"5"` // Empty name in tag results in Go field name.
1683
+ Bar int `json:"bar" minimum:"3"`
1684
+ }
1685
+
1686
+ type DeeplyEmbedded struct {
1687
+ Embed `json:""`
1688
+ }
1689
+
1690
+ type My struct {
1691
+ * DeeplyEmbedded `json:",inline"` // `inline` does not have any specific handling by encoding/json.
1692
+
1693
+ Baz float64 `json:"baz" title:"Bazzz."`
1694
+ }
1695
+
1696
+ val := My {}
1697
+ val .DeeplyEmbedded = & DeeplyEmbedded {}
1698
+ val .Foo = "abcde"
1699
+ val .Bar = 123
1700
+ val .Baz = 4.56
1701
+
1702
+ assertjson .EqMarshal (t , `{"Foo":"abcde","bar":123,"baz":4.56}` , val )
1703
+
1704
+ s , err := r .Reflect (val )
1705
+ require .NoError (t , err )
1706
+
1707
+ assertjson .EqMarshal (t , `{
1708
+ "properties":{
1709
+ "bar":{"minimum":3,"type":"integer"},
1710
+ "baz":{"title":"Bazzz.","type":"number"},
1711
+ "Foo":{"minLength":5,"type":"string"}
1712
+ },
1713
+ "type":"object"
1714
+ }` , s )
1715
+ }
1716
+
1717
+ func TestReflector_Reflect_deeplyEmbedded_validJSONTags (t * testing.T ) {
1718
+ r := jsonschema.Reflector {}
1719
+
1720
+ type Embed struct {
1721
+ Foo string `json:"foo" minLength:"5"`
1722
+ Bar int `json:"bar" minimum:"3"`
1723
+ }
1724
+
1725
+ type DeeplyEmbedded struct {
1726
+ Embed `json:"emb"`
1727
+ }
1728
+
1729
+ type My struct {
1730
+ * DeeplyEmbedded `json:"deep,inline"` // `inline` does not have any specific handling by encoding/json.
1731
+
1732
+ Baz float64 `json:"baz" title:"Bazzz."`
1733
+ }
1734
+
1735
+ val := My {}
1736
+ val .DeeplyEmbedded = & DeeplyEmbedded {}
1737
+ val .Foo = "abcde"
1738
+ val .Bar = 123
1739
+ val .Baz = 4.56
1740
+
1741
+ assertjson .EqMarshal (t , `{"deep":{"emb":{"foo":"abcde","bar":123}},"baz":4.56}` , val )
1742
+
1743
+ s , err := r .Reflect (val )
1744
+ require .NoError (t , err )
1745
+
1746
+ assertjson .EqMarshal (t , `{
1747
+ "definitions":{
1748
+ "JsonschemaGoTestDeeplyEmbedded":{
1749
+ "properties":{"emb":{"$ref":"#/definitions/JsonschemaGoTestEmbed"}},
1750
+ "type":"object"
1751
+ },
1752
+ "JsonschemaGoTestEmbed":{
1753
+ "properties":{
1754
+ "bar":{"minimum":3,"type":"integer"},
1755
+ "foo":{"minLength":5,"type":"string"}
1756
+ },
1757
+ "type":"object"
1758
+ }
1759
+ },
1760
+ "properties":{
1761
+ "baz":{"title":"Bazzz.","type":"number"},
1762
+ "deep":{"$ref":"#/definitions/JsonschemaGoTestDeeplyEmbedded"}
1763
+ },
1764
+ "type":"object"
1765
+ }` , s )
1766
+ }
1767
+
1670
1768
func TestReflector_Reflect_deeplyEmbeddedUnexported (t * testing.T ) {
1671
1769
r := jsonschema.Reflector {}
1672
1770
@@ -1685,7 +1783,14 @@ func TestReflector_Reflect_deeplyEmbeddedUnexported(t *testing.T) {
1685
1783
Baz float64 `json:"baz" title:"Bazzz."`
1686
1784
}
1687
1785
1688
- s , err := r .Reflect (My {})
1786
+ val := My {}
1787
+ val .Foo = "abcde"
1788
+ val .Bar = 123
1789
+ val .Baz = 4.56
1790
+
1791
+ assertjson .EqMarshal (t , `{"foo":"abcde","bar":123,"baz":4.56}` , val )
1792
+
1793
+ s , err := r .Reflect (val )
1689
1794
require .NoError (t , err )
1690
1795
1691
1796
assertjson .EqMarshal (t , `{
0 commit comments