swagger-model-validator
Advanced tools
Comparing version
@@ -1,41 +0,34 @@ | ||
###### Contributors | ||
[Brody Dunn](https://github.com/brodyd) | ||
<font color="#999">139 Commits</font> / <font color="#6cc644">11145++</font> / <font color="#bd3c00"> 2027--</font> | ||
<font color="#dedede">85.28% <font color="#dedede">|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||</font><br><br> | ||
[Hugo Durães](https://github.com/hugoduraes) | ||
<font color="#999">4 Commits</font> / <font color="#6cc644">383++</font> / <font color="#bd3c00"> 110--</font> | ||
<font color="#dedede">02.45% <font color="#dedede">||||</font><br><br> | ||
[Mitchell Burton](https://github.com/MitchellBurton) | ||
<font color="#999">3 Commits</font> / <font color="#6cc644">199++</font> / <font color="#bd3c00"> 22--</font> | ||
<font color="#dedede">01.84% <font color="#dedede">|||</font><br><br> | ||
[Brian Hou](https://github.com/brhou) | ||
<font color="#999">3 Commits</font> / <font color="#6cc644">61++</font> / <font color="#bd3c00"> 6--</font> | ||
<font color="#dedede">01.84% <font color="#dedede">|||</font><br><br> | ||
[Gareth Coleman](https://github.com/layerzerolabs) | ||
<font color="#999">2 Commits</font> / <font color="#6cc644">5++</font> / <font color="#bd3c00"> 6--</font> | ||
<font color="#dedede">01.23% <font color="#dedede">||</font><br><br> | ||
[Rory O'Connor](https://github.com/roryoconnor) | ||
<font color="#999">2 Commits</font> / <font color="#6cc644">137++</font> / <font color="#bd3c00"> 0--</font> | ||
<font color="#dedede">01.23% <font color="#dedede">||</font><br><br> | ||
[null](https://github.com/julianpellasrice) | ||
<font color="#999">2 Commits</font> / <font color="#6cc644">155++</font> / <font color="#bd3c00"> 4--</font> | ||
<font color="#dedede">01.23% <font color="#dedede">||</font><br><br> | ||
[Joe Mulvaney](https://github.com/mycrobe) | ||
<font color="#999">2 Commits</font> / <font color="#6cc644">283++</font> / <font color="#bd3c00"> 50--</font> | ||
<font color="#dedede">01.23% <font color="#dedede">||</font><br><br> | ||
[Abhilash Chelankara](https://github.com/abhiche) | ||
<font color="#999">2 Commits</font> / <font color="#6cc644">50++</font> / <font color="#bd3c00"> 4--</font> | ||
<font color="#dedede">01.23% <font color="#dedede">||</font><br><br> | ||
[Andrew Kandels](https://github.com/akandels) | ||
<font color="#999">1 Commits</font> / <font color="#6cc644">2++</font> / <font color="#bd3c00"> 2--</font> | ||
<font color="#dedede">00.61% <font color="#dedede">|</font><br><br> | ||
[Vu Nguyen](https://github.com/vudknguyen) | ||
<font color="#999">1 Commits</font> / <font color="#6cc644">2++</font> / <font color="#bd3c00"> 2--</font> | ||
<font color="#dedede">00.61% <font color="#dedede">|</font><br><br> | ||
[Jimi Ford](https://github.com/JimiHFord) | ||
<font color="#999">1 Commits</font> / <font color="#6cc644">1++</font> / <font color="#bd3c00"> 1--</font> | ||
<font color="#dedede">00.61% <font color="#dedede">|</font><br><br> | ||
[null](https://github.com/ssreedharan) | ||
<font color="#999">1 Commits</font> / <font color="#6cc644">1++</font> / <font color="#bd3c00"> 1--</font> | ||
<font color="#dedede">00.61% <font color="#dedede">|</font><br><br> | ||
###### [Generated](https://github.com/jakeleboeuf/contributor) on Wed Jun 05 2019 10:50:58 GMT+1200 (New Zealand Standard Time) | ||
## Contributors ✨ | ||
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): | ||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> | ||
<!-- prettier-ignore-start --> | ||
<!-- markdownlint-disable --> | ||
<table> | ||
<tr> | ||
<td align="center"><a href="https://github.com/brodyd"><img src="https://avatars.githubusercontent.com/u/2774160?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Brody Dunn</b></sub></a><br /><a href="#question-brodyd" title="Answering Questions">💬</a> <a href="https://github.com/Brody Dunn/swagger-model-validator/issues?q=author%3Abrodyd" title="Bug reports">🐛</a> <a href="https://github.com/Brody Dunn/swagger-model-validator/commits?author=brodyd" title="Code">💻</a> <a href="#content-brodyd" title="Content">🖋</a> <a href="#data-brodyd" title="Data">🔣</a> <a href="#design-brodyd" title="Design">🎨</a> <a href="https://github.com/Brody Dunn/swagger-model-validator/commits?author=brodyd" title="Documentation">📖</a> <a href="#example-brodyd" title="Examples">💡</a> <a href="#infra-brodyd" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#maintenance-brodyd" title="Maintenance">🚧</a> <a href="#projectManagement-brodyd" title="Project Management">📆</a> <a href="#research-brodyd" title="Research">🔬</a> <a href="https://github.com/Brody Dunn/swagger-model-validator/pulls?q=is%3Apr+reviewed-by%3Abrodyd" title="Reviewed Pull Requests">👀</a> <a href="#security-brodyd" title="Security">🛡️</a> <a href="https://github.com/Brody Dunn/swagger-model-validator/commits?author=brodyd" title="Tests">⚠️</a> <a href="#userTesting-brodyd" title="User Testing">📓</a></td> | ||
<td align="center"><a href="https://github.com/ssreedharan"><img src="https://avatars.githubusercontent.com/u/6464478?v=4?s=100" width="100px;" alt=""/><br /><sub><b>ssreedharan</b></sub></a><br /><a href="https://github.com/Brody Dunn/swagger-model-validator/commits?author=ssreedharan" title="Code">💻</a> <a href="#design-ssreedharan" title="Design">🎨</a> <a href="#ideas-ssreedharan" title="Ideas, Planning, & Feedback">🤔</a></td> | ||
<td align="center"><a href="http://hugoduraes.com/"><img src="https://avatars.githubusercontent.com/u/1050268?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Hugo Durães</b></sub></a><br /><a href="https://github.com/Brody Dunn/swagger-model-validator/commits?author=hugoduraes" title="Code">💻</a></td> | ||
<td align="center"><a href="https://github.com/MitchellBurton"><img src="https://avatars.githubusercontent.com/u/7017168?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mitchell Lawson-Burton</b></sub></a><br /><a href="https://github.com/Brody Dunn/swagger-model-validator/commits?author=MitchellBurton" title="Code">💻</a></td> | ||
<td align="center"><a href="https://github.com/brhou"><img src="https://avatars.githubusercontent.com/u/8788114?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Brian Hou</b></sub></a><br /><a href="https://github.com/Brody Dunn/swagger-model-validator/commits?author=brhou" title="Code">💻</a></td> | ||
<td align="center"><a href="http://www.l0l.org.uk/"><img src="https://avatars.githubusercontent.com/u/5329943?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Gareth Coleman</b></sub></a><br /><a href="https://github.com/Brody Dunn/swagger-model-validator/commits?author=layerzerolabs" title="Code">💻</a></td> | ||
<td align="center"><a href="https://github.com/roryoconnor"><img src="https://avatars.githubusercontent.com/u/10120520?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Rory Anthony O'Connor</b></sub></a><br /><a href="https://github.com/Brody Dunn/swagger-model-validator/commits?author=roryoconnor" title="Code">💻</a></td> | ||
</tr> | ||
<tr> | ||
<td align="center"><a href="https://github.com/julianpellasrice"><img src="https://avatars.githubusercontent.com/u/26866290?v=4?s=100" width="100px;" alt=""/><br /><sub><b>julianpellasrice</b></sub></a><br /><a href="https://github.com/Brody Dunn/swagger-model-validator/commits?author=julianpellasrice" title="Code">💻</a></td> | ||
<td align="center"><a href="https://github.com/mycrobe"><img src="https://avatars.githubusercontent.com/u/40182?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Joe Mulvaney</b></sub></a><br /><a href="https://github.com/Brody Dunn/swagger-model-validator/commits?author=mycrobe" title="Code">💻</a></td> | ||
<td align="center"><a href="https://github.com/abhiche"><img src="https://avatars.githubusercontent.com/u/5969234?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Abhilash Chelankara</b></sub></a><br /><a href="https://github.com/Brody Dunn/swagger-model-validator/commits?author=abhiche" title="Code">💻</a></td> | ||
<td align="center"><a href="https://www.linkedin.com/in/andrewkandels"><img src="https://avatars.githubusercontent.com/u/142410?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Andrew Kandels</b></sub></a><br /><a href="https://github.com/Brody Dunn/swagger-model-validator/commits?author=akandels" title="Code">💻</a></td> | ||
<td align="center"><a href="https://github.com/vudknguyen"><img src="https://avatars.githubusercontent.com/u/16699073?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vu Nguyen</b></sub></a><br /><a href="https://github.com/Brody Dunn/swagger-model-validator/commits?author=vudknguyen" title="Code">💻</a></td> | ||
<td align="center"><a href="https://github.com/JimiFord"><img src="https://avatars.githubusercontent.com/u/58951452?v=4?s=100" width="100px;" alt=""/><br /><sub><b>JimiFord</b></sub></a><br /><a href="https://github.com/Brody Dunn/swagger-model-validator/commits?author=JimiFord" title="Code">💻</a></td> | ||
<td align="center"><a href="https://github.com/rogermui"><img src="https://avatars.githubusercontent.com/u/13083577?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Roger Mui</b></sub></a><br /><a href="https://github.com/Brody Dunn/swagger-model-validator/commits?author=rogermui" title="Code">💻</a></td> | ||
</tr> | ||
</table> | ||
<!-- markdownlint-restore --> | ||
<!-- prettier-ignore-end --> | ||
<!-- ALL-CONTRIBUTORS-LIST:END --> | ||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! |
@@ -361,3 +361,3 @@ 'use strict'; | ||
field.type = anyOfArray[x].type; | ||
var errorResult = validateType(name, value, anyOfArray[x], models, allowBlankTargets, disallowExtraProperties); | ||
var errorResult = validateSpecification(name, value, anyOfArray[x], models, allowBlankTargets, disallowExtraProperties); | ||
if (errorResult && !errorResult.valid) { | ||
@@ -375,3 +375,2 @@ var error = new Error(name + " is not a valid target for anyOf"); | ||
var allOfArray = field.allOf; | ||
var errors = []; | ||
@@ -383,11 +382,13 @@ | ||
if (errorResult && !errorResult.valid) { | ||
var error = new Error(name + " is not a valid target for allOf"); | ||
error.errors = errorResult; | ||
errors.push(error); | ||
} else { | ||
return null; | ||
for (var y in errorResult.errors) { | ||
errors.push(errorResult.errors[y]); | ||
} | ||
} | ||
} | ||
return createReturnObject(errors, name); | ||
if (errors.length > 0) { | ||
return createReturnObject(errors, name); | ||
} | ||
return null; | ||
} | ||
@@ -521,2 +522,5 @@ } else { | ||
var arrayErrors4 = []; | ||
var mappedTypes = {}; | ||
var discriminator = field.items.discriminator; | ||
field.items.oneOf.forEach(function(possibleType) { | ||
@@ -526,2 +530,12 @@ if(possibleType.$ref) { | ||
possibleTypes.push(models[typeRef]); | ||
if (discriminator && discriminator.mapping) { | ||
for (var x in discriminator.mapping) { | ||
if (replaceModelPrefix(discriminator.mapping[x]) === typeRef) { | ||
mappedTypes[x] = models[typeRef]; | ||
} | ||
} | ||
} else { | ||
mappedTypes[typeRef] = models[typeRef]; | ||
} | ||
} else { | ||
@@ -534,2 +548,20 @@ possibleTypes.push(possibleType); | ||
var passedValidation = false; | ||
if (discriminator) { | ||
possibleTypes = []; | ||
var discriminatorValue = value[discriminator.propertyName]; | ||
if (mappedTypes[discriminatorValue]) { | ||
var refErrors = validate(name, value, mappedTypes[discriminatorValue], models, allowBlankTargets, disallowExtraProperties); | ||
if (refErrors && !refErrors.valid) { | ||
for (var x in refErrors.errors) { | ||
arrayErrors4.push(refErrors.errors[x]); | ||
} | ||
} | ||
passedValidation = true; | ||
} | ||
} | ||
possibleTypes.forEach(function(possibleType){ | ||
@@ -547,2 +579,3 @@ if(!passedValidation) { | ||
countItems = countItems + 1; | ||
count = count + 1; | ||
}); | ||
@@ -549,0 +582,0 @@ |
@@ -187,3 +187,3 @@ 'use strict'; | ||
return new Error(name + ' is not set to an allowed value (see enum)'); | ||
return new Error(name + ' must be one of the following: ' + enums.join(', ')); | ||
} | ||
@@ -190,0 +190,0 @@ |
{ | ||
"name": "swagger-model-validator", | ||
"version": "3.0.20", | ||
"version": "3.0.21", | ||
"description": "Validate incoming objects against Swagger Models.", | ||
@@ -29,2 +29,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"all-contributors-cli": "^6.20.0", | ||
"nodeunit": "^0.11.3" | ||
@@ -142,8 +143,26 @@ }, | ||
{ | ||
"name": "Roger Mui", | ||
"email": null, | ||
"url": "https://github.com/rogermui", | ||
"contributions": 5, | ||
"additions": 345, | ||
"deletions": 21, | ||
"hireable": null | ||
}, | ||
{ | ||
"name": "Igor Korotach", | ||
"email": null, | ||
"url": "https://github.com/Emulebest", | ||
"contributions": 1, | ||
"additions": 45, | ||
"deletions": 2, | ||
"hireable": null | ||
}, | ||
{ | ||
"name": "Brody Dunn", | ||
"email": null, | ||
"url": "https://github.com/brodyd", | ||
"contributions": 139, | ||
"additions": 11145, | ||
"deletions": 2027, | ||
"contributions": 161, | ||
"additions": 18228, | ||
"deletions": 4273, | ||
"hireable": null | ||
@@ -150,0 +169,0 @@ } |
# Validate incoming objects against OpenAPI Models for Node.js | ||
[ ](https://codeship.com/projects/42728) | ||
[ ](https://badge.fury.io/js/swagger-model-validator) | ||
[](https://travis-ci.org/swagger-model-validator/swagger-model-validator) | ||
[](https://snyk.io/test/npm/swagger-model-validator/3.0.15) | ||
[](https://travis-ci.org/swagger-model-validator/swagger-model-validator) | ||
[](https://snyk.io/test/npm/swagger-model-validator/3.0.21) | ||
[](https://github.com/swagger-model-validator/swagger-model-validator/blob/master/contributors.md) | ||
@@ -7,0 +9,0 @@ [](https://nodei.co/npm-dl/swagger-model-validator/) |
68512
7.37%1103
2.41%256
0.79%2
100%