Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@tsed/swagger
Advanced tools
A package of Ts.ED framework. See website: https://romakita.github.io/ts-express-decorators/#/tutorials/swagger
Before using the Swagger, we need to install the swagger-ui-express module.
npm install --save-dev @types/swagger-schema-official
npm install --save swagger-ui-express @tsed/swagger
Then add the following configuration in your ServerLoader:
import {ServerLoader, ServerSettings} from "@tsed/common";
import "@tsed/swagger"; // import swagger Ts.ED module
import Path = require("path");
const rootDir = Path.resolve(__dirname)
@ServerSettings({
rootDir,
swagger: {
path: "/api-docs"
}
})
export class Server extends ServerLoader {
}
The path option for swagger will be used to expose the documentation (ex: http://localhost:8000/api-docs).
Normally, Swagger-ui is ready. You can start your server and check if it work fine.
Note: Ts.ED will print the swagger url in the console.
Some options is available to configure Swagger-ui, Ts.ED and the default spec information.
Key | Example | Description |
---|---|---|
path | /api-doc | The url subpath to access to the documentation. |
cssPath | ${rootDir}/spec/style.css | The path to the CSS file. |
showExplorer | true | Display the search field in the navbar. |
spec | {swagger: "2.0"} | The default information spec. |
specPath | ${rootDir}/spec/swagger.json | The path to the swagger.json. This file will be written at the first server starting if it doesn't exist. The data will me merge with the collected data via annotation. |
One of the feature of Ts.ED is the model definition to serialize or deserialize a JSON Object (see converters section).
This model can used on a method controller along with @BodyParams or other decorators.
import {JsonProperty} from "@tsed/common";
import {Title, Description, Example} from "@tsed/swagger";
export class CalendarModel {
@Title("iD")
@Description("Description of calendar model id")
@Example("example1", "Description example")
@JsonProperty()
public id: string;
@JsonProperty()
public name: string;
}
import {Controller, Get, Post} from "@tsed/common";
import {Summary, Description, Responses,Deprecated, Security} from "@tsed/swagger";
@Controller('/calendars')
export class Calendar {
@Get('/:id')
@Summary("Summary of this route")
@Description("Description of this route")
@Returns("404", {description: "Not found"})
async getCalendar(@QueryParam() id: string): Promise<CalendarModel> {
//...
}
@Get('/v0/:id')
@Deprecated()
@Description("Deprecated route, use /rest/calendars/:id instead of.")
@Returns("404", {description: "Not found"})
getCalendarDeprecated(@QueryParam() id: string): Promise<CalendarModel> {
//...
}
@Post('/')
@Security("calendar_auth", "write:calendar", "read:calendar")
async createCalendar(): Promise<CalendarModel> {
//...
}
}
!> To update the swagger.json you need to reload the server before.
See our documentation https://romakita.github.io/ts-express-decorators/#/api/index
Please read contributing guidelines here.
Thank you to all our backers! 🙏 [Become a backer]
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
The MIT License (MIT)
Copyright (c) 2016 - 2018 Romain Lenzotti
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Swagger package for Ts.ED framework
The npm package @tsed/swagger receives a total of 6,820 weekly downloads. As such, @tsed/swagger popularity was classified as popular.
We found that @tsed/swagger demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.