* Processes a single OpenAPI specification file * @param folderPath - Path to the directory containing the file * @param filename - Name of the file to process * @returns The processed spec result or null if the file type is invalid * @throws {SpecScanError} If there's an error processin
(
folderPath: string,
filename: string
)
| 80 | * @throws {SpecScanError} If there's an error processing the file |
| 81 | */ |
| 82 | private async processFile( |
| 83 | folderPath: string, |
| 84 | filename: string |
| 85 | ): Promise<SpecScanResult | null> { |
| 86 | const fileType = this.getFileType(filename); |
| 87 | if (fileType === "invalid") { |
| 88 | return null; |
| 89 | } |
| 90 | |
| 91 | const filePath = path.join(folderPath, filename); |
| 92 | |
| 93 | try { |
| 94 | const content = await fs.readFile(filePath, "utf-8"); |
| 95 | const specObject = await this.parseSpec(content, fileType); |
| 96 | |
| 97 | // Validate basic spec structure |
| 98 | if (!this.isValidSpecObject(specObject)) { |
| 99 | throw new SpecScanError( |
| 100 | "Invalid OpenAPI specification format", |
| 101 | filename |
| 102 | ); |
| 103 | } |
| 104 | |
| 105 | const specId = this.extractSpecId(specObject, filename); |
| 106 | const processedSpec = await this.specProcessor.process(specObject); |
| 107 | |
| 108 | return { |
| 109 | filename, |
| 110 | spec: processedSpec, |
| 111 | specId, |
| 112 | }; |
| 113 | } catch (error) { |
| 114 | throw new SpecScanError( |
| 115 | `Failed to process spec file: ${filename}`, |
| 116 | filename, |
| 117 | error instanceof Error ? error : new Error(String(error)) |
| 118 | ); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Determines the file type based on the file extension |
no test coverage detected