This repository has been archived by the owner on May 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix requiring non-existent custom-formats file (#116)
- Loading branch information
Showing
17 changed files
with
538 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
}); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ | |
mocha: true | ||
rules: | ||
no-unused-expressions: false | ||
valid-jsdoc: 0; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.