@@ -942,6 +942,96 @@ func TestOperation_ParseParamCommentV3(t *testing.T) {
942942 assert .True (t , tFound , "results should contain t" )
943943 assert .True (t , t2Found , "results should contain t2" )
944944 })
945+
946+ t .Run ("struct headers" , func (t * testing.T ) {
947+ t .Parallel ()
948+ parser := New ()
949+ parser .packages .uniqueDefinitions ["main.Object" ] = & TypeSpecDef {
950+ File : & ast.File {Name : & ast.Ident {Name : "test" }},
951+ TypeSpec : & ast.TypeSpec {
952+ Name : & ast.Ident {Name : "Field" },
953+ TypeParams : & ast.FieldList {List : []* ast.Field {{Names : []* ast.Ident {{Name : "T" }}}}},
954+ Type : & ast.StructType {
955+ Struct : 100 ,
956+ Fields : & ast.FieldList {
957+ List : []* ast.Field {
958+ {
959+ Names : []* ast.Ident {
960+ {Name : "T" },
961+ },
962+ Type : ast .NewIdent ("string" ),
963+ },
964+ {
965+ Names : []* ast.Ident {
966+ {Name : "T2" },
967+ },
968+ Type : ast .NewIdent ("string" ),
969+ },
970+ },
971+ },
972+ },
973+ },
974+ }
975+ o := NewOperationV3 (parser )
976+ err := o .ParseComment (`@Param some_object header main.Object true "Some Object"` ,
977+ nil )
978+
979+ assert .NoError (t , err )
980+
981+ expectedT := & spec.RefOrSpec [spec.Extendable [spec.Parameter ]]{
982+ Spec : & spec.Extendable [spec.Parameter ]{
983+ Spec : & spec.Parameter {
984+ Name : "t" ,
985+ In : "header" ,
986+ Schema : & spec.RefOrSpec [spec.Schema ]{
987+ Spec : & spec.Schema {
988+ JsonSchema : spec.JsonSchema {
989+ JsonSchemaCore : spec.JsonSchemaCore {
990+ Type : & typeString ,
991+ },
992+ },
993+ },
994+ },
995+ },
996+ },
997+ }
998+ expectedT2 := & spec.RefOrSpec [spec.Extendable [spec.Parameter ]]{
999+ Spec : & spec.Extendable [spec.Parameter ]{
1000+ Spec : & spec.Parameter {
1001+ Name : "t2" ,
1002+ In : "header" ,
1003+ Schema : & spec.RefOrSpec [spec.Schema ]{
1004+ Spec : & spec.Schema {
1005+ JsonSchema : spec.JsonSchema {
1006+ JsonSchemaCore : spec.JsonSchemaCore {
1007+ Type : & typeString ,
1008+ },
1009+ },
1010+ },
1011+ },
1012+ },
1013+ },
1014+ }
1015+
1016+ assert .Len (t , o .Parameters , 2 )
1017+ tFound := false
1018+ t2Found := false
1019+ for _ , param := range o .Parameters {
1020+ switch param .Spec .Spec .Name {
1021+ case "t" :
1022+ assert .EqualValues (t , expectedT , param )
1023+ tFound = true
1024+ case "t2" :
1025+ assert .EqualValues (t , expectedT2 , param )
1026+ t2Found = true
1027+ default :
1028+ assert .Fail (t , "unexpected result" )
1029+ }
1030+ }
1031+
1032+ assert .True (t , tFound , "results should contain t" )
1033+ assert .True (t , t2Found , "results should contain t2" )
1034+ })
9451035}
9461036
9471037// Test ParseParamComment Query Params
0 commit comments