* Scans a directory for OpenAPI specification files and yields processed results * @param folderPath - Path to the directory containing OpenAPI specs * @throws {SpecScanError} If the folder doesn't exist or isn't readable
(
folderPath: string
)
| 38 | * @throws {SpecScanError} If the folder doesn't exist or isn't readable |
| 39 | */ |
| 40 | async *scan( |
| 41 | folderPath: string |
| 42 | ): AsyncGenerator<SpecScanResult, void, unknown> { |
| 43 | // Validate input |
| 44 | if (!folderPath) { |
| 45 | throw new Error("folderPath is required"); |
| 46 | } |
| 47 | |
| 48 | try { |
| 49 | const files = await fs.readdir(folderPath); |
| 50 | |
| 51 | for (const file of files) { |
| 52 | try { |
| 53 | const result = await this.processFile(folderPath, file); |
| 54 | if (result) { |
| 55 | yield result; |
| 56 | } |
| 57 | } catch (error) { |
| 58 | yield { |
| 59 | filename: file, |
| 60 | specId: file, |
| 61 | spec: {} as OpenAPIV3.Document, // Empty spec for error cases |
| 62 | error: error instanceof Error ? error : new Error(String(error)), |
| 63 | }; |
| 64 | } |
| 65 | } |
| 66 | } catch (error) { |
| 67 | throw new SpecScanError( |
| 68 | `Failed to read directory: ${folderPath}`, |
| 69 | folderPath, |
| 70 | error instanceof Error ? error : new Error(String(error)) |
| 71 | ); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Processes a single OpenAPI specification file |
nothing calls this directly
no test coverage detected