@@ -452,35 +452,41 @@ func diffJSON(a, b []byte) (bool, error) {
452452 return reflect .DeepEqual (j2 , j ), nil
453453}
454454
455+ type InEmbed struct {
456+ D int `query:"xd" enum:"1,2,3" default:"1"`
457+ E bool `query:"e"`
458+ F * string `json:"f" description:"This is F"`
459+ G []byte `validate:"required"`
460+ H uint16 `binding:"-"`
461+ K []string `query:"k" enum:"aaa,bbb,ccc"`
462+ }
463+ type inEmbedPrivate struct {
464+ I string `query:"i"`
465+ }
466+ type h string
467+ type In struct {
468+ * In // ignored, recusrive embedding
469+ * InEmbed
470+ * inEmbedPrivate
471+
472+ A int `path:"a" description:"This is A" deprecated:"oui"`
473+ B time.Time `query:"b" validate:"required" description:"This is B"`
474+ C string `header:"X-Test-C" description:"This is C" default:"test"`
475+ d int // ignored, unexported field
476+ E int `path:"a"` // ignored, duplicate of A
477+ F * string `json:"f"` // ignored, duplicate of F in InEmbed
478+ G * inEmbedPrivate
479+ h // ignored, embedded field of non-struct type
480+
481+ }
482+
483+ func (i In ) Description () string {
484+ return "Test input schema description"
485+ }
486+
455487// TestAddOperation tests that an operation can be added
456488// and generates the according specification.
457489func TestAddOperation (t * testing.T ) {
458- type InEmbed struct {
459- D int `query:"xd" enum:"1,2,3" default:"1"`
460- E bool `query:"e"`
461- F * string `json:"f" description:"This is F"`
462- G []byte `validate:"required"`
463- H uint16 `binding:"-"`
464- K []string `query:"k" enum:"aaa,bbb,ccc"`
465- }
466- type inEmbedPrivate struct {
467- I string `query:"i"`
468- }
469- type h string
470- type In struct {
471- * In // ignored, recusrive embedding
472- * InEmbed
473- * inEmbedPrivate
474-
475- A int `path:"a" description:"This is A" deprecated:"oui"`
476- B time.Time `query:"b" validate:"required" description:"This is B"`
477- C string `header:"X-Test-C" description:"This is C" default:"test"`
478- d int // ignored, unexported field
479- E int `path:"a"` // ignored, duplicate of A
480- F * string `json:"f"` // ignored, duplicate of F in InEmbed
481- G * inEmbedPrivate
482- h // ignored, embedded field of non-struct type
483- }
484490 type CustomError struct {}
485491
486492 var Header string
@@ -524,6 +530,17 @@ func TestAddOperation(t *testing.T) {
524530 if err != nil {
525531 t .Error (err )
526532 }
533+
534+ requestBodyName := infos .ID + "Input"
535+ requestBody , ok := g .API ().Components .Schemas [requestBodyName ]
536+ if ! ok {
537+ t .Errorf ("expected to found item for schema %s" , requestBodyName )
538+ }
539+
540+ if requestBody .Schema .Description == "" {
541+ t .Errorf ("expected to found description for schema %s" , requestBodyName )
542+ }
543+
527544 // Add another operation with no input/output type.
528545 // No parameters should be present, and a response
529546 // matching the default status code used by tonic
0 commit comments