swagger-express-ts
Advanced tools
Comparing version 1.0.0-alpha.1 to 1.0.0-alpha.2
@@ -0,1 +1,6 @@ | ||
<a name="1.0.0-alpha.2"></a> | ||
# [1.0.0-alpha.2] (2018-01-18) | ||
Complete informations. | ||
<a name="1.0.0-alpha.1"></a> | ||
@@ -2,0 +7,0 @@ # [1.0.0-alpha.1] (2018-01-18) |
{ | ||
"name": "swagger-express-ts", | ||
"version": "1.0.0-alpha.1", | ||
"version": "1.0.0-alpha.2", | ||
"description": "Generate and serve swagger.json", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -45,3 +45,3 @@ # swagger-express-ts | ||
info : { | ||
title : "Mon api", | ||
title : "My api", | ||
version : "1.0" | ||
@@ -81,22 +81,32 @@ }, | ||
import { injectable } from "inversify"; | ||
import { controller, httpGet, interfaces, httpPost } from "inversify-express-utils"; | ||
import { ApiPath, ApiOperationGet, ApiOperationPost } from "swagger-express-ts"; | ||
import { controller, httpGet, interfaces, httpPost, requestParam, httpPut } from "inversify-express-utils"; | ||
import { ApiPath, ApiOperationGet, ApiOperationPost, ApiOperationPut, SwaggerDefinitionConstant } from "swagger-express-ts"; | ||
import "reflect-metadata"; | ||
@ApiPath( { | ||
path : "/version", | ||
name : "Version", | ||
description : "Everything about version" | ||
path : "/versions", | ||
name : "Version" | ||
} ) | ||
@controller( "/version" ) | ||
@controller( "/versions" ) | ||
@injectable() | ||
export class VersionController implements interfaces.Controller { | ||
public static TARGET_NAME: string = "VersionController"; | ||
private data: [any] = [ | ||
{ | ||
id : "1", | ||
name : "Version 1", | ||
description : "Description Version 1", | ||
version : "1.0.0" | ||
}, | ||
{ | ||
id : "2", | ||
name : "Version 2", | ||
description : "Description Version 2", | ||
version : "2.0.0" | ||
} | ||
]; | ||
@ApiOperationGet( { | ||
responses : { | ||
200 : { | ||
description : "Success", | ||
definition : "Version" | ||
} | ||
200 : { description : "Success", isArray : true, model : "Version" } | ||
} | ||
@@ -106,19 +116,11 @@ } ) | ||
public getVersions( request: express.Request, response: express.Response, next: express.NextFunction ): void { | ||
response.json( { | ||
description : pkg.description, | ||
name : pkg.name, | ||
version : pkg.version, | ||
} ); | ||
response.json( this.data ); | ||
} | ||
@ApiOperationPost( { | ||
parameters : { | ||
body : { | ||
description : "New version", | ||
required : true, | ||
definition: "Version" | ||
} | ||
body : { description : "New version", required : true, model : "Version" } | ||
}, | ||
responses : { | ||
200 : { description : "Success" }, | ||
200 : { description : "Success", model : "Version" }, | ||
400 : { description : "Parameters fail" } | ||
@@ -132,4 +134,27 @@ } | ||
} | ||
this.data.push( request.body ); | ||
response.json( request.body ); | ||
} | ||
@ApiOperationGet( { | ||
path : "/{id}", | ||
parameters : { | ||
path : { | ||
id : { description : "Id of version", type : SwaggerDefinitionConstant.Parameter.Type.STRING, required : true } | ||
} | ||
}, | ||
responses : { | ||
200 : { description : "Success", model : "Version" }, | ||
404 : { description : "Version not exist" } | ||
}, | ||
} ) | ||
@httpGet( "/:id" ) | ||
public getVersion( @requestParam( "id" ) id: string, request: express.Request, response: express.Response, next: express.NextFunction ): void { | ||
this.data.forEach( ( version: any )=> { | ||
if ( version.id === id ) { | ||
return response.json( version ); | ||
} | ||
} ); | ||
response.status( 404 ).end(); | ||
} | ||
} | ||
@@ -136,0 +161,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59726
315