
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Super charged router for Koa
Koa-swapi is a user-friendly Koa middleware, design your koa router with koa-swapi like Hapijs, koa-swapi will validate each request components, and generate OpenAPI documant (fka Swagger RESTful API Documentation Specification).
npm i koa-swapi --save
Build Schema
const Joi = require('joi')
const { Route, Validator } = require('koa-swapi')
const catSchemas = [
Route
.get('/cat/:id')
.tags(['catt', 'aninaml'])
.summary('获得一只帅气猫')
.description('想获得一只帅气猫的时候可以调用这个接口')
.validate(
Validator
.params({
id: Joi.string().required().min(2).max(4).description('猫的id')
})
.query({
name: Joi.string().required().min(3).max(100).description('猫的名字'),
sex: Joi.any().required().valid(['0', '1']).description('猫的性别, 0:男, 1:女')
})
.output({
200: {
body: Joi.string()
}
})
)
.create('getCat')
]
Build Controller
const controller = module.exports = {}
controller.getCat = async (ctx) => {
ctx.status = 200;
ctx.body = 'miaomiaomiao'
}
Build Api
const { Api } = require('koa-swapi')
const apis = [
Api.schemas(catSchemas).handler(catController)
]
Register
// app.js
const Koa = require('koa')
const { Swapi } = require('koa-swapi')
const app = new Koa()
const swapi = new Swapi()
swapi.register(app, {
basePath: '/api',
// swagger: {...}: SwaggerSetting
apis: apis,
logger,// custom logger instance
middleware,// custom middleware use before validate happens
})
app.listen(3333)
FAQs
Build restful api like HapiJs
The npm package koa-swapi receives a total of 56 weekly downloads. As such, koa-swapi popularity was classified as not popular.
We found that koa-swapi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.