diff --git a/app/helpers/printExample.js b/app/helpers/printExample.js deleted file mode 100644 index 7bb6c2b..0000000 --- a/app/helpers/printExample.js +++ /dev/null @@ -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) -}; diff --git a/app/lib/common.js b/app/lib/common.js index 810fd31..610a859 100644 --- a/app/lib/common.js +++ b/app/lib/common.js @@ -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 ''; diff --git a/app/views/partials/swagger/operation.hbs b/app/views/partials/swagger/operation.hbs index 94ac337..3a44fbc 100644 --- a/app/views/partials/swagger/operation.hbs +++ b/app/views/partials/swagger/operation.hbs @@ -68,7 +68,7 @@
{{#if _show_requst_body_section}}
Request Example
- {{>swagger/print-example _request_body}} + {{>swagger/print-schema _request_body.schema}}
{{/if}}
diff --git a/app/views/partials/swagger/print-example.hbs b/app/views/partials/swagger/print-example.hbs deleted file mode 100644 index d4559c9..0000000 --- a/app/views/partials/swagger/print-example.hbs +++ /dev/null @@ -1 +0,0 @@ -
{{printExample .}}
diff --git a/app/views/partials/swagger/responses.hbs b/app/views/partials/swagger/responses.hbs index 15ef62c..77e061d 100644 --- a/app/views/partials/swagger/responses.hbs +++ b/app/views/partials/swagger/responses.hbs @@ -37,15 +37,18 @@ {{/each}} - + {{! Print examples without whitespace. }} -
- {{#each responses}} +
{{#each responses}}{{#if example}}
Response Example ({{@key}} {{httpResponseCode @key}})
- {{>swagger/print-example .}} + {{>swagger/print-schema example}}
- {{/each}} -
+ {{else if schema}} +
+
Response Example ({{@key}} {{httpResponseCode @key}})
+ {{>swagger/print-schema schema}} +
+ {{/if}}{{/each}}
{{/if}}