Skip to content
This repository was archived by the owner on Mar 15, 2019. It is now read-only.

Commit 1e02988

Browse files
author
Marc MacLeod
committed
.exists is not a valid js method
1 parent 6130e1d commit 1e02988

File tree

3 files changed

+36
-33
lines changed

3 files changed

+36
-33
lines changed

lib/exporters/swagger.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,11 +635,11 @@ Swagger.prototype._mapHostAndProtocol = function (env, swaggerDef) {
635635
if (hostUrl.path && hostUrl.path !== '/') {
636636
swaggerDef.BasePath = urlHelper.join(hostUrl.path, env.BasePath);
637637
}
638-
638+
639639
if (this._isTemplateUri(swaggerDef.basePath)) {
640640
this._convertToTemplateUri(swaggerDef);
641641
}
642-
642+
643643
if(Array.isArray(env.Protocols) && !_.isEmpty(env.Protocols)) {
644644
var filteredSchemes = [];
645645
env.Protocols.map(function(p){

lib/importers/swagger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ Swagger.prototype._mapResponseBody = function(responseBody, skipParameterRefs, r
213213
var res = {body: {}, example: '', codes: []}, description = '';
214214

215215
if (skipParameterRefs && needDeReferenced(responseBody[code]) &&
216-
(responseBody[code].$ref.match(/trait/) || $refs.exists(responseBody[code].$ref))) {
216+
(responseBody[code].$ref.match(/trait/) || _.includes($refs, responseBody[code].$ref))) {
217217
continue;
218218
}
219219

test/lib/converter.js

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ describe('Converter', function() {
172172
describe('reversable - from swagger 2 raml 2 swagger', function () {
173173
var baseDir = __dirname + '/../data/reversable/swagger';
174174
var testFiles = fs.readdirSync(baseDir);
175-
175+
176176
var testWithData = function (testFile) {
177177
return function (done) {
178178
var testFilePath = baseDir + '/' + testFile;
@@ -261,7 +261,7 @@ describe('reversable - from raml 2 swagger 2 raml', function () {
261261
describe('from swagger to raml', function () {
262262
var baseDir = __dirname + '/../data/swagger-import/swagger';
263263
var testFiles = fs.readdirSync(baseDir);
264-
264+
265265
var testWithData = function (sourceFile, targetFile, stringCompare) {
266266
return function (done) {
267267
var ramlVersion = _.includes(sourceFile, 'raml08') ? specConverter.Formats.RAML08 : specConverter.Formats.RAML10;
@@ -270,9 +270,9 @@ describe('from swagger to raml', function () {
270270
try{
271271
converter.convert('yaml', function(err, covertedRAML){
272272
if (err)return done(err);
273-
273+
274274
var notExistsTarget = !fs.existsSync(targetFile);
275-
275+
276276
if (notExistsTarget) {
277277
console.log('Content for non existing target file ' + targetFile + '\n.');
278278
console.log('********** Begin file **********\n');
@@ -298,19 +298,21 @@ describe('from swagger to raml', function () {
298298
};
299299

300300
testFiles.forEach(function (testFile) {
301-
var sourceFile = baseDir + '/' + testFile;
302-
var targetFile = baseDir + '/../raml/' + _.replace(testFile, 'json', 'yaml');
301+
if (!_.startsWith(testFile, '.')) {
302+
var sourceFile = baseDir + '/' + testFile;
303+
var targetFile = baseDir + '/../raml/' + _.replace(testFile, 'json', 'yaml');
303304

304-
if (process.env.fileToTest) {
305-
if (_.endsWith(sourceFile, process.env.fileToTest)) {
306-
it('test: ' + testFile, testWithData(sourceFile, targetFile, false));
307-
}
308-
}
309-
else {
310-
it('test: ' + testFile, testWithData(sourceFile, targetFile, false));
311-
}
305+
if (process.env.fileToTest) {
306+
if (_.endsWith(sourceFile, process.env.fileToTest)) {
307+
it('test: ' + testFile, testWithData(sourceFile, targetFile, false));
308+
}
309+
}
310+
else {
311+
it('test: ' + testFile, testWithData(sourceFile, targetFile, false));
312+
}
313+
}
312314
});
313-
315+
314316
if (!process.env.fileToTest) {
315317
it('should convert from swagger petstore with external refs to raml 1.0',
316318
testWithData(__dirname + '/../data/petstore-separate/spec/swagger.json', __dirname + '/../data/petstore-separate/raml10.yaml', true));
@@ -320,20 +322,20 @@ describe('from swagger to raml', function () {
320322
describe('from raml to swagger', function () {
321323
var baseDir = __dirname + '/../data/raml-import/raml';
322324
var testFiles = fs.readdirSync(baseDir);
323-
325+
324326
var myFsResolver = {
325327
content: function (filePath) {},
326328
contentAsync: function (filePath) {
327329
return new Promise(function(resolve, reject){
328330
try {
329331
var p = path.parse(filePath);
330-
332+
331333
if (p.dir.indexOf('types') > 0) {
332334
var baseDir = p.dir.replace('types', '../../types/');
333335
var fileName = p.base === 'Person.xyz' ? 'Person.json' : p.base;
334-
336+
335337
resolve(fs.readFileSync(baseDir + fileName, 'UTF8'));
336-
338+
337339
} else {
338340
resolve(fs.readFileSync(filePath, 'UTF8'));
339341
}
@@ -344,11 +346,11 @@ describe('from raml to swagger', function () {
344346
});
345347
}
346348
};
347-
349+
348350
var myOptions = {
349351
fsResolver : myFsResolver
350352
};
351-
353+
352354
var testWithData = function (testFile) {
353355
return function (done) {
354356
var testFilePath = baseDir + '/' + testFile;
@@ -359,7 +361,7 @@ describe('from raml to swagger', function () {
359361
converter.convert('json', function(err, resultSwagger){
360362
if (err)return done(err);
361363
var targetFile = baseDir + '/../swagger/' + _.replace(testFile, 'yaml', 'json');
362-
364+
363365
var notExistsTarget = !fs.existsSync(targetFile);
364366
if (notExistsTarget) {
365367
console.log('Content for non existing target file ' + targetFile + '\n.');
@@ -380,13 +382,14 @@ describe('from raml to swagger', function () {
380382
};
381383

382384
testFiles.forEach(function (testFile) {
383-
if (process.env.fileToTest) {
384-
if (_.endsWith(testFile, process.env.fileToTest)) {
385-
it('test: ' + testFile, testWithData(testFile));
386-
}
387-
}
388-
else {
389-
it('test: ' + testFile, testWithData(testFile));
390-
}
385+
if (!_.startsWith(testFile, '.')) {
386+
if (process.env.fileToTest) {
387+
if (_.endsWith(testFile, process.env.fileToTest)) {
388+
it('test: ' + testFile, testWithData(testFile));
389+
}
390+
} else {
391+
it('test: ' + testFile, testWithData(testFile));
392+
}
393+
}
391394
});
392395
});

0 commit comments

Comments
 (0)