Merge branch 'master' into clojure-client

This commit is contained in:
xhh 2015-11-18 17:27:29 +08:00
commit 50c27d258c
27 changed files with 1121 additions and 1269 deletions

View File

@ -1,19 +1,8 @@
package io.swagger.codegen;
import static org.apache.commons.lang3.StringUtils.capitalize;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import io.swagger.models.ComposedModel;
import io.swagger.models.Contact;
import io.swagger.models.Info;
import io.swagger.models.License;
import io.swagger.models.Model;
import io.swagger.models.Operation;
import io.swagger.models.Path;
import io.swagger.models.SecurityRequirement;
import io.swagger.models.Swagger;
import io.swagger.models.*;
import io.swagger.models.auth.OAuth2Definition;
import io.swagger.models.auth.SecuritySchemeDefinition;
import io.swagger.models.parameters.Parameter;
@ -23,14 +12,12 @@ import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.*;
import java.util.*;
import static org.apache.commons.lang3.StringUtils.capitalize;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
public class DefaultGenerator extends AbstractGenerator implements Generator {
Logger LOGGER = LoggerFactory.getLogger(DefaultGenerator.class);
@ -321,6 +308,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
if (swagger.getHost() != null) {
bundle.put("host", swagger.getHost());
}
bundle.put("swagger", this.swagger);
bundle.put("basePath", basePath);
bundle.put("scheme", scheme);
bundle.put("contextPath", contextPath);

View File

@ -5,6 +5,8 @@ import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.CodegenType;
import io.swagger.codegen.DefaultCodegen;
import io.swagger.codegen.SupportingFile;
import io.swagger.codegen.CodegenProperty;
import io.swagger.codegen.CodegenModel;
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.MapProperty;
import io.swagger.models.properties.Property;
@ -14,10 +16,15 @@ import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(CSharpClientCodegen.class);
protected String packageName = "IO.Swagger";
protected String packageVersion = "1.0.0";
protected String clientPackage = "IO.Swagger.Client";
@ -261,4 +268,22 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
public void setPackageVersion(String packageVersion) {
this.packageVersion = packageVersion;
}
@Override
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
List<Object> models = (List<Object>) objs.get("models");
for (Object _mo : models) {
Map<String, Object> mo = (Map<String, Object>) _mo;
CodegenModel cm = (CodegenModel) mo.get("model");
for (CodegenProperty var : cm.vars) {
// check to see if model name is same as the property name
// which will result in compilation error
// if found, prepend with _ to workaround the limitation
if (var.name.equals(cm.name)) {
var.name = "_" + var.name;
}
}
}
return objs;
}
}

View File

@ -1,27 +1,16 @@
package io.swagger.codegen.languages;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.CodegenOperation;
import io.swagger.codegen.CodegenParameter;
import io.swagger.codegen.CodegenResponse;
import io.swagger.codegen.CodegenType;
import io.swagger.codegen.DefaultCodegen;
import io.swagger.codegen.SupportingFile;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import io.swagger.codegen.*;
import io.swagger.models.Swagger;
import io.swagger.util.Yaml;
import java.io.File;
import java.util.*;
import java.util.Map.Entry;
public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig {
protected String apiVersion = "1.0.0";
@ -87,7 +76,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
// );
supportingFiles.add(new SupportingFile("swagger.mustache",
"api",
"swagger.json")
"swagger.yaml")
);
supportingFiles.add(new SupportingFile("index.mustache",
"",
@ -97,6 +86,10 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
"",
"package.json")
);
supportingFiles.add(new SupportingFile("README.mustache",
"",
"README.md")
);
if (System.getProperty("noservice") == null) {
apiTemplateFiles.put(
"service.mustache", // the template to use
@ -242,6 +235,14 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
@Override
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
Swagger swagger = (Swagger)objs.get("swagger");
if(swagger != null) {
try {
objs.put("swagger-yaml", Yaml.mapper().writeValueAsString(swagger));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
for (Map<String, Object> operations : getOperations(objs)) {
@SuppressWarnings("unchecked")
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");

View File

@ -10,7 +10,6 @@ using System.Net;
using System.Text;
using Newtonsoft.Json;
using RestSharp;
using RestSharp.Extensions;
namespace {{packageName}}.Client
{
@ -171,7 +170,7 @@ namespace {{packageName}}.Client
/// <returns>Escaped string.</returns>
public string EscapeString(string str)
{
return RestSharp.Extensions.StringExtensions.UrlEncode(str);
return UrlEncode(str);
}
/// <summary>
@ -183,9 +182,9 @@ namespace {{packageName}}.Client
public FileParameter ParameterToFile(string name, Stream stream)
{
if (stream is FileStream)
return FileParameter.Create(name, stream.ReadAsBytes(), Path.GetFileName(((FileStream)stream).Name));
return FileParameter.Create(name, ReadAsBytes(stream), Path.GetFileName(((FileStream)stream).Name));
else
return FileParameter.Create(name, stream.ReadAsBytes(), "no_file_name_provided");
return FileParameter.Create(name, ReadAsBytes(stream), "no_file_name_provided");
}
/// <summary>
@ -365,6 +364,62 @@ namespace {{packageName}}.Client
public static dynamic ConvertType(dynamic source, Type dest) {
return Convert.ChangeType(source, dest);
}
/// <summary>
/// Convert stream to byte array
/// Credit/Ref: http://stackoverflow.com/a/221941/677735
/// </summary>
/// <param name="input">Input stream to be converted</param>
/// <returns>Byte array</returns>
public static byte[] ReadAsBytes(Stream input)
{
byte[] buffer = new byte[16*1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}
/// <summary>
/// URL encode a string
/// Credit/Ref: https://github.com/restsharp/RestSharp/blob/master/RestSharp/Extensions/StringExtensions.cs#L50
/// </summary>
/// <param name="input">String to be URL encoded</param>
/// <returns>Byte array</returns>
public static string UrlEncode(string input)
{
const int maxLength = 32766;
if (input == null)
{
throw new ArgumentNullException("input");
}
if (input.Length <= maxLength)
{
return Uri.EscapeDataString(input);
}
StringBuilder sb = new StringBuilder(input.Length * 2);
int index = 0;
while (index < input.Length)
{
int length = Math.Min(input.Length - index, maxLength);
string subString = input.Substring(index, length);
sb.Append(Uri.EscapeDataString(subString));
index += subString.Length;
}
return sb.ToString();
}
}
}

View File

@ -9,17 +9,7 @@ var {{classname}} = require('./{{classname}}Service');
{{#operation}}
module.exports.{{nickname}} = function {{nickname}} (req, res, next) {
{{#allParams}}var {{paramName}} = req.swagger.params['{{baseName}}'].value;
{{/allParams}}
var result = {{classname}}.{{nickname}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
{{classname}}.{{nickname}}(req.swagger.params, res, next);
};
{{/operation}}
{{/operations}}

View File

@ -3,7 +3,8 @@
var app = require('connect')();
var http = require('http');
var swaggerTools = require('swagger-tools');
var jsyaml = require('js-yaml');
var fs = require('fs');
var serverPort = {{serverPort}};
// swaggerRouter configuration
@ -14,7 +15,8 @@ var options = {
};
// The Swagger document (require it, build it programmatically, fetch it from a URL, ...)
var swaggerDoc = require('./api/swagger.json');
var spec = fs.readFileSync('./api/swagger.yaml', 'utf8');
var swaggerDoc = jsyaml.safeLoad(spec);
// Initialize the Swagger middleware
swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {

View File

@ -10,6 +10,7 @@
"private": true,
"dependencies": {
"connect": "^3.2.0",
"swagger-tools": "0.8.*"
"js-yaml": "^3.3.0",
"swagger-tools": "0.9.*"
}
}

View File

@ -2,17 +2,27 @@
{{#operations}}
{{#operation}}
exports.{{nickname}} = function({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
exports.{{nickname}} = function(args, res, next) {
/**
* parameters expected in the args:
{{#allParams}}* {{paramName}} ({{dataType}})
{{/allParams}}**/
var examples = {};
var examples = {};
{{#examples}}
examples['{{contentType}}'] = {{{example}}};
{{/examples}}
{{#returnType}}
if(Object.keys(examples).length > 0)
return examples[Object.keys(examples)[0]];
if(Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
}
else {
res.end();
}
{{/returnType}}
{{^returnType}}res.end();{{/returnType}}
}
{{/operation}}
{{/operations}}

View File

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

View File

@ -10,7 +10,6 @@ using System.Net;
using System.Text;
using Newtonsoft.Json;
using RestSharp;
using RestSharp.Extensions;
namespace IO.Swagger.Client
{
@ -171,7 +170,7 @@ namespace IO.Swagger.Client
/// <returns>Escaped string.</returns>
public string EscapeString(string str)
{
return RestSharp.Extensions.StringExtensions.UrlEncode(str);
return UrlEncode(str);
}
/// <summary>
@ -183,9 +182,9 @@ namespace IO.Swagger.Client
public FileParameter ParameterToFile(string name, Stream stream)
{
if (stream is FileStream)
return FileParameter.Create(name, stream.ReadAsBytes(), Path.GetFileName(((FileStream)stream).Name));
return FileParameter.Create(name, ReadAsBytes(stream), Path.GetFileName(((FileStream)stream).Name));
else
return FileParameter.Create(name, stream.ReadAsBytes(), "no_file_name_provided");
return FileParameter.Create(name, ReadAsBytes(stream), "no_file_name_provided");
}
/// <summary>
@ -369,6 +368,62 @@ namespace IO.Swagger.Client
public static dynamic ConvertType(dynamic source, Type dest) {
return Convert.ChangeType(source, dest);
}
/// <summary>
/// Convert stream to byte array
/// Credit/Ref: http://stackoverflow.com/a/221941/677735
/// </summary>
/// <param name="input">Input stream to be converted</param>
/// <returns>Byte array</returns>
public static byte[] ReadAsBytes(Stream input)
{
byte[] buffer = new byte[16*1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}
/// <summary>
/// URL encode a string
/// Credit/Ref: https://github.com/restsharp/RestSharp/blob/master/RestSharp/Extensions/StringExtensions.cs#L50
/// </summary>
/// <param name="input">String to be URL encoded</param>
/// <returns>Byte array</returns>
public static string UrlEncode(string input)
{
const int maxLength = 32766;
if (input == null)
{
throw new ArgumentNullException("input");
}
if (input.Length <= maxLength)
{
return Uri.EscapeDataString(input);
}
StringBuilder sb = new StringBuilder(input.Length * 2);
int index = 0;
while (index < input.Length)
{
int length = Math.Min(input.Length - index, maxLength);
string subString = input.Substring(index, length);
sb.Append(Uri.EscapeDataString(subString));
index += subString.Length;
}
return sb.ToString();
}
}
}

View File

@ -2,7 +2,7 @@
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.Workbench ActiveDocument="TestPet.cs">
<Files>
<File FileName="TestPet.cs" Line="1" Column="1" />
<File FileName="TestPet.cs" Line="11" Column="2" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>

View File

@ -1,8 +1,8 @@
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll

View File

@ -0,0 +1,24 @@
# Swagger generated server
## Overview
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the [swagger-spec](https://github.com/swagger-api/swagger-spec) 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/swagger-api/swagger-codegen/README.md)
### Running the server
To run the server, follow these simple steps:
```
npm install
node .
```
To view the Swagger UI interface:
```
open http://localhost:8080/docs
```
This project leverages the mega-awesome [swagger-tools](https://github.com/apigee-127/swagger-tools) middleware which does most all the work.

View File

@ -1,867 +0,0 @@
{
"swagger": "2.0",
"info": {
"title": "Swagger Petstore",
"description": "This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters",
"version": "1.0.0"
},
"produces": ["application/json"],
"host": "localhost:8080",
"basePath": "/v2",
"paths": {
"/user/createWithList": {
"post": {
"summary": "Creates list of users with given input array",
"description":"",
"x-swagger-router-controller": "User",
"tags": ["User"],
"operationId": "createUsersWithListInput",
"parameters": [
{
"in" : "body",
"name" : "body",
"description" : "List of user object",
"required" : false,
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/User"
}
}
}
],
"responses": {
"default": {
"description" : "successful operation"
}
}
}
} ,
"/user/createWithArray": {
"post": {
"summary": "Creates list of users with given input array",
"description":"",
"x-swagger-router-controller": "User",
"tags": ["User"],
"operationId": "createUsersWithArrayInput",
"parameters": [
{
"in" : "body",
"name" : "body",
"description" : "List of user object",
"required" : false,
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/User"
}
}
}
],
"responses": {
"default": {
"description" : "successful operation"
}
}
}
} ,
"/user/{username}": {
"get": {
"summary": "Get user by user name",
"description":"",
"x-swagger-router-controller": "User",
"tags": ["User"],
"operationId": "getUserByName",
"parameters": [
{
"name" : "username",
"in" : "path",
"description" : "The name that needs to be fetched. Use user1 for testing. ",
"required" : true,
"type" : "string"
}
],
"responses": {
"200": {
"description" : "successful operation",
"schema" : {
"$ref" : "#/definitions/User"
},
"examples" : {
"application/json" : {
"id" : 1,
"username" : "johnp",
"firstName" : "John",
"lastName" : "Public",
"email" : "johnp@swagger.io",
"password" : "-secret-",
"phone" : "0123456789",
"userStatus" : 0
}
}
}
,
"400": {
"description" : "Invalid username supplied"
}
,
"404": {
"description" : "User not found"
}
}
} ,
"put": {
"summary": "Updated user",
"description":"This can only be done by the logged in user.",
"x-swagger-router-controller": "User",
"tags": ["User"],
"operationId": "updateUser",
"parameters": [
{
"name" : "username",
"in" : "path",
"description" : "name that need to be deleted",
"required" : true,
"type" : "string"
},
{
"in" : "body",
"name" : "body",
"description" : "Updated user object",
"required" : false,
"schema" : {
"$ref" : "#/definitions/User"
}
}
],
"responses": {
"400": {
"description" : "Invalid user supplied"
}
,
"404": {
"description" : "User not found"
}
}
} ,
"delete": {
"summary": "Delete user",
"description":"This can only be done by the logged in user.",
"x-swagger-router-controller": "User",
"tags": ["User"],
"operationId": "deleteUser",
"parameters": [
{
"name" : "username",
"in" : "path",
"description" : "The name that needs to be deleted",
"required" : true,
"type" : "string"
}
],
"responses": {
"400": {
"description" : "Invalid username supplied"
}
,
"404": {
"description" : "User not found"
}
}
}
} ,
"/user": {
"post": {
"summary": "Create user",
"description":"This can only be done by the logged in user.",
"x-swagger-router-controller": "User",
"tags": ["User"],
"operationId": "createUser",
"parameters": [
{
"in" : "body",
"name" : "body",
"description" : "Created user object",
"required" : false,
"schema" : {
"$ref" : "#/definitions/User"
}
}
],
"responses": {
"default": {
"description" : "successful operation"
}
}
}
} ,
"/user/logout": {
"get": {
"summary": "Logs out current logged in user session",
"description":"",
"x-swagger-router-controller": "User",
"tags": ["User"],
"operationId": "logoutUser",
"responses": {
"default": {
"description" : "successful operation"
}
}
}
} ,
"/user/login": {
"get": {
"summary": "Logs user into the system",
"description":"",
"x-swagger-router-controller": "User",
"tags": ["User"],
"operationId": "loginUser",
"parameters": [
{
"name" : "username",
"in" : "query",
"description" : "The user name for login",
"required" : false,
"type" : "string"
},
{
"name" : "password",
"in" : "query",
"description" : "The password for login in clear text",
"required" : false,
"type" : "string"
}
],
"responses": {
"200": {
"description" : "successful operation",
"schema" : {
"type" : "string"
}
}
,
"400": {
"description" : "Invalid username/password supplied"
}
}
}
} ,
"/pet": {
"put": {
"summary": "Update an existing pet",
"description":"",
"x-swagger-router-controller": "Pet",
"tags": ["Pet"],
"operationId": "updatePet",
"parameters": [
{
"in" : "body",
"name" : "body",
"description" : "Pet object that needs to be added to the store",
"required" : false,
"schema" : {
"$ref" : "#/definitions/Pet"
}
}
],
"responses": {
"400": {
"description" : "Invalid ID supplied"
}
,
"404": {
"description" : "Pet not found"
}
,
"405": {
"description" : "Validation exception"
}
}
} ,
"post": {
"summary": "Add a new pet to the store",
"description":"",
"x-swagger-router-controller": "Pet",
"tags": ["Pet"],
"operationId": "addPet",
"parameters": [
{
"in" : "body",
"name" : "body",
"description" : "Pet object that needs to be added to the store",
"required" : false,
"schema" : {
"$ref" : "#/definitions/Pet"
}
}
],
"responses": {
"405": {
"description" : "Invalid input"
}
}
}
} ,
"/pet/{petId}/uploadImage": {
"post": {
"summary": "uploads an image",
"description":"",
"x-swagger-router-controller": "Pet",
"tags": ["Pet"],
"operationId": "uploadFile",
"parameters": [
{
"name" : "petId",
"in" : "path",
"description" : "ID of pet to update",
"required" : true,
"type" : "integer",
"format" : "int64"
},
{
"name" : "additionalMetadata",
"in" : "formData",
"description" : "Additional data to pass to server",
"required" : false,
"type" : "string"
},
{
"name" : "file",
"in" : "formData",
"description" : "file to upload",
"required" : false,
"type" : "file"
}
],
"responses": {
"default": {
"description" : "successful operation"
}
}
}
} ,
"/pet/findByStatus": {
"get": {
"summary": "Finds Pets by status",
"description":"Multiple status values can be provided with comma seperated strings",
"x-swagger-router-controller": "Pet",
"tags": ["Pet"],
"operationId": "findPetsByStatus",
"parameters": [
{
"name" : "status",
"in" : "query",
"description" : "Status values that need to be considered for filter",
"required" : false,
"type" : "array",
"collectionFormat" : "multi",
"default" : "available"
}
],
"responses": {
"200": {
"description" : "successful operation",
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/Pet"
}
}
}
,
"400": {
"description" : "Invalid status value"
}
}
}
} ,
"/pet/findByTags": {
"get": {
"summary": "Finds Pets by tags",
"description":"Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
"x-swagger-router-controller": "Pet",
"tags": ["Pet"],
"operationId": "findPetsByTags",
"parameters": [
{
"name" : "tags",
"in" : "query",
"description" : "Tags to filter by",
"required" : false,
"type" : "array",
"collectionFormat" : "multi"
}
],
"responses": {
"200": {
"description" : "successful operation",
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/Pet"
}
}
}
,
"400": {
"description" : "Invalid tag value"
}
}
}
} ,
"/pet/{petId}": {
"get": {
"summary": "Find pet by ID",
"description":"Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions",
"x-swagger-router-controller": "Pet",
"tags": ["Pet"],
"operationId": "getPetById",
"parameters": [
{
"name" : "petId",
"in" : "path",
"description" : "ID of pet that needs to be fetched",
"required" : true,
"type" : "integer",
"format" : "int64"
}
],
"responses": {
"200": {
"description" : "successful operation",
"schema" : {
"$ref" : "#/definitions/Pet"
}
}
,
"400": {
"description" : "Invalid ID supplied"
}
,
"404": {
"description" : "Pet not found"
}
}
} ,
"post": {
"summary": "Updates a pet in the store with form data",
"description":"",
"x-swagger-router-controller": "Pet",
"tags": ["Pet"],
"operationId": "updatePetWithForm",
"parameters": [
{
"name" : "petId",
"in" : "path",
"description" : "ID of pet that needs to be updated",
"required" : true,
"type" : "string"
},
{
"name" : "name",
"in" : "formData",
"description" : "Updated name of the pet",
"required" : false,
"type" : "string"
},
{
"name" : "status",
"in" : "formData",
"description" : "Updated status of the pet",
"required" : false,
"type" : "string"
}
],
"responses": {
"405": {
"description" : "Invalid input"
}
}
} ,
"delete": {
"summary": "Deletes a pet",
"description":"",
"x-swagger-router-controller": "Pet",
"tags": ["Pet"],
"operationId": "deletePet",
"parameters": [
{
"name" : "petId",
"in" : "path",
"description" : "Pet id to delete",
"required" : true,
"type" : "integer",
"format" : "int64"
},
{
"name" : "api_key",
"in" : "header",
"description" : "",
"required" : false,
"type" : "string"
}
],
"responses": {
"400": {
"description" : "Invalid pet value"
}
}
}
} ,
"/store/order/{orderId}": {
"get": {
"summary": "Find purchase order by ID",
"description":"For valid response try integer IDs with value &lt;= 5 or &gt; 10. Other values will generated exceptions",
"x-swagger-router-controller": "Store",
"tags": ["Store"],
"operationId": "getOrderById",
"parameters": [
{
"name" : "orderId",
"in" : "path",
"description" : "ID of pet that needs to be fetched",
"required" : true,
"type" : "string"
}
],
"responses": {
"200": {
"description" : "successful operation",
"schema" : {
"$ref" : "#/definitions/Order"
}
}
,
"400": {
"description" : "Invalid ID supplied"
}
,
"404": {
"description" : "Order not found"
}
}
} ,
"delete": {
"summary": "Delete purchase order by ID",
"description":"For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors",
"x-swagger-router-controller": "Store",
"tags": ["Store"],
"operationId": "deleteOrder",
"parameters": [
{
"name" : "orderId",
"in" : "path",
"description" : "ID of the order that needs to be deleted",
"required" : true,
"type" : "string"
}
],
"responses": {
"400": {
"description" : "Invalid ID supplied"
}
,
"404": {
"description" : "Order not found"
}
}
}
} ,
"/store/order": {
"post": {
"summary": "Place an order for a pet",
"description":"",
"x-swagger-router-controller": "Store",
"tags": ["Store"],
"operationId": "placeOrder",
"parameters": [
{
"in" : "body",
"name" : "body",
"description" : "order placed for purchasing the pet",
"required" : false,
"schema" : {
"$ref" : "#/definitions/Order"
}
}
],
"responses": {
"200": {
"description" : "successful operation",
"schema" : {
"$ref" : "#/definitions/Order"
}
}
,
"400": {
"description" : "Invalid Order"
}
}
}
} ,
"/store/inventory": {
"get": {
"summary": "Returns pet inventories by status",
"description":"Returns a map of status codes to quantities",
"x-swagger-router-controller": "Store",
"tags": ["Store"],
"operationId": "getInventory",
"responses": {
"200": {
"description" : "successful operation",
"schema" : {
"type" : "object",
"additionalProperties" : {
"type" : "integer",
"format" : "int32"
}
}
}
}
}
}
}, "definitions": {
"User": {
"properties" : {
"id" : {
"type" : "integer",
"format" : "int64"
},
"username" : {
"type" : "string"
},
"firstName" : {
"type" : "string"
},
"lastName" : {
"type" : "string"
},
"email" : {
"type" : "string"
},
"password" : {
"type" : "string"
},
"phone" : {
"type" : "string"
},
"userStatus" : {
"type" : "integer",
"format" : "int32",
"description" : "User Status"
}
},
"xml" : {
"name" : "User"
}
},"Category": {
"properties" : {
"id" : {
"type" : "integer",
"format" : "int64"
},
"name" : {
"type" : "string"
}
},
"xml" : {
"name" : "Category"
}
},"Pet": {
"required" : [ "name", "photoUrls" ],
"properties" : {
"id" : {
"type" : "integer",
"format" : "int64"
},
"category" : {
"$ref" : "#/definitions/Category"
},
"name" : {
"type" : "string",
"example" : "doggie"
},
"photoUrls" : {
"type" : "array",
"xml" : {
"name" : "photoUrl",
"wrapped" : true
},
"items" : {
"type" : "string"
}
},
"tags" : {
"type" : "array",
"xml" : {
"name" : "tag",
"wrapped" : true
},
"items" : {
"$ref" : "#/definitions/Tag"
}
},
"status" : {
"type" : "string",
"description" : "pet status in the store",
"enum" : [ "available", "pending", "sold" ]
}
},
"xml" : {
"name" : "Pet"
}
},"Tag": {
"properties" : {
"id" : {
"type" : "integer",
"format" : "int64"
},
"name" : {
"type" : "string"
}
},
"xml" : {
"name" : "Tag"
}
},"Order": {
"properties" : {
"id" : {
"type" : "integer",
"format" : "int64"
},
"petId" : {
"type" : "integer",
"format" : "int64"
},
"quantity" : {
"type" : "integer",
"format" : "int32"
},
"shipDate" : {
"type" : "string",
"format" : "date-time"
},
"status" : {
"type" : "string",
"description" : "Order Status",
"enum" : [ "placed", "approved", "delivered" ]
},
"complete" : {
"type" : "boolean"
}
},
"xml" : {
"name" : "Order"
}
}
}
}

View File

@ -0,0 +1,667 @@
---
swagger: "2.0"
info:
description: "This is a sample server Petstore server. You can find out more about\
\ Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net,\
\ #swagger. For this sample, you can use the api key \"special-key\" to test\
\ the authorization filters"
version: "1.0.0"
title: "Swagger Petstore"
termsOfService: "http://swagger.io/terms/"
contact:
email: "apiteam@swagger.io"
license:
name: "Apache 2.0"
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "petstore.swagger.io"
basePath: "/v2"
schemes:
- "http"
paths:
/pet:
post:
tags:
- "pet"
summary: "Add a new pet to the store"
description: ""
operationId: "addPet"
consumes:
- "application/json"
- "application/xml"
produces:
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "Pet object that needs to be added to the store"
required: false
schema:
$ref: "#/definitions/Pet"
responses:
405:
description: "Invalid input"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
put:
tags:
- "pet"
summary: "Update an existing pet"
description: ""
operationId: "updatePet"
consumes:
- "application/json"
- "application/xml"
produces:
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "Pet object that needs to be added to the store"
required: false
schema:
$ref: "#/definitions/Pet"
responses:
400:
description: "Invalid ID supplied"
404:
description: "Pet not found"
405:
description: "Validation exception"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
/pet/findByStatus:
get:
tags:
- "pet"
summary: "Finds Pets by status"
description: "Multiple status values can be provided with comma seperated strings"
operationId: "findPetsByStatus"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "status"
in: "query"
description: "Status values that need to be considered for filter"
required: false
type: "array"
items:
type: "string"
collectionFormat: "multi"
default: "available"
responses:
200:
description: "successful operation"
schema:
type: "array"
items:
$ref: "#/definitions/Pet"
400:
description: "Invalid status value"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
/pet/findByTags:
get:
tags:
- "pet"
summary: "Finds Pets by tags"
description: "Muliple tags can be provided with comma seperated strings. Use\
\ tag1, tag2, tag3 for testing."
operationId: "findPetsByTags"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "tags"
in: "query"
description: "Tags to filter by"
required: false
type: "array"
items:
type: "string"
collectionFormat: "multi"
responses:
200:
description: "successful operation"
schema:
type: "array"
items:
$ref: "#/definitions/Pet"
400:
description: "Invalid tag value"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
/pet/{petId}:
get:
tags:
- "pet"
summary: "Find pet by ID"
description: "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate\
\ API error conditions"
operationId: "getPetById"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "petId"
in: "path"
description: "ID of pet that needs to be fetched"
required: true
type: "integer"
format: "int64"
responses:
200:
description: "successful operation"
schema:
$ref: "#/definitions/Pet"
400:
description: "Invalid ID supplied"
404:
description: "Pet not found"
security:
- api_key: []
- petstore_auth:
- "write:pets"
- "read:pets"
post:
tags:
- "pet"
summary: "Updates a pet in the store with form data"
description: ""
operationId: "updatePetWithForm"
consumes:
- "application/x-www-form-urlencoded"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "petId"
in: "path"
description: "ID of pet that needs to be updated"
required: true
type: "string"
- name: "name"
in: "formData"
description: "Updated name of the pet"
required: false
type: "string"
- name: "status"
in: "formData"
description: "Updated status of the pet"
required: false
type: "string"
responses:
405:
description: "Invalid input"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
delete:
tags:
- "pet"
summary: "Deletes a pet"
description: ""
operationId: "deletePet"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "api_key"
in: "header"
description: ""
required: false
type: "string"
- name: "petId"
in: "path"
description: "Pet id to delete"
required: true
type: "integer"
format: "int64"
responses:
400:
description: "Invalid pet value"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
/pet/{petId}/uploadImage:
post:
tags:
- "pet"
summary: "uploads an image"
description: ""
operationId: "uploadFile"
consumes:
- "multipart/form-data"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "petId"
in: "path"
description: "ID of pet to update"
required: true
type: "integer"
format: "int64"
- name: "additionalMetadata"
in: "formData"
description: "Additional data to pass to server"
required: false
type: "string"
- name: "file"
in: "formData"
description: "file to upload"
required: false
type: "file"
responses:
default:
description: "successful operation"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
/store/inventory:
get:
tags:
- "store"
summary: "Returns pet inventories by status"
description: "Returns a map of status codes to quantities"
operationId: "getInventory"
produces:
- "application/json"
- "application/xml"
parameters: []
responses:
200:
description: "successful operation"
schema:
type: "object"
additionalProperties:
type: "integer"
format: "int32"
security:
- api_key: []
/store/order:
post:
tags:
- "store"
summary: "Place an order for a pet"
description: ""
operationId: "placeOrder"
produces:
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "order placed for purchasing the pet"
required: false
schema:
$ref: "#/definitions/Order"
responses:
200:
description: "successful operation"
schema:
$ref: "#/definitions/Order"
400:
description: "Invalid Order"
/store/order/{orderId}:
get:
tags:
- "store"
summary: "Find purchase order by ID"
description: "For valid response try integer IDs with value <= 5 or > 10. Other\
\ values will generated exceptions"
operationId: "getOrderById"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "orderId"
in: "path"
description: "ID of pet that needs to be fetched"
required: true
type: "string"
responses:
200:
description: "successful operation"
schema:
$ref: "#/definitions/Order"
400:
description: "Invalid ID supplied"
404:
description: "Order not found"
delete:
tags:
- "store"
summary: "Delete purchase order by ID"
description: "For valid response try integer IDs with value < 1000. Anything\
\ above 1000 or nonintegers will generate API errors"
operationId: "deleteOrder"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "orderId"
in: "path"
description: "ID of the order that needs to be deleted"
required: true
type: "string"
responses:
400:
description: "Invalid ID supplied"
404:
description: "Order not found"
/user:
post:
tags:
- "user"
summary: "Create user"
description: "This can only be done by the logged in user."
operationId: "createUser"
produces:
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "Created user object"
required: false
schema:
$ref: "#/definitions/User"
responses:
default:
description: "successful operation"
/user/createWithArray:
post:
tags:
- "user"
summary: "Creates list of users with given input array"
description: ""
operationId: "createUsersWithArrayInput"
produces:
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "List of user object"
required: false
schema:
type: "array"
items:
$ref: "#/definitions/User"
responses:
default:
description: "successful operation"
/user/createWithList:
post:
tags:
- "user"
summary: "Creates list of users with given input array"
description: ""
operationId: "createUsersWithListInput"
produces:
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "List of user object"
required: false
schema:
type: "array"
items:
$ref: "#/definitions/User"
responses:
default:
description: "successful operation"
/user/login:
get:
tags:
- "user"
summary: "Logs user into the system"
description: ""
operationId: "loginUser"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "username"
in: "query"
description: "The user name for login"
required: false
type: "string"
- name: "password"
in: "query"
description: "The password for login in clear text"
required: false
type: "string"
responses:
200:
description: "successful operation"
schema:
type: "string"
400:
description: "Invalid username/password supplied"
/user/logout:
get:
tags:
- "user"
summary: "Logs out current logged in user session"
description: ""
operationId: "logoutUser"
produces:
- "application/json"
- "application/xml"
parameters: []
responses:
default:
description: "successful operation"
/user/{username}:
get:
tags:
- "user"
summary: "Get user by user name"
description: ""
operationId: "getUserByName"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "username"
in: "path"
description: "The name that needs to be fetched. Use user1 for testing. "
required: true
type: "string"
responses:
200:
description: "successful operation"
schema:
$ref: "#/definitions/User"
examples:
application/json:
id: 1
username: "johnp"
firstName: "John"
lastName: "Public"
email: "johnp@swagger.io"
password: "-secret-"
phone: "0123456789"
userStatus: 0
400:
description: "Invalid username supplied"
404:
description: "User not found"
put:
tags:
- "user"
summary: "Updated user"
description: "This can only be done by the logged in user."
operationId: "updateUser"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "username"
in: "path"
description: "name that need to be deleted"
required: true
type: "string"
- in: "body"
name: "body"
description: "Updated user object"
required: false
schema:
$ref: "#/definitions/User"
responses:
400:
description: "Invalid user supplied"
404:
description: "User not found"
delete:
tags:
- "user"
summary: "Delete user"
description: "This can only be done by the logged in user."
operationId: "deleteUser"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "username"
in: "path"
description: "The name that needs to be deleted"
required: true
type: "string"
responses:
400:
description: "Invalid username supplied"
404:
description: "User not found"
securityDefinitions:
api_key:
type: "apiKey"
name: "api_key"
in: "header"
petstore_auth:
type: "oauth2"
authorizationUrl: "http://petstore.swagger.io/api/oauth/dialog"
flow: "implicit"
scopes:
write:pets: "modify pets in your account"
read:pets: "read your pets"
definitions:
User:
properties:
id:
type: "integer"
format: "int64"
username:
type: "string"
firstName:
type: "string"
lastName:
type: "string"
email:
type: "string"
password:
type: "string"
phone:
type: "string"
userStatus:
type: "integer"
format: "int32"
description: "User Status"
xml:
name: "User"
Category:
properties:
id:
type: "integer"
format: "int64"
name:
type: "string"
xml:
name: "Category"
Pet:
required:
- "name"
- "photoUrls"
properties:
id:
type: "integer"
format: "int64"
category:
$ref: "#/definitions/Category"
name:
type: "string"
example: "doggie"
photoUrls:
type: "array"
xml:
name: "photoUrl"
wrapped: true
items:
type: "string"
tags:
type: "array"
xml:
name: "tag"
wrapped: true
items:
$ref: "#/definitions/Tag"
status:
type: "string"
description: "pet status in the store"
enum:
- "available"
- "pending"
- "sold"
xml:
name: "Pet"
Tag:
properties:
id:
type: "integer"
format: "int64"
name:
type: "string"
xml:
name: "Tag"
Order:
properties:
id:
type: "integer"
format: "int64"
petId:
type: "integer"
format: "int64"
quantity:
type: "integer"
format: "int32"
shipDate:
type: "string"
format: "date-time"
status:
type: "string"
description: "Order Status"
enum:
- "placed"
- "approved"
- "delivered"
complete:
type: "boolean"
xml:
name: "Order"

View File

@ -7,118 +7,33 @@ var Pet = require('./PetService');
module.exports.updatePet = function updatePet (req, res, next) {
var body = req.swagger.params['body'].value;
var result = Pet.updatePet(body);
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
Pet.updatePet(req.swagger.params, res, next);
};
module.exports.addPet = function addPet (req, res, next) {
var body = req.swagger.params['body'].value;
var result = Pet.addPet(body);
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
Pet.addPet(req.swagger.params, res, next);
};
module.exports.findPetsByStatus = function findPetsByStatus (req, res, next) {
var status = req.swagger.params['status'].value;
var result = Pet.findPetsByStatus(status);
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
Pet.findPetsByStatus(req.swagger.params, res, next);
};
module.exports.findPetsByTags = function findPetsByTags (req, res, next) {
var tags = req.swagger.params['tags'].value;
var result = Pet.findPetsByTags(tags);
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
Pet.findPetsByTags(req.swagger.params, res, next);
};
module.exports.getPetById = function getPetById (req, res, next) {
var petId = req.swagger.params['petId'].value;
var result = Pet.getPetById(petId);
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
Pet.getPetById(req.swagger.params, res, next);
};
module.exports.updatePetWithForm = function updatePetWithForm (req, res, next) {
var petId = req.swagger.params['petId'].value;
var name = req.swagger.params['name'].value;
var status = req.swagger.params['status'].value;
var result = Pet.updatePetWithForm(petId, name, status);
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
Pet.updatePetWithForm(req.swagger.params, res, next);
};
module.exports.deletePet = function deletePet (req, res, next) {
var petId = req.swagger.params['petId'].value;
var apiKey = req.swagger.params['api_key'].value;
var result = Pet.deletePet(petId, apiKey);
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
Pet.deletePet(req.swagger.params, res, next);
};
module.exports.uploadFile = function uploadFile (req, res, next) {
var petId = req.swagger.params['petId'].value;
var additionalMetadata = req.swagger.params['additionalMetadata'].value;
var file = req.swagger.params['file'].value;
var result = Pet.uploadFile(petId, additionalMetadata, file);
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
Pet.uploadFile(req.swagger.params, res, next);
};

View File

@ -1,22 +1,36 @@
'use strict';
exports.updatePet = function(body) {
exports.updatePet = function(args, res, next) {
/**
* parameters expected in the args:
* body (Pet)
**/
var examples = {};
var examples = {};
res.end();
}
exports.addPet = function(body) {
exports.addPet = function(args, res, next) {
/**
* parameters expected in the args:
* body (Pet)
**/
var examples = {};
var examples = {};
res.end();
}
exports.findPetsByStatus = function(status) {
exports.findPetsByStatus = function(args, res, next) {
/**
* parameters expected in the args:
* status (List)
**/
var examples = {};
var examples = {};
examples['application/json'] = [ {
"tags" : [ {
@ -35,13 +49,23 @@ exports.findPetsByStatus = function(status) {
if(Object.keys(examples).length > 0)
return examples[Object.keys(examples)[0]];
if(Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
}
else {
res.end();
}
}
exports.findPetsByTags = function(tags) {
exports.findPetsByTags = function(args, res, next) {
/**
* parameters expected in the args:
* tags (List)
**/
var examples = {};
var examples = {};
examples['application/json'] = [ {
"tags" : [ {
@ -60,13 +84,23 @@ exports.findPetsByTags = function(tags) {
if(Object.keys(examples).length > 0)
return examples[Object.keys(examples)[0]];
if(Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
}
else {
res.end();
}
}
exports.getPetById = function(petId) {
exports.getPetById = function(args, res, next) {
/**
* parameters expected in the args:
* petId (Long)
**/
var examples = {};
var examples = {};
examples['application/json'] = {
"tags" : [ {
@ -85,28 +119,54 @@ exports.getPetById = function(petId) {
if(Object.keys(examples).length > 0)
return examples[Object.keys(examples)[0]];
if(Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
}
else {
res.end();
}
}
exports.updatePetWithForm = function(petId, name, status) {
exports.updatePetWithForm = function(args, res, next) {
/**
* parameters expected in the args:
* petId (String)
* name (String)
* status (String)
**/
var examples = {};
var examples = {};
res.end();
}
exports.deletePet = function(petId, apiKey) {
exports.deletePet = function(args, res, next) {
/**
* parameters expected in the args:
* petId (Long)
* apiKey (String)
**/
var examples = {};
var examples = {};
res.end();
}
exports.uploadFile = function(petId, additionalMetadata, file) {
exports.uploadFile = function(args, res, next) {
/**
* parameters expected in the args:
* petId (Long)
* additionalMetadata (String)
* file (file)
**/
var examples = {};
var examples = {};
res.end();
}

View File

@ -7,56 +7,17 @@ var Store = require('./StoreService');
module.exports.getInventory = function getInventory (req, res, next) {
var result = Store.getInventory();
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
Store.getInventory(req.swagger.params, res, next);
};
module.exports.placeOrder = function placeOrder (req, res, next) {
var body = req.swagger.params['body'].value;
var result = Store.placeOrder(body);
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
Store.placeOrder(req.swagger.params, res, next);
};
module.exports.getOrderById = function getOrderById (req, res, next) {
var orderId = req.swagger.params['orderId'].value;
var result = Store.getOrderById(orderId);
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
Store.getOrderById(req.swagger.params, res, next);
};
module.exports.deleteOrder = function deleteOrder (req, res, next) {
var orderId = req.swagger.params['orderId'].value;
var result = Store.deleteOrder(orderId);
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
Store.deleteOrder(req.swagger.params, res, next);
};

View File

@ -1,8 +1,11 @@
'use strict';
exports.getInventory = function() {
exports.getInventory = function(args, res, next) {
/**
* parameters expected in the args:
**/
var examples = {};
var examples = {};
examples['application/json'] = {
"key" : 123
@ -10,13 +13,23 @@ exports.getInventory = function() {
if(Object.keys(examples).length > 0)
return examples[Object.keys(examples)[0]];
if(Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
}
else {
res.end();
}
}
exports.placeOrder = function(body) {
exports.placeOrder = function(args, res, next) {
/**
* parameters expected in the args:
* body (Order)
**/
var examples = {};
var examples = {};
examples['application/json'] = {
"id" : 123456789,
@ -24,18 +37,28 @@ exports.placeOrder = function(body) {
"complete" : true,
"status" : "aeiou",
"quantity" : 123,
"shipDate" : "2015-10-20T06:12:23.907+0000"
"shipDate" : "2015-11-18T02:43:54.540+0000"
};
if(Object.keys(examples).length > 0)
return examples[Object.keys(examples)[0]];
if(Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
}
else {
res.end();
}
}
exports.getOrderById = function(orderId) {
exports.getOrderById = function(args, res, next) {
/**
* parameters expected in the args:
* orderId (String)
**/
var examples = {};
var examples = {};
examples['application/json'] = {
"id" : 123456789,
@ -43,19 +66,30 @@ exports.getOrderById = function(orderId) {
"complete" : true,
"status" : "aeiou",
"quantity" : 123,
"shipDate" : "2015-10-20T06:12:23.911+0000"
"shipDate" : "2015-11-18T02:43:54.544+0000"
};
if(Object.keys(examples).length > 0)
return examples[Object.keys(examples)[0]];
if(Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
}
else {
res.end();
}
}
exports.deleteOrder = function(orderId) {
exports.deleteOrder = function(args, res, next) {
/**
* parameters expected in the args:
* orderId (String)
**/
var examples = {};
var examples = {};
res.end();
}

View File

@ -7,114 +7,33 @@ var User = require('./UserService');
module.exports.createUser = function createUser (req, res, next) {
var body = req.swagger.params['body'].value;
var result = User.createUser(body);
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
User.createUser(req.swagger.params, res, next);
};
module.exports.createUsersWithArrayInput = function createUsersWithArrayInput (req, res, next) {
var body = req.swagger.params['body'].value;
var result = User.createUsersWithArrayInput(body);
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
User.createUsersWithArrayInput(req.swagger.params, res, next);
};
module.exports.createUsersWithListInput = function createUsersWithListInput (req, res, next) {
var body = req.swagger.params['body'].value;
var result = User.createUsersWithListInput(body);
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
User.createUsersWithListInput(req.swagger.params, res, next);
};
module.exports.loginUser = function loginUser (req, res, next) {
var username = req.swagger.params['username'].value;
var password = req.swagger.params['password'].value;
var result = User.loginUser(username, password);
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
User.loginUser(req.swagger.params, res, next);
};
module.exports.logoutUser = function logoutUser (req, res, next) {
var result = User.logoutUser();
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
User.logoutUser(req.swagger.params, res, next);
};
module.exports.getUserByName = function getUserByName (req, res, next) {
var username = req.swagger.params['username'].value;
var result = User.getUserByName(username);
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
User.getUserByName(req.swagger.params, res, next);
};
module.exports.updateUser = function updateUser (req, res, next) {
var username = req.swagger.params['username'].value;
var body = req.swagger.params['body'].value;
var result = User.updateUser(username, body);
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
User.updateUser(req.swagger.params, res, next);
};
module.exports.deleteUser = function deleteUser (req, res, next) {
var username = req.swagger.params['username'].value;
var result = User.deleteUser(username);
if(typeof result !== 'undefined') {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result || {}, null, 2));
}
else
res.end();
User.deleteUser(req.swagger.params, res, next);
};

View File

@ -1,48 +1,82 @@
'use strict';
exports.createUser = function(body) {
exports.createUser = function(args, res, next) {
/**
* parameters expected in the args:
* body (User)
**/
var examples = {};
var examples = {};
res.end();
}
exports.createUsersWithArrayInput = function(body) {
exports.createUsersWithArrayInput = function(args, res, next) {
/**
* parameters expected in the args:
* body (List)
**/
var examples = {};
var examples = {};
res.end();
}
exports.createUsersWithListInput = function(body) {
exports.createUsersWithListInput = function(args, res, next) {
/**
* parameters expected in the args:
* body (List)
**/
var examples = {};
var examples = {};
res.end();
}
exports.loginUser = function(username, password) {
exports.loginUser = function(args, res, next) {
/**
* parameters expected in the args:
* username (String)
* password (String)
**/
var examples = {};
var examples = {};
examples['application/json'] = "aeiou";
if(Object.keys(examples).length > 0)
return examples[Object.keys(examples)[0]];
if(Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
}
else {
res.end();
}
}
exports.logoutUser = function() {
exports.logoutUser = function(args, res, next) {
/**
* parameters expected in the args:
**/
var examples = {};
var examples = {};
res.end();
}
exports.getUserByName = function(username) {
exports.getUserByName = function(args, res, next) {
/**
* parameters expected in the args:
* username (String)
**/
var examples = {};
var examples = {};
examples['application/json'] = {
"id" : 1,
@ -57,21 +91,38 @@ exports.getUserByName = function(username) {
if(Object.keys(examples).length > 0)
return examples[Object.keys(examples)[0]];
if(Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
}
else {
res.end();
}
}
exports.updateUser = function(username, body) {
exports.updateUser = function(args, res, next) {
/**
* parameters expected in the args:
* username (String)
* body (User)
**/
var examples = {};
var examples = {};
res.end();
}
exports.deleteUser = function(username) {
exports.deleteUser = function(args, res, next) {
/**
* parameters expected in the args:
* username (String)
**/
var examples = {};
var examples = {};
res.end();
}

View File

@ -3,7 +3,8 @@
var app = require('connect')();
var http = require('http');
var swaggerTools = require('swagger-tools');
var jsyaml = require('js-yaml');
var fs = require('fs');
var serverPort = 8080;
// swaggerRouter configuration
@ -14,7 +15,8 @@ var options = {
};
// The Swagger document (require it, build it programmatically, fetch it from a URL, ...)
var swaggerDoc = require('./api/swagger.json');
var spec = fs.readFileSync('./api/swagger.yaml', 'utf8');
var swaggerDoc = jsyaml.safeLoad(spec);
// Initialize the Swagger middleware
swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {

View File

@ -10,6 +10,7 @@
"private": true,
"dependencies": {
"connect": "^3.2.0",
"swagger-tools": "0.8.*"
"js-yaml": "^3.3.0",
"swagger-tools": "0.9.*"
}
}