changed safeschemafaker funcgion signature

This commit is contained in:
Dhroov Gupta
2019-08-21 16:03:10 +05:30
parent a7e32eb524
commit cb6010c7d9
4 changed files with 10 additions and 10 deletions

3
.gitignore vendored
View File

@@ -42,5 +42,4 @@ test/data/.temp
*.orig
# Prevent unit test coverage reports from being added
.coverage
tempOutput.json
.coverage

View File

@@ -151,7 +151,6 @@ module.exports = {
// shallow cloning schema object except properties object
let tempSchema = _.omit(schema, 'properties');
tempSchema.properties = {};
for (prop in schema.properties) {
if (schema.properties.hasOwnProperty(prop)) {
/* eslint-disable max-depth */

View File

@@ -64,13 +64,13 @@ schemaFaker.option({
* Safe wrapper for schemaFaker that resolves references and
* removes things that might make schemaFaker crash
* @param {*} oldSchema the schema to fake
* @param {string} bodyType tells that the schema object is of request or response
* @param {*} components list of predefined components (with schemas)
* @param {string} schemaFormat default or xml
* @param {string} indentCharacter char for 1 unit of indentation
* @param {string} bodyType tells that the schema object is of request or response
* @returns {object} fakedObject
*/
function safeSchemaFaker(oldSchema, components, schemaFormat, indentCharacter, bodyType) {
function safeSchemaFaker(oldSchema, bodyType, components, schemaFormat, indentCharacter) {
var prop,
schema = deref.resolveRefs(oldSchema, bodyType, components);
@@ -756,7 +756,7 @@ module.exports = {
if (this.getHeaderFamily(contentType) === HEADER_TYPE.XML) {
schemaType = SCHEMA_FORMATS.XML;
}
bodyData = safeSchemaFaker(bodyObj.schema || {}, this.components, schemaType, indentCharacter, bodyType);
bodyData = safeSchemaFaker(bodyObj.schema || {}, bodyType, this.components, schemaType, indentCharacter);
}
else {
// do not fake if the option is false

View File

@@ -29,9 +29,10 @@ describe('UTILITY FUNCTION TESTS ', function () {
$ref: '#/components/schemas/schema2'
}
}
};
},
bodyType = 'REQUEST';
expect(Utils.safeSchemaFaker(schema, components)).to.equal('<string>');
expect(Utils.safeSchemaFaker(schema, bodyType, components)).to.equal('<string>');
done();
});
@@ -62,10 +63,11 @@ describe('UTILITY FUNCTION TESTS ', function () {
$ref: '#/components/schem2'
}
}
};
},
bodyType = 'REQUEST';
expect(function() {
Utils.safeSchemaFaker(schema, components);
Utils.safeSchemaFaker(schema, bodyType, components);
}).to.throw(openApiErr, 'Invalid schema reference: #/components/schem2');
done();
});