mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-02 21:50:55 +00:00
added files
This commit is contained in:
parent
3c2845aaa6
commit
178d7d19c4
10
src/main/resources/nodejs/README.mustache
Normal file
10
src/main/resources/nodejs/README.mustache
Normal file
@ -0,0 +1,10 @@
|
||||
# Swagger generated server
|
||||
|
||||
## Overview
|
||||
This server was generated by the [swagger-codegen](https://github.com/wordnik/swagger-codegen) project. By using the
|
||||
[swagger-spec](https://github.com/wordnik/swagger-core/wiki) from a remote server, you can easily generate a server stub. This
|
||||
is an example of building a node.js server.
|
||||
|
||||
This example uses the [expressjs](http://expressjs.com/) framework. To see how to make this your own, look here:
|
||||
|
||||
[README](https://github.com/wordnik/swagger-codegen/tree/master/samples/server-generator/node)
|
52
src/main/resources/nodejs/api.mustache
Normal file
52
src/main/resources/nodejs/api.mustache
Normal file
@ -0,0 +1,52 @@
|
||||
var swagger = require("swagger-node-express");
|
||||
var url = require("url");
|
||||
var errors = swagger.errors;
|
||||
var params = swagger.params;
|
||||
|
||||
/* add model includes */
|
||||
|
||||
function writeResponse (response, data) {
|
||||
response.header('Access-Control-Allow-Origin', "*");
|
||||
response.header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
response.header("Access-Control-Allow-Headers", "Content-Type");
|
||||
response.header("Content-Type", "application/json; charset=utf-8");
|
||||
response.send(JSON.stringify(data));
|
||||
}
|
||||
|
||||
exports.models = models = require("../models.js");
|
||||
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
exports.{{nickname}} = {
|
||||
'spec': {
|
||||
"description" : "Operations about pets",
|
||||
"path" : "{{path}}",
|
||||
"notes" : "{{{notes}}}",
|
||||
"summary" : "{{{summary}}}",
|
||||
"method": "{{httpMethod}}",
|
||||
"params" : [{{#queryParams}}
|
||||
params.query("{{paramName}}", "{{description}}", "{{swaggerDataType}}", {{#required}}true{{/required}}{{^required}}false{{/required}}, {{#allowMultiple}}true{{/allowMultiple}}{{^allowMultiple}}false{{/allowMultiple}}, "{{{allowableValues}}}"{{#defaultValue}}, {{{defaultValue}}}{{/defaultValue}}){{#hasMore}},{{/hasMore}}
|
||||
{{/queryParams}}].concat([{{#pathParams}}
|
||||
params.path("{{paramName}}", "{{description}}"){{#hasMore}},{{/hasMore}}
|
||||
{{/pathParams}}]).concat([{{#headerParams}}
|
||||
params.header("{{paramName}}", "{{description}}"){{#hasMore}},{{/hasMore}}
|
||||
{{/headerParams}}]).concat([{{#bodyParams}}
|
||||
params.body("body", "{{swaggerDataType}}", "{{description}}", {{#required}}{{required}}{{/required}}{{^required}}false{{/required}})
|
||||
{{/bodyParams}}]),
|
||||
"type" : "{{returnType}}",
|
||||
"responseMessages" : [errors.invalid('id'), errors.notFound('{{returnType}}')],
|
||||
"nickname" : "{{nickname}}"
|
||||
},
|
||||
'action': function (req,res) {
|
||||
{{#requiredParamCount}}
|
||||
{{#requiredParams}}
|
||||
if (!req.params.{{baseName}}) {
|
||||
throw errors.invalid('{{baseName}}');
|
||||
}
|
||||
{{/requiredParams}}
|
||||
{{/requiredParamCount}}
|
||||
writeResponse(res, {message: "how about implementing {{nickname}} as a {{httpMethod}} method?"});
|
||||
}
|
||||
};
|
||||
{{/operation}}
|
||||
{{/operations}}
|
47
src/main/resources/nodejs/main.mustache
Normal file
47
src/main/resources/nodejs/main.mustache
Normal file
@ -0,0 +1,47 @@
|
||||
var express = require("express")
|
||||
, url = require("url")
|
||||
, cors = require("cors")
|
||||
, swagger = require("swagger-node-express")
|
||||
, db = false
|
||||
|
||||
var app = express();
|
||||
app.use(express.bodyParser());
|
||||
|
||||
var corsOptions = {
|
||||
credentials: true,
|
||||
origin: function(origin,callback) {
|
||||
if(origin===undefined) {
|
||||
callback(null,false);
|
||||
} else {
|
||||
callback(null,true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
app.use(cors(corsOptions));
|
||||
|
||||
swagger.setAppHandler(app);
|
||||
swagger.configureSwaggerPaths("", "api-docs", "")
|
||||
|
||||
var models = require("./models.js");
|
||||
|
||||
{{#apiInfo}}
|
||||
{{#apis}}
|
||||
var {{classname}} = require("./{{apiFolder}}/{{classname}}.js");
|
||||
{{/apis}}
|
||||
{{/apiInfo}}
|
||||
|
||||
swagger.addModels(models)
|
||||
{{#apiInfo}}
|
||||
{{#apis}}
|
||||
{{#operations}}
|
||||
{{#operation}}.add{{httpMethod}}({{classname}}.{{nickname}}){{newline}}{{/operation}}
|
||||
{{/operations}}
|
||||
{{/apis}};
|
||||
{{/apiInfo}}
|
||||
|
||||
// configures the app
|
||||
swagger.configure("http://localhost:8002", "0.1");
|
||||
|
||||
// start the server
|
||||
app.listen(8002);
|
3
src/main/resources/nodejs/models.mustache
Normal file
3
src/main/resources/nodejs/models.mustache
Normal file
@ -0,0 +1,3 @@
|
||||
exports.models = {
|
||||
{{#models}}{{#model}}"{{classVarName}}": {{{modelJson}}}{{#hasMoreModels}},{{/hasMoreModels}}{{/model}}{{/models}}
|
||||
}
|
16
src/main/resources/nodejs/package.mustache
Executable file
16
src/main/resources/nodejs/package.mustache
Executable file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "{{{artifactId}}}",
|
||||
"description": "Wordnik node.js server generator",
|
||||
"version": "{{{artifactVersion}}}",
|
||||
"homepage": "{{{homepage}}}",
|
||||
"main": "./{{codeDir}}/main.js",
|
||||
"engines": {
|
||||
"node": ">= 0.8.x"
|
||||
},
|
||||
"dependencies": {
|
||||
"swagger-node-express": ">= 2.0.x",
|
||||
"connect": ">= 1.8.x",
|
||||
"cors": "2.1.1",
|
||||
"express": "3.x"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user