@@ -33,13 +33,16 @@ func TestRemoveElementsExact(t *testing.T) {
33
33
"x-private-matter" ,
34
34
)
35
35
36
+ // PATH-LEVEL EXTENSION
36
37
c .Assert (doc .Paths .Value ("/orgs/{orgId}/projects" ).Extensions ["x-snyk-api-resource" ], qt .Not (qt .IsNil ))
38
+
39
+ // DOC-LEVEL EXTENSION (Root of the OpenAPI)
37
40
c .Assert (doc .Extensions ["x-snyk-api-lifecycle" ], qt .Not (qt .IsNil ))
38
41
39
42
// Remove some of them
40
43
41
44
err = vervet .RemoveElements (doc .T , vervet.ExcludePatterns {
42
- ExtensionPatterns : []string {"x-snyk-api-releases" , "x-snyk-api-resource" },
45
+ ExtensionPatterns : []string {"x-snyk-api-releases" , "x-snyk-api-resource" , "x-snyk-api-lifecycle" },
43
46
HeaderPatterns : []string {"snyk-request-id" , "x-private-matter" },
44
47
Paths : []string {"/examples/hello-world" , "/examples/hello-world/{id}" },
45
48
})
@@ -60,8 +63,11 @@ func TestRemoveElementsExact(t *testing.T) {
60
63
c .Assert (doc .Paths .Value ("/orgs/{org_id}/projects/{project_id}" ).
61
64
Delete .Parameters , qt .HasLen , 3 ) // x-private-matter removed
62
65
63
- c .Assert (doc .Paths .Value ("/orgs/{orgId}/projects" ).Extensions ["x-snyk-api-resource" ], qt .IsNil ) // now removed
64
- c .Assert (doc .Extensions ["x-snyk-api-lifecycle" ], qt .Not (qt .IsNil )) // still there
66
+ // PATH-LEVEL EXTENSION removed
67
+ c .Assert (doc .Paths .Value ("/orgs/{orgId}/projects" ).Extensions ["x-snyk-api-resource" ], qt .IsNil )
68
+
69
+ // DOC-LEVEL EXTENSION removed
70
+ c .Assert (doc .Extensions ["x-snyk-api-lifecycle" ], qt .IsNil )
65
71
}
66
72
67
73
func TestRemoveElementsRegex (t * testing.T ) {
@@ -91,12 +97,17 @@ func TestRemoveElementsRegex(t *testing.T) {
91
97
)
92
98
93
99
c .Assert (doc .Paths .Value ("/orgs/{orgId}/projects" ).Extensions ["x-snyk-api-resource" ], qt .Not (qt .IsNil ))
94
- c .Assert (doc .Extensions ["x-snyk-api-lifecycle" ], qt .Not (qt .IsNil ))
95
100
96
- // Remove some of them
101
+ // DOC-LEVEL EXTENSION (root)
102
+ c .Assert (doc .Extensions ["x-snyk-api-lifecycle" ], qt .Not (qt .IsNil ))
97
103
104
+ // Remove using regex patterns
105
+ // - "x-snyk-api-r.*" matches "x-snyk-api-resource"
106
+ // - "snyk-version-.*" matches "snyk-version-served" header
107
+ // - "x-private-.*" matches "x-private-matter"
108
+ // - "x-snyk-api-lifecycle" for doc-level extension
98
109
err = vervet .RemoveElements (doc .T , vervet.ExcludePatterns {
99
- ExtensionPatterns : []string {"x-snyk-api-r.*" },
110
+ ExtensionPatterns : []string {"x-snyk-api-r.*" , "x-snyk-api-lifecycle" },
100
111
HeaderPatterns : []string {"snyk-version-.*" , "x-private-.*" },
101
112
})
102
113
c .Assert (err , qt .IsNil )
@@ -115,8 +126,11 @@ func TestRemoveElementsRegex(t *testing.T) {
115
126
doc .Paths .Value ("/orgs/{org_id}/projects/{project_id}" ).Delete .Parameters ,
116
127
qt .HasLen ,
117
128
3 ,
118
- ) // x-private-matter removed
129
+ )
130
+
131
+ // PATH-LEVEL EXTENSION "x-snyk-api-resource" removed
132
+ c .Assert (doc .Paths .Value ("/orgs/{orgId}/projects" ).Extensions ["x-snyk-api-resource" ], qt .IsNil )
119
133
120
- c . Assert ( doc . Paths . Value ( "/orgs/{orgId}/projects" ). Extensions [ " x-snyk-api-resource" ], qt . IsNil ) // now removed
121
- c .Assert (doc .Extensions ["x-snyk-api-lifecycle" ], qt .Not ( qt . IsNil )) // still there
134
+ // DOC-LEVEL EXTENSION " x-snyk-api-lifecycle" removed
135
+ c .Assert (doc .Extensions ["x-snyk-api-lifecycle" ], qt .IsNil )
122
136
}
0 commit comments