Installations
npm install egg-swagger-decorator-plus
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
>=8.9.0
Node Version
12.8.0
NPM Version
6.10.2
Score
71.3
Supply Chain
98.4
Quality
75
Maintenance
100
Vulnerability
99.6
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Developer
Cody2333
Download Statistics
Total Downloads
415
Last Day
1
Last Week
1
Last Month
2
Last Year
48
GitHub Statistics
351 Stars
28 Commits
80 Forks
9 Watching
4 Branches
3 Contributors
Package Meta Information
Latest Version
0.1.2
Package Id
egg-swagger-decorator-plus@0.1.2
Unpacked Size
49.21 kB
Size
14.06 kB
File Count
24
NPM Version
6.10.2
Node Version
12.8.0
Total Downloads
Cumulative downloads
Total Downloads
415
Last day
0%
1
Compared to previous day
Last week
0%
1
Compared to previous week
Last month
0%
2
Compared to previous month
Last year
-48.9%
48
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
egg-swagger-decorator npm-url
using decorator to auto generate swagger json docs
Installation
1npm install egg-swagger-decorator
Introduction
egg Swagger Decorator
using decorator to auto generate swagger json docs
based on Swagger OpenAPI Specification 2.0
Example
// using commonds below to start and test the example server
git clone https://github.com/Cody2333/egg-swagger-decorator.git
cd egg-swagger-decorator
npm install
npm run dev
finally open:
http://localhost:7001/swagger-html
Requirements
- egg
- typescript > 2.8
Introduction
// 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',
});
makeSwaggerRouter(app);
};
using decorator to make api definition
// controller/test.ts
import { Controller } from 'egg';
import { request, summary, query, path, body, tags } from 'egg-swagger-decorator';
const testTag = tags(['test']);
const userSchema = {
name: { type: 'string', required: true },
gender: { type: 'string', required: false, example: 'male' },
groups: {
type: 'array',
required: true,
items: { type: 'string', example: 'group1' }
}
};
export default class Test extends Controller{
@request('get', '/users')
@summary('get user list')
@testTag
@query({
type: { type: 'number', required: true, default: 1, description: 'type' }
})
public async getUsers() {
const { ctx } = this;
const users = [{user1: {name: 'xxx'}}]
ctx.body = { users };
}
@request('get', '/users/{id}')
@summary('get user info by id')
@testTag
@path({
id: { type: 'number', required: true, default: 1, description: 'id' }
})
public async getUser() {
const { id } = this.ctx.params;
const user = {user1: {id, name: 'xxx'}}
this.ctx.body = { user };
}
@request('post', '/users')
@testTag
@body(userSchema)
public async postUser() {
const body = this.ctx.request.body;
this.ctx.body = { result: body };
}
public async temp(ctx) {
ctx.body = { result: 'success' };
}
}
avaliable annotations:
- tags
- query
- path
- body
- formData
- middlewares
- summary
- description
- responses
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
runing the project and it will generate docs through swagger ui
License
© MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
Found 2/26 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:8: update your workflow using https://app.stepsecurity.io/secureworkflow/Cody2333/koa-swagger-decorator/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:9: update your workflow using https://app.stepsecurity.io/secureworkflow/Cody2333/koa-swagger-decorator/ci.yml/main?enable=pin
- Info: 0 out of 1 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 4 are checked with a SAST tool
Score
3.1
/10
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More