mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	import/order sorts require() calls as well as import statements. Signed-off-by: Anders Kaseorg <anders@zulip.com>
		
			
				
	
	
		
			44 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
#!/usr/bin/env node
 | 
						|
 | 
						|
const fs = require("fs");
 | 
						|
 | 
						|
const jsyaml = require("js-yaml");
 | 
						|
const ExampleValidator = require("openapi-examples-validator");
 | 
						|
const SwaggerParser = require("swagger-parser");
 | 
						|
 | 
						|
(async () => {
 | 
						|
    // Iterate through the changed files, passed in the arguments.
 | 
						|
    // The two first arguments are the call to the Node interpreter and this
 | 
						|
    // script, hence the starting point at 2.
 | 
						|
    for (const file of process.argv.slice(2)) {
 | 
						|
        try {
 | 
						|
            if (
 | 
						|
                jsyaml.safeLoad(await fs.promises.readFile(file, "utf8"), {
 | 
						|
                    filename: file,
 | 
						|
                }).openapi !== undefined
 | 
						|
            ) {
 | 
						|
                await SwaggerParser.validate(file);
 | 
						|
                const res = await ExampleValidator.validateFile(file);
 | 
						|
                if (!res.valid) {
 | 
						|
                    for (const error of res.errors) {
 | 
						|
                        console.error(error);
 | 
						|
                    }
 | 
						|
                    process.exitCode = 1;
 | 
						|
                }
 | 
						|
            }
 | 
						|
        } catch (error) {
 | 
						|
            if (error instanceof jsyaml.YAMLException) {
 | 
						|
                console.error(error.message);
 | 
						|
            } else if (error instanceof SyntaxError) {
 | 
						|
                console.error(`${file}: ${error.message}`);
 | 
						|
            } else {
 | 
						|
                throw error;
 | 
						|
            }
 | 
						|
            process.exitCode = 1;
 | 
						|
        }
 | 
						|
    }
 | 
						|
})().catch((error) => {
 | 
						|
    console.error(error);
 | 
						|
    process.exit(1);
 | 
						|
});
 |