@smartive/giuseppe-swagger-plugin
v2.0.0
Published
Swagger documentation generator
Downloads
846
Readme
giuseppe-swagger-plugin
This is a plugin for giuseppe.
A bunch of badges
Installation
To install this package, simply run
How to use
Here is a brief example of how to add the plugin to giuseppe:
import { Giuseppe } from 'giuseppe';
import { GiuseppeSwaggerPlugin } from 'giuseppe-swagger-plugin';
const app = new Giuseppe();
app.registerPlugin(new GiuseppeSwaggerPlugin());
app.start();
This is how to enrich a Giuseppe controller with swagger annotations:
@Controller()
class Ctrl2 {
@SwaggerRoute({
description: 'A route',
responses: {
200: {
description: 'Response description',
type: Model,
},
},
})
@Get('route')
getRoute(
@Query('a')
a: string,
@SwaggerParam({
default: 10,
description: 'Parameter b',
})
@Query('b')
b: number,
@SwaggerParam({
type: Model
})
@Query('c')
c: Model,
@SwaggerParam({
type: Number
})
@Query('d')
d: number[],
@SwaggerParam({
type: Model
})
@Query('e')
e: Model[],
@Header('f')
f: string,
): Model {
return new Model();
}
}
This is how to enrich a model with swagger annotations:
@SwaggerObject({
description: 'A model',
})
class Model {
@SwaggerField({
required: true,
})
a: string;
@SwaggerField()
b: number;
@SwaggerField({
type: Other,
})
c: Model;
@SwaggerField({
type: Number
})
d: number[];
@SwaggerField({
type: Other
})
e: Other[];
}
This is how to generate the swagger json:
import { SwaggerDocs } from 'giuseppe-swagger-plugin';
@Controller()
class Ctrl {
@SwaggerDocs('swagger', {
info: {
description: 'A test swagger route.',
title: 'Swagger',
version: '1.0.0',
},
})
public getSwagger(): void { }
}
The schema can be forced to adhere to swagger 2.
Changelog
The changelog is generated by semantic release and is located under the release section.
Licence
This software is licenced under the MIT licence.