in lib/validate.ts [323:369]
export async function generateExamples(
specPath: string,
payloadDir?: string,
operationIds?: string,
readme?: string,
tag?: string,
generationRule?: "Max" | "Min",
options?: Options
): Promise<any> {
if (!options) {
options = {};
}
const wholeInputFiles: string[] = [];
if (readme && tag) {
const inputFiles = await utils.getInputFiles(readme, tag);
if (!inputFiles) {
throw Error("get input files from readme tag failed.");
}
inputFiles.forEach((file) => {
if (path.isAbsolute(file)) {
wholeInputFiles.push(file);
} else {
wholeInputFiles.push(path.join(path.dirname(readme), file));
}
});
} else if (specPath) {
wholeInputFiles.push(specPath);
}
if (wholeInputFiles.length === 0) {
console.error(`no spec file specified !`);
}
log.consoleLogLevel = options.consoleLogLevel || log.consoleLogLevel;
log.filepath = options.logFilepath || log.filepath;
for (const file of wholeInputFiles) {
const generator = new ExampleGenerator(file, payloadDir, generationRule);
if (operationIds) {
const operationIdArray = operationIds.trim().split(",");
for (const operationId of operationIdArray) {
if (operationId) {
await generator.generate(operationId);
}
}
continue;
}
await generator.generateAll();
}
}