@@ -206,15 +206,18 @@ def _baseUrl(spec, origin=None, servers=None):
206206
207207_METHODS = ("get" , "post" , "put" , "delete" , "patch" , "options" , "head" )
208208
209- def openApiTargets (content , origin = None ):
209+ def openApiTargets (content , origin = None , tags = None ):
210210 """
211211 Returns a list of (url, method, data, headers) request tuples derived from an OpenAPI/Swagger
212212 specification. 'headers' is a list of (name, value) tuples (matching conf.httpHeaders). 'origin'
213213 (scheme://host[:port] of the specification's own location) is used only to resolve RELATIVE 'servers'
214214 entries - absolute server URLs are used as declared. Path parameters and header/cookie values carry
215- the custom injection mark so they become testable injection points.
215+ the custom injection mark so they become testable injection points. 'tags' (list) restricts extraction
216+ to operations declaring at least one of those OpenAPI tags (to scope a scan of a large API).
216217 """
217218
219+ tagSet = set (tags ) if tags else None
220+
218221 spec = _loadSpec (content )
219222 if not isinstance (spec , dict ) or not isinstance (spec .get ("paths" ), dict ) or not spec .get ("paths" ):
220223 errMsg = "no valid 'paths' object found in the provided OpenAPI/Swagger specification"
@@ -236,6 +239,8 @@ def openApiTargets(content, origin=None):
236239 for method , operation in item .items ():
237240 if str (method ).lower () not in _METHODS or not isinstance (operation , dict ): # str(): YAML keys can be non-string (e.g. 404, 'on'->bool)
238241 continue
242+ if tagSet is not None and not (tagSet & set (_ for _ in (operation .get ("tags" ) or []) if isinstance (_ , six .string_types ))):
243+ continue # '--openapi-tags' filter: operation carries none of the requested tags
239244 try :
240245 # effective base URL with OpenAPI precedence: operation 'servers' > path-item 'servers' > root
241246 opServers = operation .get ("servers" ) or item .get ("servers" )
0 commit comments