mirror of
https://github.com/sourcey/spectacle.git
synced 2024-09-11 05:25:36 +03:00
Merge pull request #44 from sourcey/revert-42-print-example
Revert "Print examples using definition example fields"
This commit is contained in:
commit
df8aea5ba8
@ -1,10 +0,0 @@
|
||||
var Handlebars = require('handlebars');
|
||||
var common = require('../lib/common');
|
||||
|
||||
module.exports = function(value, options) {
|
||||
var cloned = common.formatExample(value, options.data.root);
|
||||
if (options.hash.type == 'array')
|
||||
cloned = [cloned];
|
||||
var html = common.printSchema(cloned);
|
||||
return new Handlebars.SafeString(html)
|
||||
};
|
@ -67,47 +67,6 @@ var common = {
|
||||
return cloned;
|
||||
},
|
||||
|
||||
formatExample: function(value, root) {
|
||||
if (value.example) {
|
||||
return value.example;
|
||||
}
|
||||
else if (value.schema && value.schema.$ref) {
|
||||
return this.formatExampleProp(value.schema, root);
|
||||
}
|
||||
else if (value.schema && value.schema.items) {
|
||||
return this.formatExampleProp(value.schema.items.$ref, root);
|
||||
}
|
||||
},
|
||||
|
||||
formatExampleProp: function(ref, root) {
|
||||
var obj = {};
|
||||
var that = this;
|
||||
|
||||
if (ref.$ref) {
|
||||
ref = this.resolveSchemaReference(ref.$ref, root);
|
||||
return this.formatExampleProp(ref, root);
|
||||
}
|
||||
else if (ref.type == 'object') {
|
||||
Object.keys(ref.properties).forEach(function(k) {
|
||||
obj[k] = that.formatExampleProp(ref.properties[k], root);
|
||||
});
|
||||
}
|
||||
else if (ref.type == 'array' && ref.items) {
|
||||
obj = [
|
||||
this.formatExampleProp(ref.items, root),
|
||||
this.formatExampleProp(ref.items, root),
|
||||
];
|
||||
}
|
||||
else if (ref.example) {
|
||||
return ref.example;
|
||||
}
|
||||
else {
|
||||
return ref.type + (ref.format ? ' (' + ref.format + ')' : '');
|
||||
}
|
||||
|
||||
return obj;
|
||||
},
|
||||
|
||||
printSchema: function(value) {
|
||||
if (!value) {
|
||||
return '';
|
||||
|
@ -68,7 +68,7 @@
|
||||
<div class="doc-examples">{{#if _show_requst_body_section}}
|
||||
<section>
|
||||
<h5>Request Example</h5>
|
||||
{{>swagger/print-example _request_body}}
|
||||
{{>swagger/print-schema _request_body.schema}}
|
||||
</section>
|
||||
{{/if}}</div>
|
||||
</div>
|
||||
|
@ -1 +0,0 @@
|
||||
<div class="hljs">{{printExample .}}</div>
|
@ -37,15 +37,18 @@
|
||||
{{/each}}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
|
||||
{{! Print examples without whitespace. }}
|
||||
<div class="doc-examples">
|
||||
{{#each responses}}
|
||||
<div class="doc-examples">{{#each responses}}{{#if example}}
|
||||
<section>
|
||||
<h5>Response Example <span>({{@key}} {{httpResponseCode @key}})</span></h5>
|
||||
{{>swagger/print-example .}}
|
||||
{{>swagger/print-schema example}}
|
||||
</section>
|
||||
{{/each}}
|
||||
</div>
|
||||
{{else if schema}}
|
||||
<section>
|
||||
<h5>Response Example <span>({{@key}} {{httpResponseCode @key}})</span></h5>
|
||||
{{>swagger/print-schema schema}}
|
||||
</section>
|
||||
{{/if}}{{/each}}</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
Loading…
Reference in New Issue
Block a user