forked from loafle/openapi-generator-original
		
	
		
			
				
	
	
		
			51 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| var swagger = require("swagger-node-express");
 | |
| var url = require("url");
 | |
| var errors = swagger.errors;
 | |
| 
 | |
| /* 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}}
 | |
|       swagger.queryParam("{{paramName}}", "{{description}}", "{{swaggerDataType}}", {{required}}, {{allowMultiple}}, "{{{allowableValues}}}"{{#defaultValue}}, {{{defaultValue}}}{{/defaultValue}}){{#hasMore}},{{/hasMore}}
 | |
|     {{/queryParams}}].concat([{{#pathParams}}
 | |
|       swagger.pathParam("{{paramName}}", "{{description}}"){{#hasMore}},{{/hasMore}}
 | |
|     {{/pathParams}}]).concat([{{#headerParams}}
 | |
|       swagger.header("{{paramName}}", "{{description}}"){{#hasMore}},{{/hasMore}}
 | |
|     {{/headerParams}}]).concat([{{#bodyParams}}
 | |
|       swagger.postParam("{{swaggerDataType}}", "{{description}}", {{required}})
 | |
|     {{/bodyParams}}]),
 | |
|     "responseClass" : "{{returnType}}",
 | |
|     "errorResponses" : [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}} |