mirror of
https://github.com/sourcey/spectacle.git
synced 2024-09-11 05:25:36 +03:00
Use schema examples in 'request example'
This commit is contained in:
parent
4b830d020a
commit
2300e48d06
@ -25,3 +25,40 @@ module.exports = function(reference, options) {
|
||||
var html = common.printSchema(cloned);
|
||||
return new Handlebars.SafeString(html);
|
||||
};
|
||||
|
||||
|
||||
var Handlebars = require('handlebars');
|
||||
var common = require('../lib/common');
|
||||
var _ = require('lodash');
|
||||
|
||||
module.exports = function(reference, options) {
|
||||
if (!reference) {
|
||||
console.error("Cannot print null reference.");
|
||||
return '';
|
||||
}
|
||||
var model = common.resolveSchemaReference(reference, options.data.root);
|
||||
if (typeof model === 'object' && typeof model.properties === 'object') {
|
||||
if (model['example']) {
|
||||
// Use the supplied example
|
||||
model = model.example;
|
||||
var cloned = _.cloneDeep(model);
|
||||
} else {
|
||||
// Create json object of keys : type info string
|
||||
model = model.properties;
|
||||
var cloned = _.cloneDeep(model);
|
||||
Object.keys(cloned).forEach(function(propName) {
|
||||
var prop = cloned[propName];
|
||||
if (prop.type) {
|
||||
cloned[propName] = prop.type;
|
||||
if (prop.format) {
|
||||
cloned[propName] += ('(' + prop.format + ')');
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
if (options.hash.type == 'array')
|
||||
cloned = [cloned];
|
||||
var html = common.printSchema(cloned);
|
||||
return new Handlebars.SafeString(html);
|
||||
};
|
Loading…
Reference in New Issue
Block a user