Skip to content

Commit

Permalink
fix(generator): validate swagger file before parse
Browse files Browse the repository at this point in the history
fixes #58

Signed-off-by: Vojtech Mašek <[email protected]>
  • Loading branch information
vmasek committed Jun 22, 2018
1 parent 31dc76b commit cafa99f
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { existsSync, mkdir, readFile, writeFile } from 'fs';
import { ensureDir } from 'fs-extra';
import * as Mustache from 'mustache';
import { dirname, join } from 'path';
import { parse as swaggerFile } from 'swagger-parser';
import { parse as swaggerFile, validate } from 'swagger-parser';
import { promisify } from 'util';
import { MustacheData } from './types';
import { fileName } from './helper';
Expand All @@ -14,25 +14,26 @@ export async function generateAPIClient(swaggerFilePath: string, outputPath: str
await ensureDir(outputPath);
}

const mustacheData = createMustacheViewModel(await swaggerFile(
swaggerFilePath,
{
allow: {
json: true,
yaml: true,
empty: false,
unknown: false,
},
validate: {
schema: true,
spec: true,
}
}).catch((e) => console.error('Provided swagger file is invalid', e))
);
validate(swaggerFilePath, {
allow: {
json: true,
yaml: true,
empty: false,
unknown: false,
},
validate: {
schema: true,
spec: true,
}
}).then(
async () => {
const mustacheData = createMustacheViewModel(await swaggerFile(swaggerFilePath));

await generateClient(mustacheData, outputPath);
await generateModels(mustacheData, outputPath);
await generateModuleExportIndex(mustacheData, outputPath);
await generateClient(mustacheData, outputPath);
await generateModels(mustacheData, outputPath);
await generateModuleExportIndex(mustacheData, outputPath);
}
).catch((e) => console.error('Provided swagger file is invalid', e));
}

async function generateClient(viewContext: MustacheData, outputPath: string): Promise<void> {
Expand Down

0 comments on commit cafa99f

Please sign in to comment.