Skip to content

Commit

Permalink
Recursively resolve allOfs in parameter schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
saharj committed May 12, 2016
1 parent 5408972 commit ca1225c
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions scripts/directives/tryoperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,33 @@ SwaggerEditor.controller('TryOperation', function($scope, formdataFilter,
return model;
}

/**
* Resolves all of `allOf` recursively in a schema
* @description
* if a schema has allOf it means that the schema is the result of mergin all
* schemas in it's allOf array.
*
* @param {object} schema - JSON Schema
*
* @return {object} JSON Schema
*/
function resolveAllOf(schema) {
if (schema.allOf) {
schema = _.assign.apply(null, [schema].concat(schema.allOf));
delete schema.allOf;
}

if (_.isObject(schema.properties)) {
schema.properties = _.keys(schema.properties)
.reduce(function(properties, key) {
properties[key] = resolveAllOf(schema.properties[key]);
return properties;
}, {});
}

return schema;
}

/**
* Fills in empty gaps of a JSON Schema. This method is mostly used to
* normalize JSON Schema objects that are abstracted from Swagger parameters
Expand All @@ -300,12 +327,7 @@ SwaggerEditor.controller('TryOperation', function($scope, formdataFilter,
schema.title = schema.name;
}

// if a schema has allOf it means that the schema is the result of mergin all
// schemas in it's allOf array.
if (schema.allOf) {
schema = _.assign.apply(null, [schema].concat(schema.allOf));
delete schema.allOf;
}
schema = resolveAllOf(schema);

// if schema is missing the "type" property fill it in based on available
// properties
Expand Down

0 comments on commit ca1225c

Please sign in to comment.