├── .gitignore ├── LICENSE ├── README.md ├── assets ├── plugin.css └── plugin.js ├── index.js ├── less ├── theme.less └── variables.less ├── package.json ├── partials ├── base │ ├── body.hbs │ ├── footer.hbs │ ├── header.hbs │ ├── html-head.hbs │ ├── javascript-libs.hbs │ └── title.hbs └── swagger │ ├── definitions.hbs │ ├── list-of-labels.hbs │ ├── model.hbs │ ├── operation.hbs │ ├── parameterDefinitions.hbs │ ├── parameterRow.hbs │ ├── parameters.hbs │ ├── path.hbs │ ├── paths.hbs │ ├── request-body.hbs │ ├── response.hbs │ ├── responseDefinitions.hbs │ ├── responseHeaderRow.hbs │ ├── responses.hbs │ ├── security.hbs │ ├── securityDefinitions.hbs │ ├── summary.hbs │ └── tags.hbs └── template.html /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2016 Jeremy Wilken 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Gitbook Swagger Plugin 2 | 3 | This plugin will render out a Swagger definition file into a page. 4 | 5 | ### How to use 6 | 7 | First you'll need to add to your **book.json**. 8 | 9 | { 10 | "plugins": ["swagger"] 11 | } 12 | 13 | Then you'll need to add the following snippet into a book page, and it will replace it with the rendered version. 14 | 15 | swagger.json 16 | 17 | The file between the tags can be either a local file or a url. It must resolve to a swagger JSON file. 18 | 19 | # To Do 20 | 21 | * [ ] Get stylings to work better by default 22 | * [ ] Polish some of the layouts 23 | * [ ] Add UI collapsing and niceness 24 | * [ ] Determine if can/should support 'Try it now' features 25 | * [ ] Add test suites 26 | 27 | # License 28 | 29 | MIT. See [License](./LICENSE) -------------------------------------------------------------------------------- /assets/plugin.css: -------------------------------------------------------------------------------- 1 | .swagger > ul { 2 | list-style: none; 3 | padding-left: 0; 4 | } 5 | .swagger > ul > li { 6 | list-style: none; 7 | background: #f8f8f8; 8 | border: 1px solid #eeeeee; 9 | list-style: none; 10 | padding: 20px; 11 | margin: 20px 0; 12 | box-shadow: 0px 0px 2px rgba(0,0,0,.2); 13 | } 14 | .swagger > ul > li.even { 15 | background: #fcfcfc; 16 | } 17 | .swagger > ul > li > h3, .swagger > ul > li > h4 { 18 | margin: 0; 19 | cursor: pointer; 20 | } 21 | .swagger > ul > li.collapse { 22 | height: 120px; 23 | overflow: hidden; 24 | } 25 | .swagger > ul > li .path { 26 | margin-bottom: 20px; 27 | } 28 | .swagger > ul > li .method { 29 | padding: 4px; 30 | border-radius: 3px; 31 | color: #ffffff; 32 | margin-right: 10px; 33 | } 34 | .swagger > ul > li .method.get { 35 | background: #3a9c68; 36 | } 37 | .swagger > ul > li .method.post { 38 | background: #4397a7; 39 | } 40 | .swagger > ul > li .method.put { 41 | background: #a74374; 42 | } 43 | .swagger > ul > li .method.patch { 44 | background: #5043a7; 45 | } 46 | .swagger > ul > li .method.delete { 47 | background: #ab3333; 48 | } -------------------------------------------------------------------------------- /assets/plugin.js: -------------------------------------------------------------------------------- 1 | require(['gitbook', 'jquery'], function(gitbook, $) { 2 | var items = $('.swagger > ul > li'); 3 | items.addClass('collapse'); 4 | items.find('h3').on('click', function(event) { 5 | $(event.target).parent().toggleClass('collapse'); 6 | }); 7 | }); -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | const path = require('path'); 5 | const bootprint = require('bootprint'); 6 | const crypto = require('crypto'); 7 | const swaggers = {}; 8 | 9 | module.exports = { 10 | book: { 11 | assets: './assets', 12 | js: [ 13 | 'plugin.js' 14 | ], 15 | css: [ 16 | 'plugin.css' 17 | ] 18 | }, 19 | hooks: { 20 | page: function(page) { 21 | // Need to replace the content after it was rendered 22 | let regex = /\(.*?)\<\/swagger\>/gmi; 23 | let definition = regex.exec(page.content); 24 | 25 | // Replace if tag is found 26 | if (definition !== null) { 27 | page.content = page.content.replace(regex, swaggers[definition[1]]); 28 | } 29 | return page; 30 | }, 31 | 'page:before': function(page) { 32 | // Determine if the page contains a swagger file 33 | let regex = /\(.*?)\<\/swagger\>/gmi; 34 | let definition = regex.exec(page.content); 35 | 36 | // If so, build using bootprint and hold in swagger variable for later 37 | if (definition !== null) { 38 | let temp = '_tmp_' + crypto.createHash('md5').update(definition[1]).digest('hex'); 39 | // Load bootprint 40 | return new Promise( 41 | function(resolve, reject) { 42 | bootprint 43 | .load(require('bootprint-swagger')) 44 | .merge({ 45 | less: { 46 | main: [ 47 | require.resolve('./less/theme.less') 48 | ] 49 | }, 50 | handlebars: { 51 | partials: path.join(__dirname, 'partials') 52 | } 53 | }) 54 | // Define the build into the temp directory (doesn't support render as a string) 55 | .build(definition[1], temp) 56 | // Generate the build 57 | .generate() 58 | // On completion, read the output back into memory and save it for later 59 | .done(function() { 60 | let file = fs.readFileSync(temp + '/index.html', 'utf8') 61 | let search = /]*>((.|[\n\r])*)<\/body>/gmi; 62 | let content = search.exec(file); 63 | swaggers[definition[1]] = content[1]; 64 | var exec = require('child_process').exec; 65 | exec('rm -r ' + temp); 66 | resolve(page); 67 | }); 68 | }).then(function(page) { 69 | return page; 70 | }); 71 | } else { 72 | return page; 73 | } 74 | } 75 | } 76 | }; 77 | -------------------------------------------------------------------------------- /less/theme.less: -------------------------------------------------------------------------------- 1 | @container-lg: 900px; 2 | @container-sm: 800px; 3 | 4 | .table.swagger--summary>tbody>tr>td { 5 | &.swagger--summary-path { 6 | vertical-align: middle; 7 | } 8 | 9 | p { 10 | margin: 0; 11 | } 12 | } 13 | 14 | // Draw a panel in a given color 15 | .swagger--panel-operation(@color) { 16 | .panel-variant(darken(@color,30%), @panel-default-text, @color, darken(@color, 30%)); 17 | 18 | .operation-name { 19 | font-weight: bold; 20 | } 21 | .operation-summary { 22 | .pull-right 23 | } 24 | } 25 | 26 | // Panels 27 | .swagger--panel-operation-post { 28 | .swagger--panel-operation(#e7f6ec); 29 | } 30 | 31 | .swagger--panel { 32 | &-operation-get { 33 | .swagger--panel-operation(#e7f0f7); 34 | } 35 | 36 | &-operation-put { 37 | .swagger--panel-operation(#f9f2e9); 38 | } 39 | 40 | &-operation-patch { 41 | .swagger--panel-operation(#FCE9E3); 42 | } 43 | 44 | &-operation-options { 45 | .swagger--panel-operation(#e7f0f7); 46 | } 47 | 48 | &-operation-delete { 49 | .swagger--panel-operation(#f5e8e8); 50 | } 51 | 52 | &-operation-head { 53 | .swagger--panel-operation(#fcffcd); 54 | } 55 | } 56 | 57 | .sw-operation-description { 58 | .named-section(@msg-sw-section-operation-description); 59 | } 60 | 61 | .sw-request-params { 62 | .named-section(@msg-sw-section-request-params); 63 | } 64 | 65 | .sw-request-body { 66 | .named-section(@msg-sw-section-request-body); 67 | } 68 | 69 | .sw-responses { 70 | .named-section(@msg-sw-section-responses); 71 | } 72 | 73 | .table-header(@label,@width: auto) { 74 | width: auto; 75 | &:before { 76 | content: @label; 77 | } 78 | } 79 | 80 | 81 | .swagger--global { 82 | .named-label(@msg-sw-badge-global); 83 | } 84 | 85 | 86 | // Tables 87 | table.table { 88 | 89 | th.sw-param-key { 90 | .table-header(@msg-sw-param-key, 10%); 91 | } 92 | th.sw-param-name { 93 | .table-header(@msg-sw-param-name, 10%); 94 | } 95 | th.sw-param-description { 96 | .table-header(@msg-sw-param-description); 97 | } 98 | th.sw-param-data-type { 99 | .table-header(@msg-sw-param-data-type, 30%); 100 | } 101 | th.sw-param-type { 102 | .table-header(@msg-sw-param-type, 10%); 103 | } 104 | 105 | th.sw-request-security-schema { 106 | .table-header(@msg-sw-request-security-schema, 50%); 107 | } 108 | th.sw-request-security-scopes { 109 | .table-header(@msg-sw-request-security-scopes, 50%); 110 | } 111 | 112 | th.sw-response-header-name { 113 | .table-header(@msg-sw-response-header-name) 114 | } 115 | 116 | th.sw-response-header-description { 117 | .table-header(@msg-sw-response-header-description) 118 | } 119 | 120 | th.sw-response-header-data-type { 121 | .table-header(@msg-sw-response-header-data-type) 122 | } 123 | 124 | 125 | 126 | } 127 | 128 | .sw-response-name-value { 129 | font-weight: bold; 130 | } 131 | 132 | .sw-param-collection-format { 133 | } 134 | 135 | 136 | .sw-response-description-text { 137 | padding-bottom: 0.5em; 138 | } 139 | 140 | 141 | code.highlight { 142 | padding: 0 143 | } 144 | 145 | .panel-security-definition { 146 | .panel-variant(@security-definition-panel-border-color, @security-definition-panel-header-text-color, @security-definition-panel-header-bg-color, @security-definition-panel-border-color); 147 | } 148 | 149 | .sw-request-security { 150 | .named-section(@msg-sw-section-request-security); 151 | } 152 | 153 | .sw-security-definition-basic { 154 | &:before { 155 | color: @gray; 156 | font-size: smaller; 157 | content: @msg-sw-security-definition-type-basic; 158 | } 159 | } 160 | 161 | span.sw-default-value-header { 162 | font-weight: bold; 163 | } 164 | 165 | .sw-info { 166 | font-weight: bold; 167 | span { 168 | font-family: monospace; 169 | font-weight: normal; 170 | font-size: 1.1em; 171 | } 172 | } -------------------------------------------------------------------------------- /less/variables.less: -------------------------------------------------------------------------------- 1 | 2 | @msg-sw-data-type: "Data type"; 3 | @msg-sw-description: "Description"; 4 | 5 | @msg-sw-section-operation-description: @msg-sw-description; 6 | @msg-sw-section-request-params: "Request parameters"; 7 | @msg-sw-section-request-body: "Request body"; 8 | @msg-sw-section-responses: "Responses"; 9 | 10 | @msg-sw-param-key: "Key"; 11 | @msg-sw-param-name: "Name"; 12 | @msg-sw-param-description: @msg-sw-description; 13 | @msg-sw-param-data-type: "Data type"; 14 | @msg-sw-param-type: "Type"; 15 | 16 | 17 | @msg-sw-response-header-name: "Header"; 18 | @msg-sw-response-header-description: @msg-sw-description; 19 | @msg-sw-response-header-data-type: "Data type"; 20 | 21 | 22 | @security-definition-panel-header-bg-color: @gray-lighter; 23 | @security-definition-panel-header-text-color: contrast(@security-definition-panel-header-bg-color); 24 | @security-definition-panel-border-color: darken(@security-definition-panel-header-bg-color, 30%); 25 | @security-definition-panel-inner-border-color: @security-definition-panel-border-color; 26 | 27 | @msg-sw-section-request-security: "Security"; 28 | @msg-sw-request-security-scopes: "Scopes"; 29 | @msg-sw-request-security-schema: "Schema"; 30 | @msg-sw-security-definition-type-basic: "(HTTP Basic Authentication)"; 31 | @msg-sw-badge-global: 'global'; 32 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gitbook-plugin-swagger", 3 | "version": "0.2.0", 4 | "description": "A plugin to consume Swagger files into a Gitbook", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/gnomeontherun/gitbook-plugin-swagger.git" 9 | }, 10 | "keywords": [ 11 | "gitbook", 12 | "plugin" 13 | ], 14 | "author": "Jeremy Wilken ", 15 | "license": "MIT", 16 | "bugs": { 17 | "url": "https://github.com/gnomeontherun/gitbook-plugin-swagger/issues" 18 | }, 19 | "homepage": "https://github.com/gnomeontherun/gitbook-plugin-swagger#readme", 20 | "engines": { 21 | "gitbook": ">=3" 22 | }, 23 | "gitbook": { 24 | "properties": { 25 | "file": { 26 | "type": "string", 27 | "default": "", 28 | "description": "Relative path to snippets file to use." 29 | } 30 | } 31 | }, 32 | "dependencies": { 33 | "bootprint": "^1.0.0", 34 | "bootprint-swagger": "^1.0.1" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /partials/base/body.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | This partial renders the of the HTML page. 3 | @api public 4 | 5 | --}} 6 |
7 |

{{info.title}}

8 |

{{#if basePath}}Base URL: {{basePath}}, {{/if}}Version: {{info.version}}

9 |

{{md info.description}}

10 | 11 | {{#if consumes}} 12 |
13 | Default request content-types: 14 | {{#each consumes}}{{.}}{{#unless @last}}, {{/unless}}{{/each}} 15 |
16 | {{/if}} 17 | {{#if produces}} 18 |
19 | Default response content-types: 20 | {{#each produces}}{{.}}{{#unless @last}}, {{/unless}}{{/each}} 21 |
22 | {{/if}} 23 | 24 |
25 | Schemes: 26 | {{#each schemes}}{{.}}{{#unless @last}}, {{/unless}}{{/each}} 27 |
28 | 29 | {{#if showTagSummary}} 30 | {{>swagger/tags}} 31 | {{else}} 32 | {{>swagger/summary}} 33 | {{/if}} 34 | 35 | {{>swagger/securityDefinitions}} 36 | 37 | {{>swagger/paths paths=paths}} 38 | 39 | {{>swagger/parameterDefinitions parameters=parameters}} 40 | 41 | {{>swagger/responseDefinitions responses=responses}} 42 | 43 | {{>swagger/definitions definitions=definitions}} 44 | 45 |
-------------------------------------------------------------------------------- /partials/base/footer.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | This partial is displayed at the bottom of the HTML-body. 3 | It is empty and can be overridden to include custom content in 4 | the Bootprint-result. 5 | 6 | @param {object} $context$ the whole input data 7 | @public 8 | --}} -------------------------------------------------------------------------------- /partials/base/header.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | This partial is displayed at the top of the HTML-body. 3 | It is empty and can be overridden to include custom content in 4 | the Bootprint-result. 5 | 6 | @param {object} $context$ the whole input data 7 | @public 8 | --}} -------------------------------------------------------------------------------- /partials/base/html-head.hbs: -------------------------------------------------------------------------------- 1 | {{! 2 | This partial is rendered into the ``-tag of the page. It can be overridden 3 | to replace its contents. 4 | }} 5 | 6 | -------------------------------------------------------------------------------- /partials/base/javascript-libs.hbs: -------------------------------------------------------------------------------- 1 | {{! 2 | This partial is rendered below the `footer`-partial of the page. It includes the 3 | javascript-bundle generated by `customize-engine-uglify`. If you don't want to 4 | include the javascript-bundle, because you do not require the bootstrap-javascript, 5 | you can override this partial with an empty one. 6 | }} 7 | 8 | -------------------------------------------------------------------------------- /partials/base/title.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | Renders the page title 3 | @param {object} $context$ the whole swagger definition 4 | @api public 5 | --}} 6 | {{info.title}} -------------------------------------------------------------------------------- /partials/swagger/definitions.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | Renders the definition-section of the HTML-page. 3 | @param {Definition[]} definitions a list of JSON-subschemas. 4 | @api public 5 | --}} 6 | 7 | {{#if definitions}} 8 |

Schema definitions

9 | 10 | {{#eachSorted definitions}} 11 | {{>swagger/model model=. title=@key anchor="/definitions" }} 12 | {{/eachSorted}} 13 | {{/if}} 14 | -------------------------------------------------------------------------------- /partials/swagger/list-of-labels.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | Renders an array of strings as list of labels 3 | @param {string[]} values 4 | --}} 5 | {{#each values}}{{.}} {{/each}} 6 | -------------------------------------------------------------------------------- /partials/swagger/model.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | Renders a json-schema model within swagger (calls json-schema-partials). 3 | @param {JsonSchema} model a JSON-schema definition 4 | @param {string} title the name of the definition 5 | @api public 6 | --}} 7 | 8 | {{! "title" is usually past as parameter, call the json-schema partials if necessary}} 9 | {{#if model}} 10 | {{>json-schema/main-panel model title=title anchor=anchor}} 11 | {{/if}} -------------------------------------------------------------------------------- /partials/swagger/operation.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | This partial renders a box containing information about a single operation of the service 3 | (such as calling a POST on the "/pets" resource). 4 | @param {Operation} operation a Swagger-Operation object. 5 | @param {string} method the http-method (GET, POST, DELETE, PUT, PATCH) 6 | @api public 7 | --}} 8 |
9 |
10 |
{{md summary stripParagraph="true"}}
11 |

{{toUpperCase method}} {{path}}

12 | {{#if tags}} 13 | Tags: 14 | {{#each tags}} 15 | {{.}}{{#unless @last}}, {{/unless}} 16 | {{/each}} 17 | {{/if}} 18 |
19 |
20 |
21 | {{md operation.description}} 22 |
23 | {{! The _request_body variable is filled with the parameter `body` by the preprocessor. }} 24 | {{#if _show_requst_body_section}} 25 | {{>swagger/request-body consumes=operation.consumes body=_request_body}} 26 | {{/if}} 27 | {{>swagger/parameters parameters=parameters}} 28 | {{>swagger/responses}} 29 | {{>swagger/security}} 30 |
31 |
-------------------------------------------------------------------------------- /partials/swagger/parameterDefinitions.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | Global parameter definitions (see https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#parametersDefinitionsObject) 3 | @param {object} parameters the parameter-definitions object 4 | @api public 5 | --}} 6 | {{#if parameters}} 7 |

Parameter definitions

8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | {{#each parameters}} 21 | {{> swagger/parameterRow key=@key parameter=.}} 22 | {{/each}} 23 | 24 |
KeyNameDescriptionTypeData TypeAnnotation
25 | {{/if}} 26 | -------------------------------------------------------------------------------- /partials/swagger/parameterRow.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | Display a single parameter in a table row. 3 | @param {Parameter} parameter a parameter object 4 | @param {string=} key a reference key (if present, this is display in an additional 5 | column in front of the other columns 6 | @param {string=} $ref the reference path of the parameter, in case it is a reference to a default parameter 7 | @api public 8 | --}} 9 | 10 | {{#if key}} 11 | {{key}} 12 | {{/if}} 13 | 14 | {{parameter.name}} 15 | {{md parameter.description}} 16 | {{parameter.in}} 17 | 18 | {{~>json-schema/datatype parameter ~}} 19 | {{~#if parameter.collectionFormat ~}} 20 | , 21 | {{md (swagger--collection-format parameter.collectionFormat parameter.name) stripParagraph=true}} 22 | 23 | {{~/if}} 24 | 25 | 26 | {{#if parameter.required}} 27 | 28 | {{/if}} 29 | {{#if $ref}} 30 | {{$ref}} 31 | {{/if}} 32 | 33 | 34 | -------------------------------------------------------------------------------- /partials/swagger/parameters.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | Renders the parameter table within a operation definition. 3 | @param {Array|Object} parameters a list of Swagger-Parameter objects 4 | If this is an object, an it is expected to be the global parameter list 5 | https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#parametersDefinitionsObject 6 | and the key of each entry is display in a column in front of the other columns. 7 | @api public 8 | --}} 9 | 10 | {{#if parameters}} 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | {{#each parameters}} 24 | {{#if $ref}} 25 | {{> swagger/parameterRow parameter=(json-schema--resolve-ref $ref) $ref=$ref}} 26 | {{else}} 27 | {{> swagger/parameterRow parameter=.}} 28 | {{/if}} 29 | {{/each}} 30 | 31 |
NameDescriptionTypeData TypeAnnotation
32 |
33 | {{/if}} -------------------------------------------------------------------------------- /partials/swagger/path.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | Renders a single path definition with all its methods (GET, POST). 3 | @param {string} path the request path 4 | @param {object} pathItems a swagger [path-item-object](http://swagger.io/specification/#pathItemObject) 5 | @api public 6 | --}} 7 | 8 | 9 | {{#eachSorted pathItems}} 10 | {{>swagger/operation . operation=. method=@key path=../path}} 11 | {{/eachSorted}} 12 | -------------------------------------------------------------------------------- /partials/swagger/paths.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | Renders the paths-section of the Rest-Service definition 3 | @params {Path[]} paths a list of Swagger Path-Objects 4 | @api public 5 | --}} 6 |

Paths

7 | 8 | {{#eachSorted paths}} 9 | {{>swagger/path pathItems=. path=@key}} 10 | {{/eachSorted}} 11 | -------------------------------------------------------------------------------- /partials/swagger/request-body.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | Renders the request-body section of an operation. 3 | @param {string[]} consumes a list of request content type eligible for this operation. 4 | @param {Parameter} body the Parameter-Object of the `body`-parameter 5 | @api public 6 | --}} 7 | 8 |
9 | {{json $root}} 10 | {{#if consumes}} 11 |

{{>swagger/list-of-labels values=consumes}}

12 | {{else if @root.consumes}} 13 |

Uses default content-types: 14 | {{>swagger/list-of-labels values=@root.consumes}} 15 |

16 | {{/if}} 17 | {{#if body}} 18 | {{#with body}} 19 |
20 |
21 |

{{md description}}

22 |
23 |
{{>swagger/model model=schema}}
24 |
25 | {{/with}} 26 | {{/if}} 27 |
-------------------------------------------------------------------------------- /partials/swagger/response.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | Renders details about a single response 3 | @param {Response} response a swagger response-object 4 | --}} 5 | {{! If global is set, attach an id to the table row }} 6 |
7 |
8 | {{md response.description}} 9 |
10 |
11 |
12 | {{#each response.examples}} 13 |
14 |
Example for {{@key}}
15 | {{json .}} 16 |
17 | {{/each}} 18 | 19 |
{{>swagger/model model=response.schema}}
20 | 21 | {{#if response.headers}} 22 |
23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | {{#each response.headers}} 34 | {{#if $ref}} 35 | {{> swagger/responseHeaderRow header=(json-schema--resolve-ref $ref) name=@key}} 36 | {{else}} 37 | {{> swagger/responseHeaderRow header=. name=@key}} 38 | {{/if}} 39 | {{/each}} 40 | 41 |
NameDescriptionData Type
42 |
43 |
44 | {{/if}} 45 |
-------------------------------------------------------------------------------- /partials/swagger/responseDefinitions.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | Renders the response definitions 3 | --}} 4 | {{#if responses}} 5 |

Response definitions

6 | 7 |
8 | {{#each responses}} 9 |
{{@key}}
10 |
11 | {{> swagger/response response=.}} 12 |
13 | {{/each}} 14 |
15 | {{/if}} 16 | -------------------------------------------------------------------------------- /partials/swagger/responseHeaderRow.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | Display a single parameter in a table row. 3 | @param {Header} header a (Header)[https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#headerObject] object 4 | @param {string} name the name of the response header 5 | @api public 6 | --}} 7 | 8 | 9 | {{name}} 10 | {{md header.description}} 11 | 12 | {{>json-schema/datatype header}} 13 | {{#if header.items}} 14 | ,{{>json-schema/datatype header.items}} 15 | {{/if}} 16 | {{#if header.collectionFormat}} 17 |
{{md (swagger--collection-format header.collectionFormat)}}
18 | {{/if}} 19 | 20 | 21 | -------------------------------------------------------------------------------- /partials/swagger/responses.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | Renders the responses section of an operation 3 | @param {Response[]} responses a list of Swagger-Response definitions 4 | @param {string[]} produces a list of response content types produced by the operation 5 | @api public 6 | --}} 7 | 8 | {{#if responses}} 9 |
10 | {{#if produces}} 11 |

{{>swagger/list-of-labels values=produces}}

12 | {{else if @root.produces}} 13 |

Uses default content-types: 14 | {{>swagger/list-of-labels values=@root.produces}} 15 |

16 | {{/if}} 17 | 18 |
19 | {{#each responses}} 20 |
21 | {{! Use response-code and http-name as text}} 22 | {{@key}} {{swagger--response-code @key}} 23 | {{#if $ref}} 24 | {{$ref}} 25 | {{/if}} 26 | 27 |
28 |
29 | {{#if $ref}} 30 | {{>swagger/response response=(json-schema--resolve-ref $ref)}} 31 | {{else}} 32 | {{>swagger/response response=.}} 33 | {{/if}} 34 |
35 | {{/each}} 36 |
37 |
38 | {{/if}} -------------------------------------------------------------------------------- /partials/swagger/security.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | Renders the security definitions of the Rest-service. 3 | @param {Security[]} security TODO 4 | @api public 5 | --}} 6 | {{#if security}} 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | {{#each security}} 17 | {{#each this}} 18 | 19 | 20 | 25 | 26 | {{/each}} 27 | {{/each}} 28 | 29 |
SchemaScopes
{{@key}} 21 | {{#each this}} 22 | {{#unless @first}}, {{/unless}}{{this}} 23 | {{/each}} 24 |
30 |
31 | {{/if}} 32 | -------------------------------------------------------------------------------- /partials/swagger/securityDefinitions.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | Renders the security-section of the HTML-page 3 | TODO: Parameters 4 | @api public 5 | --}} 6 | 7 | {{#if securityDefinitions}} 8 |

Security

9 | 10 | {{#each securityDefinitions}} 11 |
12 |
13 |

{{@key}}

14 | Type: {{type}} 15 |
16 |
17 |
18 |
19 | {{#ifeq type 'apiKey'}} 20 | {{#if name}} 21 |
Name:
22 |
23 |
24 |

{{name}}

25 |
26 |
27 | {{/if}} 28 | {{#if in}} 29 |
In:
30 |
31 |
32 |

{{in}}

33 |
34 |
35 | {{/if}} 36 | {{/ifeq}} 37 | {{#ifeq type 'oauth2'}} 38 | {{#if flow}} 39 |
Flow:
40 |
41 |
42 |

{{flow}}

43 |
44 |
45 | {{/if}} 46 | {{#if authorizationUrl}} 47 |
AuthorizationUrl:
48 |
49 |
50 |

{{authorizationUrl}}

51 |
52 |
53 | {{/if}} 54 | {{#if tokenUrl}} 55 |
TokenUrl:
56 |
57 |
58 |

{{tokenUrl}}

59 |
60 |
61 | {{/if}} 62 | {{#if scopes}} 63 |
Scopes:
64 | {{#each scopes}} 65 |
66 |
67 |
{{@key}}: {{this}}
68 |
69 |
70 | {{/each}} 71 |

72 | {{/if}} 73 | {{/ifeq}} 74 | {{#if description}} 75 |

Description:
76 |
77 |
78 |

{{md description}}

79 |
80 |
81 | {{/if}} 82 |
83 |
84 |
85 |
86 | {{/each}} 87 | {{/if}} 88 | -------------------------------------------------------------------------------- /partials/swagger/summary.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | Renders a summary of this services ignoring tags, containing references to all operations and paths 3 | @todo params 4 | @api public 5 | --}} 6 |

Summary

7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | {{#eachSorted paths}} 17 | {{#eachSorted .}} 18 | 19 | {{#if @first}} 20 | 23 | {{/if}} 24 | 27 | 30 | 31 | {{/eachSorted}} 32 | {{/eachSorted}} 33 | 34 |
PathOperationDescription
21 | {{@../key}} 22 | 25 | {{toUpperCase @key}} 26 | 28 | {{md summary}} 29 |
35 | -------------------------------------------------------------------------------- /partials/swagger/tags.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | Renders a summary based on the tags of this services, containing references to all operations and paths 3 | @param {Array<{name:string, summary:string, operations: object}>} tags a list of tags 4 | @api public 5 | --}} 6 | 7 |

Summary

8 | {{#eachSorted tags}} 9 |

Tag: {{name}}

10 | {{md description}} 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | {{#each operations}} 21 | 22 | 23 | 24 | 25 | {{/each}} 26 | 27 |
OperationDescription
{{toUpperCase method}} {{path}}{{md summary}}
28 | {{/eachSorted}} 29 | 30 | -------------------------------------------------------------------------------- /template.html: -------------------------------------------------------------------------------- 1 |
2 |

<%= api.info.title %>

3 |
<%= api.info.description %>
4 | 5 |
    6 | <% 7 | var row = 'even'; 8 | for (var path in api.paths) { 9 | var methods = api.paths[path]; 10 | for (var method in methods) { 11 | var endpoint = methods[method]; 12 | row = (row == 'even') ? 'odd' : 'even'; 13 | %> 14 |
  • 15 |

    <%= endpoint.summary %>

    16 |

    <%= method.toUpperCase() %><%= path %>

    17 |

    <%= endpoint.description %>

    18 | <% if (endpoint.consumes && endpoint.consumes.legnth) { %> 19 |

    Accepts: <%= endpoint.consumes.join(', ')%> | Produces: <%= endpoint.produces.join(', ') %>

    20 | <% } %> 21 | 22 |
    Parameters
    23 | <% if (endpoint.parameters.length) { %> 24 |
      25 | <% 26 | for (var i = 0; i < endpoint.parameters.length; i++) { 27 | var parameter = endpoint.parameters[i]; 28 | %> 29 |
    • <%= parameter.name %>
    • 30 | <% } %> 31 |
    32 | <% } else { %> 33 |

    There are no parameters

    34 | <% } %> 35 | 36 |
    Responses
    37 | <% if (endpoint.responses.length) { %> 38 |
      39 | <% 40 | for (var code in endpoint.responses) { 41 | var response = endpoint.responses[code]; 42 | %> 43 |
    • 44 |

      <%= code %> <%= response.description %>

      45 |
    • 46 | <% } %> 47 |
    48 | <% } else { %> 49 |

    There are no responses

    50 | <% } %> 51 |
  • 52 | <% } %> 53 | <% } %> 54 |
55 |
56 | --------------------------------------------------------------------------------