Skip to content

Commit

Permalink
remove spaces from paths with spoofed params
Browse files Browse the repository at this point in the history
reformatted entire codebase
  • Loading branch information
noahdietz committed Jun 15, 2018
1 parent ec863cb commit 229fc54
Show file tree
Hide file tree
Showing 13 changed files with 2,070 additions and 1,296 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.vscode
node_modules
.DS_Store
.DS_Store
.idea
oatts.iml
59 changes: 37 additions & 22 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,47 @@ cli.version(require('../package.json').version)
.usage('<subcommand>')

cli.command('generate')
.description('generate unit test scaffolding for a given OpenAPI/Swagger Spec')
.description(
'generate unit test scaffolding for a given OpenAPI/Swagger Spec')
.option('--host <host>', 'target hostname to use in test generation')
.option('-p, --paths <paths>', 'comma separated list of paths to generate tests for', util.sep)
.option('-e, --samples', 'generate sample response bodies rather than schema, if applicable')
.option('-s, --spec <spec>', 'path to the target OpenAPI/Swagger spec document to consume')
.option('-w, --writeTo <writeTo>', 'directory to write the generated tests to file')
.option('-c, --consumes <consumes>', 'consumes/content-type to use in request when applicable to the API resource')
.option('-o, --produces <produces>', 'produces/accept to use in request when applicable to the API resource')
.option('-u, --customValues <customValues>', 'custom request values to be used in generation; takes precedent over a customValuesFile')
.option('--customValuesFile <customValuesFile>', 'path to JSON file with custom request values to be used in generation')
.option('-m, --scheme <scheme>', 'which scheme to use if multiple are present in spec')
.option('-t --templates <templateDir>', 'path to direcotry of custom templates')
.option('-S, --status-codes <statusCodes>', 'comma separated list of status codes to explicity generate tests for', util.sep)
.action(function(options) {
options.error = util.optionError;
if (!options.spec) { return options.error('spec path is required'); }

var generated = oatts.generate(options.spec, options);
generated.then(function(gen){
.option('-p, --paths <paths>',
'comma separated list of paths to generate tests for', util.sep)
.option('-e, --samples',
'generate sample response bodies rather than schema, if applicable')
.option('-s, --spec <spec>',
'path to the target OpenAPI/Swagger spec document to consume')
.option('-w, --writeTo <writeTo>',
'directory to write the generated tests to file')
.option('-c, --consumes <consumes>',
'consumes/content-type to use in request when applicable to the API resource')
.option('-o, --produces <produces>',
'produces/accept to use in request when applicable to the API resource')
.option('-u, --customValues <customValues>',
'custom request values to be used in generation; takes precedent over a customValuesFile')
.option('--customValuesFile <customValuesFile>',
'path to JSON file with custom request values to be used in generation')
.option('-m, --scheme <scheme>',
'which scheme to use if multiple are present in spec')
.option('-t --templates <templateDir>',
'path to direcotry of custom templates')
.option('-S, --status-codes <statusCodes>',
'comma separated list of status codes to explicity generate tests for',
util.sep)
.action(function (options) {
options.error = util.optionError;
if (!options.spec) {
return options.error('spec path is required');
}

var generated = oatts.generate(options.spec, options);
generated.then(function (gen) {
if (options.writeTo === undefined) {
console.log(gen)
console.log(gen)
}
},
function(err) {
},
function (err) {
console.error(err)
});
});
});

cli.parse(process.argv);
15 changes: 7 additions & 8 deletions bin/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@
'use strict';

module.exports = {
sep: sep,
optionError: optionError
sep: sep,
optionError: optionError
}

function sep(list) {
var sep = list.split(',')
sep.forEach(function(s, ndx, arr) {
arr[ndx] = s.trim()
});
var sep = list.split(',')
sep.forEach(function (s, ndx, arr) {
arr[ndx] = s.trim()
});

return sep
return sep
}


function optionError(message) {
console.error(message);
this.help();
Expand Down
62 changes: 32 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var join = require('path').join
var merge2 = require('./lib/util').merge2

module.exports = {
generate: generate
generate: generate
}

/**
Expand All @@ -40,37 +40,39 @@ module.exports = {
* @return {Promise<GenerationResults>}
*/
function generate(specPath, options) {
return sway.create({'definition': specPath})
.then(function (api) {
if (options.customValues) {
options.customValues = JSON.parse(options.customValues);
}

if (options.customValuesFile) {
var customFromFile = require(join(process.cwd(), options.customValuesFile))
options.customValues = merge2(options.customValues, customFromFile)
}
return sway.create({'definition': specPath})
.then(function (api) {
if (options.customValues) {
options.customValues = JSON.parse(options.customValues);
}

var processed = proc(api, options)
var compiled = compile(processed, options)
if (options.customValuesFile) {
var customFromFile = require(
join(process.cwd(), options.customValuesFile))
options.customValues = merge2(options.customValues, customFromFile)
}

if (options.writeTo !== undefined) {
if (!fs.existsSync(options.writeTo)) {
fs.mkdirSync(options.writeTo)
}

compiled.forEach(function(testObj, ndx, arr) {
fs.writeFile(join(options.writeTo, testObj.filename), testObj.contents, function(err) {
if (err !== null) {
console.error(err)
}
})
var processed = proc(api, options)
var compiled = compile(processed, options)

if (options.writeTo !== undefined) {
if (!fs.existsSync(options.writeTo)) {
fs.mkdirSync(options.writeTo)
}

compiled.forEach(function (testObj, ndx, arr) {
fs.writeFile(join(options.writeTo, testObj.filename),
testObj.contents, function (err) {
if (err !== null) {
console.error(err)
}
})
}
})
}

return { 'generated': compiled }
}, function (err) {
console.error(err.stack);
return err
});
return {'generated': compiled}
}, function (err) {
console.error(err.stack);
return err
});
}
23 changes: 14 additions & 9 deletions jsdoc.config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{
"source": {
"exclude": ["./node_modules", "./test", "./templates", "./docs"]
},
"opts": {
"destination": "./docs",
"readme": "./README.md",
"recurse": true,
"template": "./node_modules/docdash"
}
"source": {
"exclude": [
"./node_modules",
"./test",
"./templates",
"./docs"
]
},
"opts": {
"destination": "./docs",
"readme": "./README.md",
"recurse": true,
"template": "./node_modules/docdash"
}
}
Loading

0 comments on commit 229fc54

Please sign in to comment.