@@ -22,6 +22,11 @@ func forType[T any]() *jsonschema.Schema {
2222
2323func TestForType (t * testing.T ) {
2424 type schema = jsonschema.Schema
25+
26+ type S struct {
27+ B int `jsonschema:"bdesc"`
28+ }
29+
2530 tests := []struct {
2631 name string
2732 got * jsonschema.Schema
@@ -44,9 +49,9 @@ func TestForType(t *testing.T) {
4449 {
4550 "struct" ,
4651 forType [struct {
47- F int `json:"f"`
52+ F int `json:"f" jsonschema:"fdesc" `
4853 G []float64
49- P * bool
54+ P * bool `jsonschema:"pdesc"`
5055 Skip string `json:"-"`
5156 NoSkip string `json:",omitempty"`
5257 unexported float64
@@ -55,13 +60,13 @@ func TestForType(t *testing.T) {
5560 & schema {
5661 Type : "object" ,
5762 Properties : map [string ]* schema {
58- "f" : {Type : "integer" },
63+ "f" : {Type : "integer" , Description : "fdesc" },
5964 "G" : {Type : "array" , Items : & schema {Type : "number" }},
60- "P" : {Types : []string {"null" , "boolean" }},
65+ "P" : {Types : []string {"null" , "boolean" }, Description : "pdesc" },
6166 "NoSkip" : {Type : "string" },
6267 },
6368 Required : []string {"f" , "G" , "P" },
64- AdditionalProperties : & jsonschema. Schema { Not : & jsonschema. Schema {}} ,
69+ AdditionalProperties : falseSchema () ,
6570 },
6671 },
6772 {
@@ -74,7 +79,37 @@ func TestForType(t *testing.T) {
7479 "Y" : {Type : "integer" },
7580 },
7681 Required : []string {"X" , "Y" },
77- AdditionalProperties : & jsonschema.Schema {Not : & jsonschema.Schema {}},
82+ AdditionalProperties : falseSchema (),
83+ },
84+ },
85+ {
86+ "nested and embedded" ,
87+ forType [struct {
88+ A S
89+ S
90+ }](),
91+ & schema {
92+ Type : "object" ,
93+ Properties : map [string ]* schema {
94+ "A" : {
95+ Type : "object" ,
96+ Properties : map [string ]* schema {
97+ "B" : {Type : "integer" , Description : "bdesc" },
98+ },
99+ Required : []string {"B" },
100+ AdditionalProperties : falseSchema (),
101+ },
102+ "S" : {
103+ Type : "object" ,
104+ Properties : map [string ]* schema {
105+ "B" : {Type : "integer" , Description : "bdesc" },
106+ },
107+ Required : []string {"B" },
108+ AdditionalProperties : falseSchema (),
109+ },
110+ },
111+ Required : []string {"A" , "S" },
112+ AdditionalProperties : falseSchema (),
78113 },
79114 },
80115 }
@@ -91,3 +126,7 @@ func TestForType(t *testing.T) {
91126 })
92127 }
93128}
129+
130+ func falseSchema () * jsonschema.Schema {
131+ return & jsonschema.Schema {Not : & jsonschema.Schema {}}
132+ }
0 commit comments