OpenApiComponentAnnotationScanner.ScanFromRunningScriptOrPath method

Scan starting from the running script (via $PSCommandPath) or a provided mainPath, follow dot-sourced files, and extract “standalone attribute line applies to next variable assignment” annotations.

public static Dictionary<string, AnnotatedVariable> ScanFromRunningScriptOrPath(
    EngineIntrinsics engine, string? mainPath = null, 
    IReadOnlyCollection<string>? attributeTypeFilter = null, string componentNameArgument = "Name", 
    int maxFiles = 200)
parameter description
engine The PowerShell engine intrinsics.
mainPath Optional main script file path to start scanning from. If null, uses the running script path ($PSCommandPath).
attributeTypeFilter Optional filter of attribute type names to include. If null or empty, includes all.
componentNameArgument The name of the attribute argument to use as component name.
maxFiles Maximum number of files to scan to prevent cycles.

Return Value

A dictionary keyed by variable name. Each value contains the collected annotations, the declared variable type (if any), and the initializer value/expression (if any).

Exceptions

exception condition
InvalidOperationException Thrown if no running script path is found and no mainPath is provided.

Remarks

This method performs a breadth-first traversal of the script files starting from mainPath or $PSCommandPath, following dot-sourced includes and extracting attribute annotations that precede variable assignments.

See Also