@@ -23,6 +23,11 @@ func forType[T any]() *jsonschema.Schema {
2323
2424func TestFor (t * testing.T ) {
2525 type schema = jsonschema.Schema
26+
27+ type S struct {
28+ B int `jsonschema:"bdesc"`
29+ }
30+
2631 tests := []struct {
2732 name string
2833 got * jsonschema.Schema
@@ -45,9 +50,9 @@ func TestFor(t *testing.T) {
4550 {
4651 "struct" ,
4752 forType [struct {
48- F int `json:"f"`
53+ F int `json:"f" jsonschema:"fdesc" `
4954 G []float64
50- P * bool
55+ P * bool `jsonschema:"pdesc"`
5156 Skip string `json:"-"`
5257 NoSkip string `json:",omitempty"`
5358 unexported float64
@@ -56,13 +61,13 @@ func TestFor(t *testing.T) {
5661 & schema {
5762 Type : "object" ,
5863 Properties : map [string ]* schema {
59- "f" : {Type : "integer" },
64+ "f" : {Type : "integer" , Description : "fdesc" },
6065 "G" : {Type : "array" , Items : & schema {Type : "number" }},
61- "P" : {Types : []string {"null" , "boolean" }},
66+ "P" : {Types : []string {"null" , "boolean" }, Description : "pdesc" },
6267 "NoSkip" : {Type : "string" },
6368 },
6469 Required : []string {"f" , "G" , "P" },
65- AdditionalProperties : & jsonschema. Schema { Not : & jsonschema. Schema {}} ,
70+ AdditionalProperties : falseSchema () ,
6671 },
6772 },
6873 {
@@ -75,7 +80,37 @@ func TestFor(t *testing.T) {
7580 "Y" : {Type : "integer" },
7681 },
7782 Required : []string {"X" , "Y" },
78- AdditionalProperties : & jsonschema.Schema {Not : & jsonschema.Schema {}},
83+ AdditionalProperties : falseSchema (),
84+ },
85+ },
86+ {
87+ "nested and embedded" ,
88+ forType [struct {
89+ A S
90+ S
91+ }](),
92+ & schema {
93+ Type : "object" ,
94+ Properties : map [string ]* schema {
95+ "A" : {
96+ Type : "object" ,
97+ Properties : map [string ]* schema {
98+ "B" : {Type : "integer" , Description : "bdesc" },
99+ },
100+ Required : []string {"B" },
101+ AdditionalProperties : falseSchema (),
102+ },
103+ "S" : {
104+ Type : "object" ,
105+ Properties : map [string ]* schema {
106+ "B" : {Type : "integer" , Description : "bdesc" },
107+ },
108+ Required : []string {"B" },
109+ AdditionalProperties : falseSchema (),
110+ },
111+ },
112+ Required : []string {"A" , "S" },
113+ AdditionalProperties : falseSchema (),
79114 },
80115 },
81116 }
@@ -205,7 +240,6 @@ func TestForWithCycle(t *testing.T) {
205240 }
206241
207242 for _ , test := range tests {
208- test := test // prevent loop shadowing
209243 t .Run (test .name , func (t * testing.T ) {
210244 err := test .fn ()
211245 if test .shouldErr && err == nil {
0 commit comments