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

[Core] Improve Interface for swagger documentation #4

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ const document = new DocumentBuilder()
title: 'Express application',
version: '1.0',
// Below fields are optional
description: 'Description';
termsOfService: 'http://swagger.io/terms/';
description: 'Description',
termsOfService: 'http://swagger.io/terms/',
contact: {
name: 'Phu';
email: '[email protected]';
};
name: 'Phu',
email: '[email protected]',
},
license: {
name: 'Apache 2.0';
url: 'http://www.apache.org/licenses/LICENSE-2.0.html';
};
name: 'Apache 2.0',
url: 'http://www.apache.org/licenses/LICENSE-2.0.html',
},
})
```
25 changes: 25 additions & 0 deletions example/01-express-example/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};

35 changes: 35 additions & 0 deletions example/01-express-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# compiled output
/dist
/node_modules

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
4 changes: 4 additions & 0 deletions example/01-express-example/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
6 changes: 6 additions & 0 deletions example/01-express-example/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"watch": ["src"],
"ext": ".js",
"ignore": [],
"exec": "node ./src/index.js"
}
32 changes: 32 additions & 0 deletions example/01-express-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "lite-express-swagger",
"version": "1.0.0",
"main": "dist/index.ts",
"license": "MIT",
"dependencies": {
"express": "^4.17.1",
"swagger-ui-express": "^4.1.6",
"lite-express-swagger": "../../lib"
},
"scripts": {
"prebuild": "rimraf dist",
"build": "yarn prebuild && tsc",
"start": "node dist/index.js",
"dev": "nodemon",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"libs/**/*.ts\"",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"devDependencies": {
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"jest": "^27.0.6",
"nodemon": "^2.0.12",
"prettier": "^2.3.2"
}
}
11 changes: 11 additions & 0 deletions example/01-express-example/src/api/auth/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const express = require("express");

const app = express.Router();

app.get('/', function (req, res) {
return res.send('Hello World');
});

module.exports = {
authRouter: app
}
11 changes: 11 additions & 0 deletions example/01-express-example/src/api/users/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const express = require('express');

const app = express.Router();

app.get('/', function (req, res) {
return res.send('Hello World');
});

module.exports = {
userRouter: app
}
16 changes: 16 additions & 0 deletions example/01-express-example/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const express = require("express");
const swaggerConfig = require("./swagger.config.js");
const { authRouter } = require("./api/auth");
const { userRouter } = require("./api/users");

const app = express();
const PORT = 3000;

app.use('/api/v1/auth', authRouter);
app.use('/api/v1/users', userRouter);

swaggerConfig(app);

app.listen(PORT, () => {
console.log(`App is running on port ${PORT}`);
});
25 changes: 25 additions & 0 deletions example/01-express-example/src/swagger.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { DocumentBuilder } = require('../../../lib/api/core/document');
const { setup, serve } = require("swagger-ui-express");

module.exports = (app) => {
const document = new DocumentBuilder()
.setInfo({
title: 'Express application',
version: '1.0',
// Below fields are optional
description: 'Description',
termsOfService: 'http://swagger.io/terms/',
contact: {
name: 'Phu',
email: '[email protected]',
},
license: {
name: 'Apache 2.0',
url: 'http://www.apache.org/licenses/LICENSE-2.0.html',
},
})
.setBearerAuth()
.build();

app.use('/docs', serve, setup(document));
};
Loading