1.0.23 • Published 3 years ago

@anzerr/swagger.ts v1.0.23

Weekly downloads
18
License
MIT
Repository
github
Last release
3 years ago

Intro

GitHub Actions status | linter GitHub Actions status | publish GitHub Actions status | test

Add swagger decorator to build the swagger.json in the controller.

Install

npm install --save git+https://github.com/anzerr/swagger.ts.git
npm install --save @anzerr/swagger.ts

Example

import 'reflect-metadata';
import {Swagger, SwaggerDocument, Meta} from 'swagger.ts';
import {Server, Controller, Get} from 'http.ts';
import {Injectable, Inject, Module} from 'inject.ts';

@Controller('user')
class Test extends Server.Controller {

	@Get()
	list() {
		this.res.status(200).send('1');
	}

	@Put()
	@Meta.responses(200, 'create/update')
	@Meta.responses(400, 'wrong param sent in body')
	@Meta.responses(500, 'something wen\'t wrong')
	@Meta.param.body({
		type: 'object',
		required: ['users'],
		properties: {
			users: {
				type: 'array',
				items: {
					type: 'object',
					properties: {
						name: {type: 'string'},
						password: {type: 'string'}
						code: {type: 'number'}
					}
				}
			}
		}
	})
	create() {
		this.res.status(200).send('3');
	}

}

const document = new SwaggerDocument();

const s = new Server(3000)
	.withController([Swagger, Controller]);

s.start().then(() => {
	Swagger.json = document.withServer(s).toJson();
	return s;
}).catch((err) => {
	console.log(err);
	process.exit(1);
});
1.0.23

3 years ago

1.0.22

4 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.4

6 years ago

1.0.1

6 years ago

1.0.2

6 years ago

1.0.3

6 years ago