rollback nodejs and htmldocs template

This commit is contained in:
wing328 2015-06-09 12:51:52 +08:00
parent eee8685847
commit eede02a6ab
12 changed files with 226 additions and 251 deletions

View File

@ -1,5 +1,3 @@
{{#isBodyParam}}
<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
{{#isBodyParam}}<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
<div class="param-desc"><span class="param-type">Body Parameter</span> &mdash; {{description}} {{#defaultValue}}
default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isBodyParam}}
<div class="param-desc"><span class="param-type">Body Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isBodyParam}}

View File

@ -1,5 +1,3 @@
{{#isFormParam}}
<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
{{#isFormParam}}<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
<div class="param-desc"><span class="param-type">Form Parameter</span> &mdash; {{description}} {{#defaultValue}}
default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isFormParam}}
<div class="param-desc"><span class="param-type">Form Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isFormParam}}

View File

@ -1,5 +1,3 @@
{{#isHeaderParam}}
<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
{{#isHeaderParam}}<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
<div class="param-desc"><span class="param-type">Header Parameter</span> &mdash; {{description}} {{#defaultValue}}
default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isHeaderParam}}
<div class="param-desc"><span class="param-type">Header Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isHeaderParam}}

View File

@ -1,76 +1,61 @@
<html lang="en">
<head>
<meta charset="utf-8"/>
<head>
<meta charset="utf-8" />
<title>API Reference</title>
</head>
<body>
<h1>{{{appName}}}</h1>
<div class="app-desc">{{{appDescription}}} for {{partner}}</div>
{{#infoUrl}}
<div class="app-desc">More information: <a href="{{{infoUrl}}}">{{{infoUrl}}}</a></div>{{/infoUrl}}
{{#infoEmail}}
<div class="app-desc">Contact Info: <a href="{{{infoEmail}}}">{{{infoEmail}}}</a></div>{{/infoEmail}}
{{#version}}
<div class="app-desc">Version: {{{version}}}</div>{{/version}}
<div class="license-info">{{{licenseInfo}}}</div>
<div class="license-url">{{{licenseUrl}}}</div>
<h2>Access</h2>
<div class="method-summary">Customize this message as you see fit!</div>
<h2>Methods</h2>
{{#apiInfo}}
</head>
<body>
<h1>{{{appName}}}</h1>
<div class="app-desc">{{{appDescription}}} for {{partner}}</div>
{{#infoUrl}}<div class="app-desc">More information: <a href="{{{infoUrl}}}">{{{infoUrl}}}</a></div>{{/infoUrl}}
{{#infoEmail}}<div class="app-desc">Contact Info: <a href="{{{infoEmail}}}">{{{infoEmail}}}</a></div>{{/infoEmail}}
{{#version}}<div class="app-desc">Version: {{{version}}}</div>{{/version}}
<div class="license-info">{{{licenseInfo}}}</div>
<div class="license-url">{{{licenseUrl}}}</div>
<h2>Access</h2>
<div class="method-summary">Customize this message as you see fit!</div>
<h2>Methods</h2>
{{#apiInfo}}
{{#apis}}
{{#operations}}{{#operation}}
<div class="method">
<div class="method-path">
<pre class="{{httpMethod}}"><code class="huge"><span>{{httpMethod}}</span>: {{path}}</code></pre>
</div>
<div class="method-path"><pre class="{{httpMethod}}"><code class="huge"><span>{{httpMethod}}</span>: {{path}}</code></pre></div>
<div class="method-tags"> {{#tags}}<span class="method-tag">{{this}}</span>{{/tags}}</div>
<div class="method-summary"><span class="nickname">{{nickname}}</span> {{summary}}</div>
<div class="method-notes">{{notes}}</div>
<h3 class="field-label">Parameters</h3>
<div class="field-items">
{{#allParams}}{{>queryParam}}{{>pathParam}}{{>bodyParam}}{{>headerParam}}{{>formParam}}
{{/allParams}}
</div>
<!-- field-items -->
</div> <!-- field-items -->
<h3 class="field-label">Return type</h3>
<div class="return-type"><a href="#{{returnContainer}}">{{{returnType}}}</a></div>
{{#examples}}
<h3 class="field-label">Example data</h3>
<div class="example-data-content-type">Content-Type: {{{contentType}}}</div>
<pre class="example"><code>{{example}}</code></pre>
{{/examples}}
</div>
<!-- method -->
</div> <!-- method -->
<hr>
{{/operation}}{{/operations}}
{{/apis}}{{/apiInfo}}
<h2>Models</h2>
{{#models}}
<h2>Models</h2>
{{#models}}
{{#model}}
<div class="model">
<h3 class="field-label"><a name="{{classname}}">{{classname}}</a></h3>
<div class="field-items">
{{#vars}}
<div class="param">{{name}} {{#isNotRequired}}(optional){{/isNotRequired}}</div>
<div class="param-desc"><span class="param-type">{{datatype}}</span> {{description}}</div>
{{#vars}}<div class="param">{{name}} {{#isNotRequired}}(optional){{/isNotRequired}}</div><div class="param-desc"><span class="param-type">{{datatype}}</span> {{description}}</div>
{{/vars}}
</div>
<!-- field-items -->
</div> <!-- field-items -->
</div>
{{/model}}
{{/models}}
<style>
{{>style.css}}
</style>
</body>
{{/models}}
<style>
{{>style.css}}
</style>
</body>
</html>

View File

@ -1,5 +1,3 @@
{{#isPathParam}}
<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
{{#isPathParam}}<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
<div class="param-desc"><span class="param-type">Path Parameter</span> &mdash; {{description}} {{#defaultValue}}
default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isPathParam}}
<div class="param-desc"><span class="param-type">Path Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isPathParam}}

View File

@ -1,5 +1,3 @@
{{#isQueryParam}}
<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
{{#isQueryParam}}<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
<div class="param-desc"><span class="param-type">Query Parameter</span> &mdash; {{description}} {{#defaultValue}}
default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isQueryParam}}
<div class="param-desc"><span class="param-type">Query Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isQueryParam}}

View File

@ -1,151 +1,151 @@
body {
font-family: Trebuchet MS, sans-serif;
font-size: 15px;
color: #444;
margin-right: 24px;
font-family: Trebuchet MS, sans-serif;
font-size: 15px;
color: #444;
margin-right: 24px;
}
h1 {
font-size: 25px;
font-size: 25px;
}
h2 {
font-size: 20px;
font-size: 20px;
}
h3 {
font-size: 16px;
font-weight: bold;
font-size: 16px;
font-weight: bold;
}
hr {
height: 1px;
border: 0;
color: #ddd;
background-color: #ddd;
display: none;
height: 1px;
border: 0;
color: #ddd;
background-color: #ddd;
display: none;
}
.app-desc {
clear: both;
margin-left: 20px;
clear: both;
margin-left: 20px;
}
.param-name {
width: 100%;
width: 100%;
}
.license-info {
margin-left: 20px;
margin-left: 20px;
}
.license-url {
margin-left: 20px;
margin-left: 20px;
}
.model {
margin: 0 0 0px 20px;
margin: 0 0 0px 20px;
}
.method {
margin-left: 20px;
margin-left: 20px;
}
.method-notes {
margin: 10px 0 20px 0;
font-size: 90%;
color: #555;
margin: 10px 0 20px 0;
font-size: 90%;
color: #555;
}
pre {
padding: 10px;
margin-bottom: 2px;
padding: 10px;
margin-bottom: 2px;
}
pre.get {
background-color: #0f6ab4;
background-color: #0f6ab4;
}
pre.post {
background-color: #10a54a;
background-color: #10a54a;
}
pre.put {
background-color: #c5862b;
background-color: #c5862b;
}
pre.delete {
background-color: #a41e22;
background-color: #a41e22;
}
.huge {
color: #fff;
color: #fff;
}
pre.example {
background-color: #f3f3f3;
padding: 10px;
border: 1px solid #ddd;
background-color: #f3f3f3;
padding: 10px;
border: 1px solid #ddd;
}
code {
white-space: pre;
white-space: pre;
}
.nickname {
font-weight: bold;
font-weight: bold;
}
.method-path {
font-size: 1.5em;
background-color: #0f6ab4;
font-size: 1.5em;
background-color: #0f6ab4;
}
.parameter {
width: 500px;
width: 500px;
}
.param {
width: 500px;
padding: 10px 0 0 20px;
font-weight: bold;
width: 500px;
padding: 10px 0 0 20px;
font-weight: bold;
}
.param-desc {
width: 700px;
padding: 0 0 0 20px;
color: #777;
width: 700px;
padding: 0 0 0 20px;
color: #777;
}
.param-type {
font-style: italic;
font-style: italic;
}
.field-label {
padding: 0;
margin: 0;
clear: both;
padding: 0;
margin: 0;
clear: both;
}
.field-items {
padding: 0 0 15px 0;
margin-bottom: 15px;
padding: 0 0 15px 0;
margin-bottom: 15px;
}
.return-type {
clear: both;
padding-bottom: 10px;
clear: both;
padding-bottom: 10px;
}
.param-header {
font-weight: bold;
font-weight: bold;
}
.method-tags {
text-align: right;
text-align: right;
}
.method-tag {
background: none repeat scroll 0% 0% #24A600;
border-radius: 3px;
padding: 2px 10px;
margin: 2px;
color: #FFF;
display: inline-block;
text-decoration: none;
background: none repeat scroll 0% 0% #24A600;
border-radius: 3px;
padding: 2px 10px;
margin: 2px;
color: #FFF;
display: inline-block;
text-decoration: none;
}

View File

@ -4,11 +4,11 @@ var url = require('url');
{{#operations}}
var {{classname}} = require('./{{classname}}Service');
var {{classname}} = require('./{{classname}}Service');
{{#operation}}
{{#operation}}
module.exports.{{nickname}} = function {{nickname}} (req, res, next) {
module.exports.{{nickname}} = function {{nickname}} (req, res, next) {
{{#allParams}}var {{paramName}} = req.swagger.params['{{baseName}}'].value;
{{/allParams}}
@ -20,6 +20,6 @@ var url = require('url');
}
else
res.end();
};
{{/operation}}
};
{{/operation}}
{{/operations}}

View File

@ -8,9 +8,9 @@ var serverPort = {{serverPort}};
// swaggerRouter configuration
var options = {
swaggerUi: '/swagger.json',
controllers: './controllers',
useStubs: process.env.NODE_ENV === 'development' ? true : false // Conditionally turn on stubs (mock mode)
swaggerUi: '/swagger.json',
controllers: './controllers',
useStubs: process.env.NODE_ENV === 'development' ? true : false // Conditionally turn on stubs (mock mode)
};
// The Swagger document (require it, build it programmatically, fetch it from a URL, ...)
@ -18,21 +18,21 @@ var swaggerDoc = require('./api/swagger.json');
// Initialize the Swagger middleware
swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {
// Interpret Swagger resources and attach metadata to request - must be first in swagger-tools middleware chain
app.use(middleware.swaggerMetadata());
// Interpret Swagger resources and attach metadata to request - must be first in swagger-tools middleware chain
app.use(middleware.swaggerMetadata());
// Validate Swagger requests
app.use(middleware.swaggerValidator());
// Validate Swagger requests
app.use(middleware.swaggerValidator());
// Route validated requests to appropriate controller
app.use(middleware.swaggerRouter(options));
// Route validated requests to appropriate controller
app.use(middleware.swaggerRouter(options));
// Serve the Swagger documents and Swagger UI
app.use(middleware.swaggerUi());
// Serve the Swagger documents and Swagger UI
app.use(middleware.swaggerUi());
// Start the server
http.createServer(app).listen({{serverPort}}, function () {
console.log('Your server is listening on port %d (http://localhost:%d)', {{serverPort}}, {{serverPort}});
console.log('Swagger-ui is available on http://localhost:%d/docs', {{serverPort}});
});
// Start the server
http.createServer(app).listen({{serverPort}}, function () {
console.log('Your server is listening on port %d (http://localhost:%d)', {{serverPort}}, {{serverPort}});
console.log('Swagger-ui is available on http://localhost:%d/docs', {{serverPort}});
});
});

View File

@ -1,15 +1,15 @@
{
"name": "{{projectName}}",
"version": "{{appVersion}}",
"description": "{{appDescription}}",
"main": "index.js",
"keywords": [
"swagger"
],
"license": "MIT",
"private": true,
"dependencies": {
"connect": "^3.2.0",
"swagger-tools": "0.8.*"
}
"name": "{{projectName}}",
"version": "{{appVersion}}",
"description": "{{appDescription}}",
"main": "index.js",
"keywords": [
"swagger"
],
"license": "MIT",
"private": true,
"dependencies": {
"connect": "^3.2.0",
"swagger-tools": "0.8.*"
}
}

View File

@ -1,8 +1,8 @@
'use strict';
{{#operations}}
{{#operation}}
exports.{{nickname}} = function({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
{{#operation}}
exports.{{nickname}} = function({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
var examples = {};
{{#examples}}
@ -13,6 +13,6 @@
if(Object.keys(examples).length > 0)
return examples[Object.keys(examples)[0]];
{{/returnType}}
}
{{/operation}}
}
{{/operation}}
{{/operations}}

View File

@ -1,17 +1,17 @@
{
"swagger": "2.0",
"info": {
"title": "{{appName}}",
"description": "{{appDescription}}",
"version": "{{apiVersion}}"
},
"swagger": "2.0",
"info": {
"title": "{{appName}}",
"description": "{{appDescription}}",
"version": "{{apiVersion}}"
},
{{#apiInfo}}
"produces": ["application/json"],
"host": "localhost:{{serverPort}}",
"basePath": "{{contextPath}}",
"paths": {
{{#apis}}
{{#operations}}
{{#apis}}
{{#operations}}
{{#operation}}
"{{{path}}}": {
"{{httpMethod}}": {
@ -33,10 +33,10 @@
} {{#hasMore}},{{/hasMore}}
{{/operation}}
{{#hasMore}},{{/hasMore}}
{{/operations}}
{{/apis}}
{{/operations}}
{{/apis}}
{{/apiInfo}}
}, "definitions": {
{{#models}}{{#model}}"{{classVarName}}": {{{modelJson}}}{{#hasMoreModels}},{{/hasMoreModels}}{{/model}}{{/models}}
}
}, "definitions": {
{{#models}}{{#model}}"{{classVarName}}": {{{modelJson}}}{{#hasMoreModels}},{{/hasMoreModels}}{{/model}}{{/models}}
}
}