added options for schemaFaker & reqName

This commit is contained in:
pavanteja-potnuru
2018-09-10 16:03:17 +05:30
parent a5dc21d81d
commit 2ee7be66f1
3 changed files with 19 additions and 12 deletions

View File

@@ -95,6 +95,7 @@ class Trie {
module.exports = {
// list of predefined schemas in components
components: {},
options: {},
/**
* Adds the neccessary server variables to the collection
@@ -196,9 +197,11 @@ module.exports = {
i,
summary,
path,
xthis,
// creating a root node for the trie (serves as the root dir)
trie = new Trie(root);
xthis = this;
for (path in paths) {
if (paths.hasOwnProperty(path)) {
// decalring a variable to be in this loops context only
@@ -256,7 +259,7 @@ module.exports = {
currentNode.addMethod({
name: summary,
id: operationItem.operationId,
id: operationItem[xthis.options.requestName],
method: method,
path: path,
properties: operationItem,
@@ -297,7 +300,7 @@ module.exports = {
_.forEach(pathVariables, (variable) => {
variables.push({
key: variable.name,
value: safeSchemaFaker(variable.schema || {}, this.components),
value: this.options.schemaFaker ? safeSchemaFaker(variable.schema || {}, this.components) : '',
description: variable.description || ''
});
});
@@ -408,7 +411,7 @@ module.exports = {
_.forOwn(responseHeaders, (value, key) => {
header = {
key: key,
value: safeSchemaFaker(value.schema || {}, this.components),
value: this.options.schemaFaker ? safeSchemaFaker(value.schema || {}, this.components) : '',
description: value.description || ''
};
headerArray.push(header);
@@ -484,7 +487,7 @@ module.exports = {
// This part is to remove format:binary from any string-type properties
// will cause schemaFaker to crash if left untreated
if (bodyObj.hasOwnProperty('schema')) {
bodyData = safeSchemaFaker(bodyObj.schema || {}, this.components);
bodyData = this.options.schemaFaker ? safeSchemaFaker(bodyObj.schema || {}, this.components) : '';
}
else if (bodyObj.hasOwnProperty('examples')) {
bodyData = this.getExampleData(openapi, bodyObj.examples);
@@ -522,7 +525,8 @@ module.exports = {
_.forEach(queryParameters, (param) => {
// check for existence of schema
if (param.hasOwnProperty('schema')) {
paramValue = safeSchemaFaker(param.schema, this.components); // fake data generated
// fake data generated
paramValue = this.options.schemaFaker ? safeSchemaFaker(param.schema, this.components) : '';
paramType = param.schema.type;
// checking the type of the query parameter
if (paramType === 'array') {
@@ -607,7 +611,7 @@ module.exports = {
_.forEach(headers, (header) => {
if (header.hasOwnProperty('schema')) {
fakeData = safeSchemaFaker(header.schema || {}, this.components);
fakeData = options.schemaFaker ? safeSchemaFaker(header.schema || {}, this.components) : '';
}
else {
fakeData = '';