Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
@chenxxx/egg-swagger-decorator
Advanced tools
using decorator to make router definitions and automatically generate swagger doc for egg.js
using decorator to auto generate swagger json docs
yarn add @grfe/egg-swagger-decorator --registry=http://r.npm.guorou.net/
using decorator to auto generate swagger json docs
based on Swagger OpenAPI Specification 2.0
// using commonds below to start and test the example server
git clone http://git.shensz.local/FE/egg-swagger-decorator
cd egg-swagger-decorator
npm install
npm run dev
finally open:
http://localhost:7001/swagger-html
// router.js
import { Application } from 'egg';
import { wrapper } from '../lib';
export default (app: Application) => {
wrapper(app, {
// // [optional] default is /swagger-html
// swaggerHtmlEndpoint: '/sw',
// // [optional] default is /swagger-json
// swaggerJsonEndpoint: '/sj',
// // [optional] default is false. if true, will call makeSwaggerRouter(app) automatically
// makeswaggerRouter: false,
title: 'foo',
version: 'v1.0.0',
description: 'bar',
// autoMount 是否开启
// defaultRequestMounte: true
});
makeSwaggerRouter(app);
};
// controller/test.ts
import { Controller, Context } from "egg";
import {
request,
summary,
path,
tags,
responses,
middlewares,
description,
} from "@grfe/egg-swagger-decorator";
import { PathParamsVO, IGetUserResultVO, IUserListVO } from "../dto";
const testTag = tags(["test"])
export default class Test extends Controller {
@request("get", "/users")
@description("get user list")
@testTag
@middlewares(async (ctx: Context, next) => {
ctx.logger.info("mid");
await next();
})
@responses(IUserListVO)
public async getUsers() {
const { ctx } = this;
const users = [{ name: "cjfff" }];
ctx.body = { users };
}
@request("get", "/users/{id}")
@summary("get user info by id")
@testTag
@path(PathParamsVO)
@responses(IGetUserResultVO)
public async getUser() {
const { id } = this.ctx.params;
this.ctx.body = { id };
}
}
dto define
// ../dto.ts
export class PathParamsVO {
@ApiProperty({
type: "number",
description: "用户id",
example: 10086,
})
@IsNumber({ maxDecimalPlaces: 1000 }, { message: "id 必须是数字2323232" })
id: number;
}
export class IUserVO {
@ApiProperty({
type: 'string'
})
name: string;
}
export class IUserListVO {
@ApiProperty({
type: IUserVO,
isArray: true
})
users: IUserVO[]
}
export class IGetUserResultVO {
@ApiProperty({
type: 'number'
})
id: number;
}
request // @request('POST', '/users')
tags // @tags(['example'])
query // @query({limit: {type: 'number', required: true, default: 10, description: 'desc'}})
path // @path({limit: {type: 'number', required: true, default: 10, description: 'desc'}})
body // @body({groups: {type: 'array', required: true, items: { type: 'string', example: 'group1' }}})
formData // @formData({file: {type: 'file', required: true, description: 'file content'}})
middlewares
// support koa middlewares.
// eg. @middlewares([func1,func2])
summary // @summary('api summary')
description // @description('api description')
responses
// @responses({ 200: { description: 'success'}, 400: { description: 'error'}})
// responses is optional
© MIT
FAQs
using decorator to make router definitions and automatically generate swagger doc for egg.js
The npm package @chenxxx/egg-swagger-decorator receives a total of 0 weekly downloads. As such, @chenxxx/egg-swagger-decorator popularity was classified as not popular.
We found that @chenxxx/egg-swagger-decorator 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
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
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.