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}} {{#isBodyParam}}<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
<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}} <div class="param-desc"><span class="param-type">Body Parameter</span> &mdash; {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isBodyParam}}
default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isBodyParam}}

View File

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

View File

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

View File

@ -1,76 +1,61 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"/> <meta charset="utf-8" />
<title>API Reference</title> <title>API Reference</title>
</head> </head>
<body> <body>
<h1>{{{appName}}}</h1> <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-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>
<div class="app-desc">{{{appDescription}}} for {{partner}}</div> <h3 class="field-label">Parameters</h3>
{{#infoUrl}} <div class="field-items">
<div class="app-desc">More information: <a href="{{{infoUrl}}}">{{{infoUrl}}}</a></div>{{/infoUrl}} {{#allParams}}{{>queryParam}}{{>pathParam}}{{>bodyParam}}{{>headerParam}}{{>formParam}}
{{#infoEmail}} {{/allParams}}
<div class="app-desc">Contact Info: <a href="{{{infoEmail}}}">{{{infoEmail}}}</a></div>{{/infoEmail}} </div> <!-- field-items -->
{{#version}} <h3 class="field-label">Return type</h3>
<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> <div class="return-type"><a href="#{{returnContainer}}">{{{returnType}}}</a></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-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> {{#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 -->
<hr>
{{/operation}}{{/operations}}
{{/apis}}{{/apiInfo}}
<div class="field-items"> <h2>Models</h2>
{{#allParams}}{{>queryParam}}{{>pathParam}}{{>bodyParam}}{{>headerParam}}{{>formParam}} {{#models}}
{{/allParams}} {{#model}}
</div> <div class="model">
<!-- field-items --> <h3 class="field-label"><a name="{{classname}}">{{classname}}</a></h3>
<h3 class="field-label">Return type</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>
<div class="return-type"><a href="#{{returnContainer}}">{{{returnType}}}</a></div> {{/vars}}
</div> <!-- field-items -->
{{#examples}} </div>
<h3 class="field-label">Example data</h3> {{/model}}
{{/models}}
<div class="example-data-content-type">Content-Type: {{{contentType}}}</div> <style>
<pre class="example"><code>{{example}}</code></pre> {{>style.css}}
{{/examples}} </style>
</div> </body>
<!-- method -->
<hr>
{{/operation}}{{/operations}}
{{/apis}}{{/apiInfo}}
<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>
<!-- field-items -->
</div>
{{/model}}
{{/models}}
<style>
{{>style.css}}
</style>
</body>
</html> </html>

View File

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

View File

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

View File

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

View File

@ -4,22 +4,22 @@ var url = require('url');
{{#operations}} {{#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}}var {{paramName}} = req.swagger.params['{{baseName}}'].value;
{{/allParams}} {{/allParams}}
var result = {{classname}}.{{nickname}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); var result = {{classname}}.{{nickname}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
if(typeof result !== 'undefined') { if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json'); res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2)); res.end(JSON.stringify(result || {}, null, 2));
} }
else else
res.end(); res.end();
}; };
{{/operation}} {{/operation}}
{{/operations}} {{/operations}}

View File

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

View File

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

View File

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

View File

@ -1,42 +1,42 @@
{ {
"swagger": "2.0", "swagger": "2.0",
"info": { "info": {
"title": "{{appName}}", "title": "{{appName}}",
"description": "{{appDescription}}", "description": "{{appDescription}}",
"version": "{{apiVersion}}" "version": "{{apiVersion}}"
}, },
{{#apiInfo}} {{#apiInfo}}
"produces": ["application/json"], "produces": ["application/json"],
"host": "localhost:{{serverPort}}", "host": "localhost:{{serverPort}}",
"basePath": "{{contextPath}}", "basePath": "{{contextPath}}",
"paths": { "paths": {
{{#apis}} {{#apis}}
{{#operations}} {{#operations}}
{{#operation}} {{#operation}}
"{{{path}}}": { "{{{path}}}": {
"{{httpMethod}}": { "{{httpMethod}}": {
"x-swagger-router-controller": "{{classname}}", "x-swagger-router-controller": "{{classname}}",
"tags": ["{{baseName}}"], "tags": ["{{baseName}}"],
"operationId": "{{operationId}}",{{#hasParams}} "operationId": "{{operationId}}",{{#hasParams}}
"parameters": [ "parameters": [
{{#allParams}} {{#allParams}}
{{{jsonSchema}}}{{#hasMore}},{{/hasMore}} {{{jsonSchema}}}{{#hasMore}},{{/hasMore}}
{{/allParams}} {{/allParams}}
],{{/hasParams}} ],{{/hasParams}}
"responses": { "responses": {
{{#responses}} {{#responses}}
"{{code}}": {{{jsonSchema}}} "{{code}}": {{{jsonSchema}}}
{{#hasMore}},{{/hasMore}} {{#hasMore}},{{/hasMore}}
{{/responses}} {{/responses}}
} }
} }
} {{#hasMore}},{{/hasMore}} } {{#hasMore}},{{/hasMore}}
{{/operation}} {{/operation}}
{{#hasMore}},{{/hasMore}} {{#hasMore}},{{/hasMore}}
{{/operations}} {{/operations}}
{{/apis}} {{/apis}}
{{/apiInfo}} {{/apiInfo}}
}, "definitions": { }, "definitions": {
{{#models}}{{#model}}"{{classVarName}}": {{{modelJson}}}{{#hasMoreModels}},{{/hasMoreModels}}{{/model}}{{/models}} {{#models}}{{#model}}"{{classVarName}}": {{{modelJson}}}{{#hasMoreModels}},{{/hasMoreModels}}{{/model}}{{/models}}
} }
} }