@smartive/giuseppe-swagger-plugin
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

giuseppe-swagger-plugin

This is a plugin for giuseppe.

A bunch of badges

Build Status npm

Installation

To install this package, simply run

NPM

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.

Package Sidebar

Install

npm i @smartive/giuseppe-swagger-plugin

Weekly Downloads

389

Version

2.0.0

License

MIT

Unpacked Size

32.9 kB

Total Files

24

Last publish

Collaborators

  • cbuehler
  • deniaz
  • dwirz
  • mfeltscher
  • nmaro
  • petermanser
  • smartive-ci