Skip to content

Commit

Permalink
fix: Parse input URL (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
ffflorian committed May 27, 2019
1 parent d5da7ec commit f20a3a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Swaxios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from 'fs-extra';
import initializeHelpers from 'handlebars-helpers';
import path from 'path';
import {Path, Spec} from 'swagger-schema-official';
import url from 'url';
import yaml from 'yamljs';

import {APIClientGenerator, IndexFileGenerator, ResourceGenerator} from './generators';
Expand Down Expand Up @@ -98,7 +99,8 @@ async function readInputFile(inputFile: string): Promise<Spec> {
}

export async function writeClient(inputFile: string, outputDirectory: string): Promise<void> {
const swaggerJson = inputFile.startsWith('http:') ? await readInputURL(inputFile) : await readInputFile(inputFile);
const parsedInput = url.parse(inputFile);
const swaggerJson = parsedInput.protocol ? await readInputURL(inputFile) : await readInputFile(inputFile);
await validateConfig(swaggerJson);
return generateClient(swaggerJson, outputDirectory);
}
3 changes: 1 addition & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ if (!program.input || !program.output) {
process.exit(1);
}

const inputFile = program.input.startsWith('http:') ? program.input : path.resolve(process.cwd(), program.input);
const outputDirectory = path.resolve(process.cwd(), program.output);

writeClient(inputFile, outputDirectory)
writeClient(program.input, outputDirectory)
.then(() => {
console.log(`Created API client in "${outputDirectory}".`);
})
Expand Down

0 comments on commit f20a3a6

Please sign in to comment.