Release 2.0.6-3
·
11 commits
to main
since this release
New way to register controllers. Using JSDocs comments to do that.
Example:
/**
* @api /auth
* @name Authentication
*/
class AuthController implements Controller {
methods: expressRequestAndResponseType[] = [
/**
* @get /v1/login
* @description Authentication Login
*/
function login(req, res) {
res.send('hello world');
},
/**
* @post /v1/register
* @description Authentication Register
*/
async function register(req, res) {
try {
const newUser = new UserEntity({
name: req.body.name,
username: req.body.username,
email: req.body.email,
password: await bcryptPassword(req.body.password),
});
const savedUser: UserEntity = await newUser.save();
res.status(201).json(userEntityToDto(savedUser));
} catch (err) {
console.error(err);
res.status(500).send("Error");
}
}
];
For register a new Controller use:
/**
* @api /path-you-want
* @name Name of the controller to generate swagger specifications
*/
For register a each api endpoint use:
/**
* @post path/of/endpoint
* @description Description to generate swagger specifications
*/
The api endpoint will use the api path as root + endpoint path
Example: controllerPath/apiPath