@@ -1084,3 +1084,67 @@ func TestWalk_Terminate_Success(t *testing.T) {
10841084
10851085 assert .Equal (t , 1 , visits , "expected only one visit before terminating" )
10861086}
1087+
1088+ func TestWalkAdditionalOperations_Success (t * testing.T ) {
1089+ t .Parallel ()
1090+
1091+ // Load OpenAPI document with additionalOperations
1092+ f , err := os .Open ("testdata/walk.additionaloperations.openapi.yaml" )
1093+ require .NoError (t , err )
1094+ defer f .Close ()
1095+
1096+ openAPIDoc , validationErrs , err := openapi .Unmarshal (t .Context (), f )
1097+ require .NoError (t , err )
1098+ require .Empty (t , validationErrs , "Document should be valid" )
1099+
1100+ matchedLocations := []string {}
1101+ expectedAssertions := map [string ]func (* openapi.Operation ){
1102+ "/paths/~1custom~1{id}/get" : func (op * openapi.Operation ) {
1103+ assert .Equal (t , "getCustomResource" , op .GetOperationID ())
1104+ assert .Equal (t , "Get custom resource" , op .GetSummary ())
1105+ },
1106+ "/paths/~1custom~1{id}/additionalOperations/COPY" : func (op * openapi.Operation ) {
1107+ assert .Equal (t , "copyCustomResource" , op .GetOperationID ())
1108+ assert .Equal (t , "Copy custom resource" , op .GetSummary ())
1109+ assert .Equal (t , "Custom COPY operation to duplicate a resource" , op .GetDescription ())
1110+ assert .Contains (t , op .GetTags (), "custom" )
1111+ },
1112+ "/paths/~1custom~1{id}/additionalOperations/PURGE" : func (op * openapi.Operation ) {
1113+ assert .Equal (t , "purgeCustomResource" , op .GetOperationID ())
1114+ assert .Equal (t , "Purge custom resource" , op .GetSummary ())
1115+ assert .Equal (t , "Custom PURGE operation to completely remove a resource" , op .GetDescription ())
1116+ assert .Contains (t , op .GetTags (), "custom" )
1117+ },
1118+ "/paths/~1standard/get" : func (op * openapi.Operation ) {
1119+ assert .Equal (t , "getStandardResource" , op .GetOperationID ())
1120+ assert .Equal (t , "Get standard resource" , op .GetSummary ())
1121+ },
1122+ }
1123+
1124+ for item := range openapi .Walk (t .Context (), openAPIDoc ) {
1125+ err := item .Match (openapi.Matcher {
1126+ Operation : func (op * openapi.Operation ) error {
1127+ operationLoc := string (item .Location .ToJSONPointer ())
1128+ matchedLocations = append (matchedLocations , operationLoc )
1129+
1130+ if assertFunc , exists := expectedAssertions [operationLoc ]; exists {
1131+ assertFunc (op )
1132+ }
1133+
1134+ return nil
1135+ },
1136+ })
1137+ require .NoError (t , err )
1138+ }
1139+
1140+ // Verify all expected operations were visited
1141+ for expectedLoc := range expectedAssertions {
1142+ assert .Contains (t , matchedLocations , expectedLoc , "Should visit operation at location: %s" , expectedLoc )
1143+ }
1144+
1145+ // Verify we found both standard and additional operations
1146+ assert .Contains (t , matchedLocations , "/paths/~1custom~1{id}/get" , "Should visit standard GET operation" )
1147+ assert .Contains (t , matchedLocations , "/paths/~1custom~1{id}/additionalOperations/COPY" , "Should visit additional COPY operation" )
1148+ assert .Contains (t , matchedLocations , "/paths/~1custom~1{id}/additionalOperations/PURGE" , "Should visit additional PURGE operation" )
1149+ assert .Contains (t , matchedLocations , "/paths/~1standard/get" , "Should visit standard operation on path without additionalOperations" )
1150+ }
0 commit comments