Skip to content
This repository was archived by the owner on Mar 8, 2025. It is now read-only.

Commit 361bdb0

Browse files
author
dnphu
committed
[Core] Add several auth in swagger
1 parent 465fcdb commit 361bdb0

File tree

18 files changed

+4085
-36
lines changed

18 files changed

+4085
-36
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ const document = new DocumentBuilder()
1616
title: 'Express application',
1717
version: '1.0',
1818
// Below fields are optional
19-
description: 'Description';
20-
termsOfService: 'http://swagger.io/terms/';
19+
description: 'Description',
20+
termsOfService: 'http://swagger.io/terms/',
2121
contact: {
22-
name: 'Phu';
23-
24-
};
22+
name: 'Phu',
23+
24+
},
2525
license: {
26-
name: 'Apache 2.0';
27-
url: 'http://www.apache.org/licenses/LICENSE-2.0.html';
28-
};
26+
name: 'Apache 2.0',
27+
url: 'http://www.apache.org/licenses/LICENSE-2.0.html',
28+
},
2929
})
3030
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
parserOptions: {
4+
project: 'tsconfig.json',
5+
sourceType: 'module',
6+
},
7+
plugins: ['@typescript-eslint/eslint-plugin'],
8+
extends: [
9+
'plugin:@typescript-eslint/recommended',
10+
'plugin:prettier/recommended',
11+
],
12+
root: true,
13+
env: {
14+
node: true,
15+
jest: true,
16+
},
17+
ignorePatterns: ['.eslintrc.js'],
18+
rules: {
19+
'@typescript-eslint/interface-name-prefix': 'off',
20+
'@typescript-eslint/explicit-function-return-type': 'off',
21+
'@typescript-eslint/explicit-module-boundary-types': 'off',
22+
'@typescript-eslint/no-explicit-any': 'off',
23+
},
24+
};
25+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# compiled output
2+
/dist
3+
/node_modules
4+
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
pnpm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
lerna-debug.log*
13+
14+
# OS
15+
.DS_Store
16+
17+
# Tests
18+
/coverage
19+
/.nyc_output
20+
21+
# IDEs and editors
22+
/.idea
23+
.project
24+
.classpath
25+
.c9/
26+
*.launch
27+
.settings/
28+
*.sublime-workspace
29+
30+
# IDE - VSCode
31+
.vscode/*
32+
!.vscode/settings.json
33+
!.vscode/tasks.json
34+
!.vscode/launch.json
35+
!.vscode/extensions.json
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all"
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"watch": ["src"],
3+
"ext": ".ts,.js",
4+
"ignore": [],
5+
"exec": "ts-node ./src/index.ts"
6+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"name": "lite-express-swagger",
3+
"version": "1.0.0",
4+
"main": "dist/index.ts",
5+
"license": "MIT",
6+
"dependencies": {
7+
"express": "^4.17.1",
8+
"swagger-ui-express": "^4.1.6"
9+
},
10+
"scripts": {
11+
"prebuild": "rimraf dist",
12+
"build": "yarn prebuild && tsc",
13+
"start": "node dist/index.js",
14+
"dev": "nodemon",
15+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"libs/**/*.ts\"",
16+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
17+
"test": "jest",
18+
"test:watch": "jest --watch",
19+
"test:cov": "jest --coverage",
20+
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
21+
"test:e2e": "jest --config ./test/jest-e2e.json"
22+
},
23+
"devDependencies": {
24+
"@types/express": "^4.17.13",
25+
"@types/jest": "^27.0.1",
26+
"@types/node": "^16.0.0",
27+
"@types/supertest": "^2.0.11",
28+
"@types/swagger-ui-express": "^4.1.3",
29+
"@typescript-eslint/eslint-plugin": "^4.28.2",
30+
"@typescript-eslint/parser": "^4.28.2",
31+
"eslint": "^7.30.0",
32+
"eslint-config-prettier": "^8.3.0",
33+
"eslint-plugin-prettier": "^3.4.0",
34+
"jest": "^27.0.6",
35+
"prettier": "^2.3.2",
36+
"supertest": "^6.1.3",
37+
"ts-jest": "^27.0.3",
38+
"ts-loader": "^9.2.3",
39+
"ts-node": "^10.0.0",
40+
"tsconfig-paths": "^3.10.1",
41+
"typescript": "^4.3.5"
42+
},
43+
"jest": {
44+
"moduleFileExtensions": [
45+
"js",
46+
"json",
47+
"ts"
48+
],
49+
"rootDir": ".",
50+
"testRegex": ".*\\.spec\\.ts$",
51+
"transform": {
52+
"^.+\\.(t|j)s$": "ts-jest"
53+
},
54+
"collectCoverageFrom": [
55+
"**/*.(t|j)s"
56+
],
57+
"coverageDirectory": "./coverage",
58+
"testEnvironment": "node",
59+
"roots": [
60+
"<rootDir>/src/",
61+
"<rootDir>/libs/"
62+
],
63+
"moduleNameMapper": {
64+
"^@rest/nest-rest(|/.*)$": "<rootDir>/libs/nest-rest/src/$1",
65+
"@modules/(.*)": "<rootDir>/src/modules/$1"
66+
}
67+
}
68+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as express from 'express';
2+
3+
const app = express.Router();
4+
5+
app.get('/', function (req, res) {
6+
return res.send('Hello World');
7+
});
8+
9+
export const authRouter = app;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as express from 'express';
2+
3+
const app = express.Router();
4+
5+
app.get('/', function (req, res) {
6+
return res.send('Hello World');
7+
});
8+
9+
export const userRouter = app;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as express from 'express';
2+
import swaggerConfig from './swagger.config';
3+
import { authRouter } from './api/auth';
4+
import { userRouter } from './api/users';
5+
6+
const app = express();
7+
const PORT = 3000;
8+
9+
app.use('/api/v1/auth', authRouter);
10+
app.use('/api/v1/users', userRouter);
11+
12+
swaggerConfig(app);
13+
14+
app.listen(PORT, () => {
15+
console.log(`App is running on port ${PORT}`);
16+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { DocumentBuilder } from '../../../lib/api/core/document';
2+
3+
export default (app) => {
4+
const document = new DocumentBuilder()
5+
.setInfo({
6+
title: 'Express application',
7+
version: '1.0',
8+
// Below fields are optional
9+
description: 'Description',
10+
termsOfService: 'http://swagger.io/terms/',
11+
contact: {
12+
name: 'Phu',
13+
14+
},
15+
license: {
16+
name: 'Apache 2.0',
17+
url: 'http://www.apache.org/licenses/LICENSE-2.0.html',
18+
},
19+
})
20+
.build();
21+
};

0 commit comments

Comments
 (0)