mirror of
https://github.com/sourcey/spectacle.git
synced 2024-08-16 08:50:36 +03:00
commit
21252e92de
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@
|
|||||||
*cache
|
*cache
|
||||||
*.log
|
*.log
|
||||||
node_modules
|
node_modules
|
||||||
|
.history
|
@ -5,6 +5,6 @@ module.exports = function(value, options) {
|
|||||||
var cloned = common.formatExample(value, options.data.root, options.hash)
|
var cloned = common.formatExample(value, options.data.root, options.hash)
|
||||||
if (!cloned)
|
if (!cloned)
|
||||||
return '';
|
return '';
|
||||||
var html = common.printSchema(cloned)
|
var html = common.printSchema(cloned, options.hash.yaml === true)
|
||||||
return new Handlebars.SafeString(html)
|
return new Handlebars.SafeString(html)
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
var cheerio = require('cheerio')
|
var cheerio = require('cheerio')
|
||||||
var marked = require('marked')
|
var marked = require('marked')
|
||||||
var highlight = require('highlight.js')
|
var highlight = require('highlight.js')
|
||||||
|
var yaml = require('js-yaml')
|
||||||
var _ = require('lodash')
|
var _ = require('lodash')
|
||||||
|
|
||||||
var common = {
|
var common = {
|
||||||
@ -158,16 +159,16 @@ var common = {
|
|||||||
console.error('Cannot format example on property ', ref, ref.$ref)
|
console.error('Cannot format example on property ', ref, ref.$ref)
|
||||||
},
|
},
|
||||||
|
|
||||||
printSchema: function(value) {
|
printSchema: function(value, toyaml) {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
var schemaString = JSON.stringify(value, null, 2)
|
var schemaString = toyaml ? yaml.safeDump(value, {skipInvalid:true}) : JSON.stringify(value, null, 2)
|
||||||
|
|
||||||
// Add an extra CRLR before the code so the postprocessor can determine
|
// Add an extra CRLR before the code so the postprocessor can determine
|
||||||
// the correct line indent for the <pre> tag.
|
// the correct line indent for the <pre> tag.
|
||||||
var $ = cheerio.load(marked("```json\r\n" + schemaString + "\n```"))
|
|
||||||
|
var $ = cheerio.load(marked(toyaml ? "```yaml\r\n" + schemaString + "```" : "```json\r\n" + schemaString + "\n```"))
|
||||||
var definitions = $('span:not(:has(span)):contains("#/definitions/")')
|
var definitions = $('span:not(:has(span)):contains("#/definitions/")')
|
||||||
definitions.each(function(index, item) {
|
definitions.each(function(index, item) {
|
||||||
var ref = $(item).html()
|
var ref = $(item).html()
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
<!-- <div class="hljs"> -->
|
<!-- <div class="hljs"> -->
|
||||||
{{printExample . showReadOnly=showReadOnly}}
|
{{printExample . showReadOnly=showReadOnly yaml=false}}
|
||||||
<!-- </div> -->
|
<!-- </div> -->
|
||||||
|
36
test/fixtures/Example.yml
vendored
Normal file
36
test/fixtures/Example.yml
vendored
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
swagger: '2.0'
|
||||||
|
paths:
|
||||||
|
definitions:
|
||||||
|
Order:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
cheeseId:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
quantity:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
shipDate:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
description: Order Status
|
||||||
|
enum:
|
||||||
|
- placed
|
||||||
|
- approved
|
||||||
|
- delivered
|
||||||
|
complete:
|
||||||
|
type: boolean
|
||||||
|
default: false
|
||||||
|
example:
|
||||||
|
cheeseId: '1'
|
||||||
|
complete: 'true'
|
||||||
|
id: '1'
|
||||||
|
quantity: '66'
|
||||||
|
shipDate: '04-10-2017 00:09:21 UTC'
|
||||||
|
status: available
|
||||||
|
|
Loading…
Reference in New Issue
Block a user