MCPcopy Index your code
hub / github.com/ReAPI-com/mcp-openapi / DefaultSpecScanner

Class DefaultSpecScanner

src/core/SpecScanner.ts:32–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30 * and processes them using the provided SpecProcessor
31 */
32export class DefaultSpecScanner implements ISpecScanner {
33 constructor(private readonly specProcessor: ISpecProcessor) {}
34
35 /**
36 * Scans a directory for OpenAPI specification files and yields processed results
37 * @param folderPath - Path to the directory containing OpenAPI specs
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
77 * @param folderPath - Path to the directory containing the file
78 * @param filename - Name of the file to process
79 * @returns The processed spec result or null if the file type is invalid
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 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected