Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow use of --discovery-url parameter #1377

Merged
merged 2 commits into from Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/generator/generate.ts
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import * as minimist from 'minimist';
import * as path from 'path';
import * as rimraf from 'rimraf';
import {install} from 'source-map-support';
Expand All @@ -24,13 +25,16 @@ import {Generator} from './generator';
// enable source map support
install();

const argv = minimist(process.argv.slice(2));
const DEFAULT_DISCOVERY_URL = 'https://www.googleapis.com/discovery/v1/apis/';
const discoveryUrl = argv['discovery-url'];

const debug = true;
const args = process.argv.slice(2);
const gen = new Generator({debug, includePrivate: false});

async function main() {
if (args.length) {
args.forEach(async url => {
if (!discoveryUrl && argv._.length > 0) {
argv._.forEach(async url => {
await gen.generateAPI(url);
console.log('Generated API for ' + url);
});
Expand All @@ -39,7 +43,7 @@ async function main() {
const apiPath = path.join(__dirname, '../../../src/apis');
await util.promisify(rimraf)(apiPath);
console.log('Generating APIs...');
await gen.generateAllAPIs();
await gen.generateAllAPIs(discoveryUrl || DEFAULT_DISCOVERY_URL);
console.log('Finished generating APIs!');
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/generator/generator.ts
Expand Up @@ -28,10 +28,6 @@ const cliArgs = argv._;
const writeFile = util.promisify(fs.writeFile);
const readDir = util.promisify(fs.readdir);

const DISCOVERY_URL = argv['discovery-url'] ?
argv['discovery-url'] :
(cliArgs.length ? cliArgs[0] :
'https://www.googleapis.com/discovery/v1/apis/');
const FRAGMENT_URL =
'https://storage.googleapis.com/apisnippets-staging/public/';

Expand Down Expand Up @@ -177,9 +173,9 @@ export class Generator {
/**
* Generate all APIs and write to files.
*/
async generateAllAPIs() {
async generateAllAPIs(discoveryUrl: string) {
const headers = this.options.includePrivate ? {} : {'X-User-Ip': '0.0.0.0'};
const res = await this.request<Schemas>({url: DISCOVERY_URL, headers});
const res = await this.request<Schemas>({url: discoveryUrl, headers});
const apis = res.data.items;
const queue = new Q({concurrency: 10});
console.log(`Generating ${apis.length} APIs...`);
Expand Down