Skip to content

Commit ba77ae2

Browse files
committed
browser/swagger-client.js: Throw errors for null types
Avoid 'too much recursion' errors with properties like: "species": { "type": "string", "enum": [ null, "cat", "dog" ] } The JSON Schema spec says for enums [1]: > Elements in the array MAY be of any type, including null. But they aren't supported by Swagger 2.0, because null isn't one of Swagger 2's types [2,3]. This commit gives a more obvious hint about that. It would be nice to have clarification in the spec so we could link to tidier docs than the GitHub issue too [2]. It would be nice if I could point to line numbers (or the chain of keys?) to find the broken entry in the parsed spec, but it doesn't seem like that information is available in resolveAllOf and I'm not clear enough on the larger picture here to know where that would plug in. [1]: http://json-schema.org/latest/json-schema-validation.html#anchor77 [2]: OAI/OpenAPI-Specification#229 (comment) [3]: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#data-types
1 parent 6041486 commit ba77ae2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

browser/swagger-client.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,9 @@ Resolver.prototype.resolveAllOf = function(spec, obj, depth) {
14931493
var name;
14941494
for(var key in obj) {
14951495
var item = obj[key];
1496+
if(item === null) {
1497+
throw new TypeError("Swagger 2.0 does not support null types (" + obj + "). See https://github.com/swagger-api/swagger-spec/issues/229.")
1498+
}
14961499
if(item && typeof item.allOf !== 'undefined') {
14971500
var allOf = item.allOf;
14981501
if(Array.isArray(allOf)) {

0 commit comments

Comments
 (0)