@@ -2,10 +2,11 @@ package operations
22
33import (
44 "errors"
5+ "testing"
6+
57 oas "github.com/parvez3019/go-swagger3/openApi3Schema"
68 "github.com/parvez3019/go-swagger3/parser/schema"
79 "github.com/stretchr/testify/assert"
8- "testing"
910)
1011
1112func Test_ParseHeader (t * testing.T ) {
@@ -52,3 +53,70 @@ func Test_ParseHeader(t *testing.T) {
5253 })
5354 }
5455}
56+
57+ func TestParseParamComment_FormParam (t * testing.T ) {
58+ p := & parser {}
59+ op := & oas.OperationObject {}
60+
61+ comment := "@Param file form ignored true \" Upload file\" \" /path/to/file\" "
62+
63+ err := p .parseParamComment ("example/pkg" , "pkg" , op , comment )
64+ if err != nil {
65+ t .Fatalf ("Expected no error, got: %v" , err )
66+ }
67+ if op .RequestBody == nil {
68+ t .Error ("Expected RequestBody to be set for form param" )
69+ }
70+ }
71+
72+ func TestParseParamComment_BodyParam (t * testing.T ) {
73+ mockSchema := new (MockSchemaParser )
74+
75+ p := & parser {
76+ Parser : mockSchema ,
77+ }
78+
79+ op := & oas.OperationObject {}
80+
81+ comment := "@Param user body User true \" User info\" "
82+
83+ mockSchema .On ("RegisterType" , "example/pkg" , "pkg" , "User" ).Return ("UserSchemaRef" , nil )
84+
85+ err := p .parseParamComment ("example/pkg" , "pkg" , op , comment )
86+ if err != nil {
87+ t .Fatalf ("Expected no error, got: %v" , err )
88+ }
89+
90+ if op .RequestBody == nil {
91+ t .Error ("Expected RequestBody to be set for body param" )
92+ }
93+
94+ mockSchema .AssertExpectations (t )
95+ }
96+
97+ func TestParseParamComment_QueryParam (t * testing.T ) {
98+ p := & parser {}
99+ op := & oas.OperationObject {}
100+
101+ comment := "@Param id query int true \" User ID\" "
102+
103+ err := p .parseParamComment ("example/pkg" , "pkg" , op , comment )
104+ if err != nil {
105+ t .Fatalf ("Expected no error, got: %v" , err )
106+ }
107+ if len (op .Parameters ) == 0 {
108+ t .Error ("Expected query param to be added to operation.Parameters" )
109+ }
110+ }
111+
112+ func TestParseParamComment_InvalidComment (t * testing.T ) {
113+ p := & parser {}
114+ op := & oas.OperationObject {}
115+
116+ comment := "@Param invalid format only"
117+
118+ err := p .parseParamComment ("pkg" , "pkg" , op , comment )
119+ if err == nil {
120+ t .Error ("Expected error for invalid comment format, but got none" )
121+ }
122+ }
0 commit comments