mirror of
https://github.com/sourcey/spectacle.git
synced 2024-09-11 05:25:36 +03:00
Revert "Print examples using definition example fields"
This commit is contained in:
parent
17417bc334
commit
0fd043dd3b
@ -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;
|
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) {
|
printSchema: function(value) {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return '';
|
return '';
|
||||||
|
@ -68,7 +68,7 @@
|
|||||||
<div class="doc-examples">{{#if _show_requst_body_section}}
|
<div class="doc-examples">{{#if _show_requst_body_section}}
|
||||||
<section>
|
<section>
|
||||||
<h5>Request Example</h5>
|
<h5>Request Example</h5>
|
||||||
{{>swagger/print-example _request_body}}
|
{{>swagger/print-schema _request_body.schema}}
|
||||||
</section>
|
</section>
|
||||||
{{/if}}</div>
|
{{/if}}</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1 +0,0 @@
|
|||||||
<div class="hljs">{{printExample .}}</div>
|
|
@ -39,13 +39,16 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{! Print examples without whitespace. }}
|
{{! Print examples without whitespace. }}
|
||||||
<div class="doc-examples">
|
<div class="doc-examples">{{#each responses}}{{#if example}}
|
||||||
{{#each responses}}
|
|
||||||
<section>
|
<section>
|
||||||
<h5>Response Example <span>({{@key}} {{httpResponseCode @key}})</span></h5>
|
<h5>Response Example <span>({{@key}} {{httpResponseCode @key}})</span></h5>
|
||||||
{{>swagger/print-example .}}
|
{{>swagger/print-schema example}}
|
||||||
</section>
|
</section>
|
||||||
{{/each}}
|
{{else if schema}}
|
||||||
</div>
|
<section>
|
||||||
|
<h5>Response Example <span>({{@key}} {{httpResponseCode @key}})</span></h5>
|
||||||
|
{{>swagger/print-schema schema}}
|
||||||
|
</section>
|
||||||
|
{{/if}}{{/each}}</div>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
Loading…
Reference in New Issue
Block a user