diff --git a/.gitignore b/.gitignore index 0601d1f..4d72169 100644 --- a/.gitignore +++ b/.gitignore @@ -42,5 +42,4 @@ test/data/.temp *.orig # Prevent unit test coverage reports from being added -.coverage -tempOutput.json \ No newline at end of file +.coverage \ No newline at end of file diff --git a/lib/deref.js b/lib/deref.js index 3ce5384..203b154 100644 --- a/lib/deref.js +++ b/lib/deref.js @@ -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 */ diff --git a/lib/util.js b/lib/util.js index 533d871..ebd88af 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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 diff --git a/test/unit/util.test.js b/test/unit/util.test.js index 0c6cc75..3219dcf 100644 --- a/test/unit/util.test.js +++ b/test/unit/util.test.js @@ -29,9 +29,10 @@ describe('UTILITY FUNCTION TESTS ', function () { $ref: '#/components/schemas/schema2' } } - }; + }, + bodyType = 'REQUEST'; - expect(Utils.safeSchemaFaker(schema, components)).to.equal(''); + expect(Utils.safeSchemaFaker(schema, bodyType, components)).to.equal(''); 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(); });