Skip to content

Commit

Permalink
Removing openap.is stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed Mar 7, 2018
1 parent 79d907c commit cfb683b
Showing 1 changed file with 1 addition and 67 deletions.
68 changes: 1 addition & 67 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ exports.api = function(args, opts) {
// a file name will always have a "."
if (action && action.indexOf('.') >= 0) {
action = 'push';
opts['in'] = args[0];
}

var actionObj = exports.load(action);
Expand All @@ -32,72 +31,7 @@ exports.api = function(args, opts) {
'opts': opts,
};

if(actionObj.swagger) {
utils.findSwagger(info, function(err, swagger, file) {
if(err) {
console.error(err);
return;
}

var apiId = swagger.info.title ? uslug(swagger.info.title) : crypto.randomBytes(7).toString('hex');

request.get('https://openap.is/check/' + apiId, {json: true}, (err, check) => {
if(!swagger['x-api-id']) {

if(check.body.exists) {
// If this already exists, rather than giving a confusing
// "permissions" error, we just add a suffix
apiId += '-' + crypto.randomBytes(2).toString('hex');
}

console.log('Your Swagger file needs a unique "x-api-id" property to work. Do you want us to add it automatically?');
var add = prompt('Add automatically? ' + '(y/n) '.grey);
if(add.trim()[0] != 'y') {
console.log("");
console.log("Okay! To do it yourself, edit "+file.split('/').slice(-1)[0].yellow+" and add the following 'x-api-id' line:");
exampleId(file, apiId);

console.log("");
console.log("Make sure you commit the changes so your team is all using the same ID.");

process.exit();
} else {

if(utils.addId(file, apiId)) {
console.log("Success! ".green + "We added it to your Swagger file! Make sure you commit the changes so your team is all using the same ID.");
console.log("");
swagger['x-api-id'] = apiId;
} else {
console.log("We weren't able to add the ID automatically. In "+file.split('/').slice(-1)[0].yellow+", add the following 'x-api-id' line:");

exampleId(file, apiId);

console.log("Make sure you commit the changes so your team is all using the same ID.");

process.exit();
}

}
}

utils.removeMetadata(swagger);

info.swagger = swagger;

if(actionObj.swaggerUrl) {
utils.getSwaggerUrl(config, info, function(url) {
info.swaggerUrl = url;
actionObj.run(config, info);
});
} else {
actionObj.run(config, info);
}
});
});
} else {
actionObj.run(config, info);
}

actionObj.run(config, info);
};

exports.load = function(action) {
Expand Down

0 comments on commit cfb683b

Please sign in to comment.