Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Commit

Permalink
fix requiring non-existent custom-formats file (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
Remco75 authored and noahdietz committed Sep 14, 2016
1 parent d07c691 commit 9faa113
Show file tree
Hide file tree
Showing 17 changed files with 538 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
wrap-iife: 2
one-var: [2, "never"]
quote-props: [2, "as-needed"]
max-len: [2, 80, 2]
max-len: [2, 160, 2]
yoda: [2, "never"]
dot-notation: 2
new-cap: 2
Expand Down
30 changes: 13 additions & 17 deletions custom-formats.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,41 @@
/**
* Placeholder file for all custom-formats in known to swagger.json
* as found on
* https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#dataTypeFormat
*/
module.exports = function(zSchema) {
// Placeholder file for all custom-formats in known to swagger.json
// as found on
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#dataTypeFormat

var decimalPattern = /^\d{0,8}.?\d{0,4}[0]+$/;

exports = module.exports = function(ZSchema) {
var decimalPattern = /^\d{0,8}.?\d{0,4}[0]+$/;

/** Validates floating point as decimal / money (i.e: 12345678.123400..) */
ZSchema.registerFormat("double", function(val) {
zSchema.registerFormat('double', function(val) {
return !decimalPattern.test(val.toString());
});

/** Validates value is a 32bit integer */
ZSchema.registerFormat("int32", function(val) {
zSchema.registerFormat('int32', function(val) {
// the 32bit shift (>>) truncates any bits beyond max of 32
return Number.isInteger(val) && ((val >> 0) === val);
});

ZSchema.registerFormat("int64", function(val) {
zSchema.registerFormat('int64', function(val) {
return Number.isInteger(val);
});

ZSchema.registerFormat("float", function(val) {
zSchema.registerFormat('float', function(val) {
// should parse
return Number.isInteger(val);
});

ZSchema.registerFormat("date", function(val) {
zSchema.registerFormat('date', function(val) {
// should parse a a date
return !isNaN(Date.parse(val));
});

ZSchema.registerFormat("dateTime", function(val) {
zSchema.registerFormat('dateTime', function(val) {
return !isNaN(Date.parse(val));
});

ZSchema.registerFormat("password", function(val) {
zSchema.registerFormat('password', function(val) {
// should parse as a string
return typeof val === 'string'
return typeof val === 'string';
});

};
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var TYPE_JSON = 'application/json';

var handlebars = require('handlebars');
var sanitize = require('sanitize-filename');
var fs = require('fs');
var read = require('fs').readFileSync;
var _ = require('lodash');
var strObj = require('string');
Expand Down Expand Up @@ -399,10 +400,13 @@ function testGenPath(swagger, path, config) {
});

var output = '';
var customFormats = fs.readFileSync(require.resolve('./custom-formats'), 'utf-8');

var data = {
description: path,
assertion: config.assertionFormat,
testmodule: config.testModule,
customFormats: customFormats,
scheme: (swagger.schemes !== undefined ? swagger.schemes[0] : 'http'),
host: (swagger.host !== undefined ? swagger.host : 'localhost:10010'),
tests: result,
Expand Down
3 changes: 2 additions & 1 deletion templates/outerDescribe.handlebars
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';
var chai = require('chai');{{#if importValidator}}
var ZSchema = require('z-schema');
var customFormats = {{customFormats}}
customFormats(ZSchema);

require('./custom-formats')(ZSchema);
var validator = new ZSchema({});{{/if}}
{{#is testmodule 'request'}}
var request = require('request');
Expand Down
2 changes: 2 additions & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
mocha: true
rules:
no-unused-expressions: false
valid-jsdoc: 0;

44 changes: 43 additions & 1 deletion test/loadTest/compare/request/assert/base-path-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,50 @@
'use strict';
var chai = require('chai');
var ZSchema = require('z-schema');
var customFormats = module.exports = function(zSchema) {
// Placeholder file for all custom-formats in known to swagger.json
// as found on
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#dataTypeFormat

var decimalPattern = /^\d{0,8}.?\d{0,4}[0]+$/;

/** Validates floating point as decimal / money (i.e: 12345678.123400..) */
zSchema.registerFormat('double', function(val) {
return !decimalPattern.test(val.toString());
});

/** Validates value is a 32bit integer */
zSchema.registerFormat('int32', function(val) {
// the 32bit shift (>>) truncates any bits beyond max of 32
return Number.isInteger(val) && ((val >> 0) === val);
});

zSchema.registerFormat('int64', function(val) {
return Number.isInteger(val);
});

zSchema.registerFormat('float', function(val) {
// should parse
return Number.isInteger(val);
});

zSchema.registerFormat('date', function(val) {
// should parse a a date
return !isNaN(Date.parse(val));
});

zSchema.registerFormat('dateTime', function(val) {
return !isNaN(Date.parse(val));
});

zSchema.registerFormat('password', function(val) {
// should parse as a string
return typeof val === 'string';
});
};

customFormats(ZSchema);

require('./custom-formats')(ZSchema);
var validator = new ZSchema({});
var request = require('request');
var assert = chai.assert;
Expand Down
44 changes: 43 additions & 1 deletion test/loadTest/compare/request/expect/base-path-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,50 @@
'use strict';
var chai = require('chai');
var ZSchema = require('z-schema');
var customFormats = module.exports = function(zSchema) {
// Placeholder file for all custom-formats in known to swagger.json
// as found on
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#dataTypeFormat

var decimalPattern = /^\d{0,8}.?\d{0,4}[0]+$/;

/** Validates floating point as decimal / money (i.e: 12345678.123400..) */
zSchema.registerFormat('double', function(val) {
return !decimalPattern.test(val.toString());
});

/** Validates value is a 32bit integer */
zSchema.registerFormat('int32', function(val) {
// the 32bit shift (>>) truncates any bits beyond max of 32
return Number.isInteger(val) && ((val >> 0) === val);
});

zSchema.registerFormat('int64', function(val) {
return Number.isInteger(val);
});

zSchema.registerFormat('float', function(val) {
// should parse
return Number.isInteger(val);
});

zSchema.registerFormat('date', function(val) {
// should parse a a date
return !isNaN(Date.parse(val));
});

zSchema.registerFormat('dateTime', function(val) {
return !isNaN(Date.parse(val));
});

zSchema.registerFormat('password', function(val) {
// should parse as a string
return typeof val === 'string';
});
};

customFormats(ZSchema);

require('./custom-formats')(ZSchema);
var validator = new ZSchema({});
var request = require('request');
var expect = chai.expect;
Expand Down
44 changes: 43 additions & 1 deletion test/loadTest/compare/request/should/base-path-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,50 @@
'use strict';
var chai = require('chai');
var ZSchema = require('z-schema');
var customFormats = module.exports = function(zSchema) {
// Placeholder file for all custom-formats in known to swagger.json
// as found on
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#dataTypeFormat

var decimalPattern = /^\d{0,8}.?\d{0,4}[0]+$/;

/** Validates floating point as decimal / money (i.e: 12345678.123400..) */
zSchema.registerFormat('double', function(val) {
return !decimalPattern.test(val.toString());
});

/** Validates value is a 32bit integer */
zSchema.registerFormat('int32', function(val) {
// the 32bit shift (>>) truncates any bits beyond max of 32
return Number.isInteger(val) && ((val >> 0) === val);
});

zSchema.registerFormat('int64', function(val) {
return Number.isInteger(val);
});

zSchema.registerFormat('float', function(val) {
// should parse
return Number.isInteger(val);
});

zSchema.registerFormat('date', function(val) {
// should parse a a date
return !isNaN(Date.parse(val));
});

zSchema.registerFormat('dateTime', function(val) {
return !isNaN(Date.parse(val));
});

zSchema.registerFormat('password', function(val) {
// should parse as a string
return typeof val === 'string';
});
};

customFormats(ZSchema);

require('./custom-formats')(ZSchema);
var validator = new ZSchema({});
var request = require('request');

Expand Down
44 changes: 43 additions & 1 deletion test/loadTest/compare/supertest/assert/base-path-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,50 @@
'use strict';
var chai = require('chai');
var ZSchema = require('z-schema');
var customFormats = module.exports = function(zSchema) {
// Placeholder file for all custom-formats in known to swagger.json
// as found on
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#dataTypeFormat

var decimalPattern = /^\d{0,8}.?\d{0,4}[0]+$/;

/** Validates floating point as decimal / money (i.e: 12345678.123400..) */
zSchema.registerFormat('double', function(val) {
return !decimalPattern.test(val.toString());
});

/** Validates value is a 32bit integer */
zSchema.registerFormat('int32', function(val) {
// the 32bit shift (>>) truncates any bits beyond max of 32
return Number.isInteger(val) && ((val >> 0) === val);
});

zSchema.registerFormat('int64', function(val) {
return Number.isInteger(val);
});

zSchema.registerFormat('float', function(val) {
// should parse
return Number.isInteger(val);
});

zSchema.registerFormat('date', function(val) {
// should parse a a date
return !isNaN(Date.parse(val));
});

zSchema.registerFormat('dateTime', function(val) {
return !isNaN(Date.parse(val));
});

zSchema.registerFormat('password', function(val) {
// should parse as a string
return typeof val === 'string';
});
};

customFormats(ZSchema);

require('./custom-formats')(ZSchema);
var validator = new ZSchema({});
var supertest = require('supertest');
var api = supertest('https://api.uber.com'); // supertest init;
Expand Down
44 changes: 43 additions & 1 deletion test/loadTest/compare/supertest/expect/base-path-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,50 @@
'use strict';
var chai = require('chai');
var ZSchema = require('z-schema');
var customFormats = module.exports = function(zSchema) {
// Placeholder file for all custom-formats in known to swagger.json
// as found on
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#dataTypeFormat

var decimalPattern = /^\d{0,8}.?\d{0,4}[0]+$/;

/** Validates floating point as decimal / money (i.e: 12345678.123400..) */
zSchema.registerFormat('double', function(val) {
return !decimalPattern.test(val.toString());
});

/** Validates value is a 32bit integer */
zSchema.registerFormat('int32', function(val) {
// the 32bit shift (>>) truncates any bits beyond max of 32
return Number.isInteger(val) && ((val >> 0) === val);
});

zSchema.registerFormat('int64', function(val) {
return Number.isInteger(val);
});

zSchema.registerFormat('float', function(val) {
// should parse
return Number.isInteger(val);
});

zSchema.registerFormat('date', function(val) {
// should parse a a date
return !isNaN(Date.parse(val));
});

zSchema.registerFormat('dateTime', function(val) {
return !isNaN(Date.parse(val));
});

zSchema.registerFormat('password', function(val) {
// should parse as a string
return typeof val === 'string';
});
};

customFormats(ZSchema);

require('./custom-formats')(ZSchema);
var validator = new ZSchema({});
var supertest = require('supertest');
var api = supertest('https://api.uber.com'); // supertest init;
Expand Down
Loading

0 comments on commit 9faa113

Please sign in to comment.