@anzerr/swagger.ts
TypeScript icon, indicating that this package has built-in type declarations

1.0.23 • Public • Published

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);
});

Package Sidebar

Install

npm i @anzerr/swagger.ts

Weekly Downloads

32

Version

1.0.23

License

MIT

Unpacked Size

18.3 MB

Total Files

49

Last publish

Collaborators

  • anzerr