mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-22 09:01:09 +03:00
Feature: interactive swagger-ui auto-generated API docs from express (#1812)
* Add interactive swagger-ui auto-generated API docs from express * Update README.md * Update index.ts //@ts-ignore * Fix eslint no-console error * Add swagger paths * Add all end points * Update swagger.yml * update swagger yml file * update swagger config --------- Co-authored-by: Henry <hzj94@hotmail.com>
This commit is contained in:
committed by
GitHub
parent
0f58d31493
commit
e8f5f07735
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"ignore": ["**/*.spec.ts", ".git", "node_modules"],
|
||||
"watch": ["src"],
|
||||
"exec": "ts-node ./src/index.ts",
|
||||
"ext": "ts, yml"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "flowise-api",
|
||||
"version": "1.0.0",
|
||||
"description": "Flowise API documentation server",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"start": "node dist/index.js",
|
||||
"dev": "concurrently \"tsc-watch --noClear -p ./tsconfig.json\" \"nodemon\"",
|
||||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0"
|
||||
},
|
||||
"license": "SEE LICENSE IN LICENSE.md",
|
||||
"dependencies": {
|
||||
"swagger-jsdoc": "^6.2.8",
|
||||
"swagger-ui-express": "^5.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/swagger-jsdoc": "^6.0.1",
|
||||
"@types/swagger-ui-express": "^4.1.3",
|
||||
"tsc-watch": "^6.0.4"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import swaggerJSDoc from 'swagger-jsdoc'
|
||||
|
||||
const swaggerUiOptions = {
|
||||
failOnErrors: true, // Throw when parsing errors
|
||||
baseDir: __dirname, // Base directory which we use to locate your JSDOC files
|
||||
exposeApiDocs: true,
|
||||
definition: {
|
||||
openapi: '3.0.3',
|
||||
info: {
|
||||
title: 'Flowise APIs',
|
||||
summary: 'Interactive swagger-ui auto-generated API docs from express, based on a swagger.yml file',
|
||||
version: '1.0.0',
|
||||
description:
|
||||
'This module serves auto-generated swagger-ui generated API docs from Flowise express backend, based on a swagger.yml file. Swagger is available on: http://localhost:6655/api-docs',
|
||||
license: {
|
||||
name: 'Apache 2.0',
|
||||
url: 'https://github.com/FlowiseAI/Flowise/blob/main/LICENSE.md'
|
||||
},
|
||||
contact: {
|
||||
name: 'FlowiseAI',
|
||||
email: 'support@flowiseai.com'
|
||||
}
|
||||
},
|
||||
servers: [
|
||||
{
|
||||
url: 'http://localhost:3000/api/v1',
|
||||
description: 'Flowise Server'
|
||||
}
|
||||
]
|
||||
},
|
||||
apis: [`${process.cwd()}/dist/routes/**/*.js`, `${process.cwd()}/src/yml/swagger.yml`]
|
||||
}
|
||||
|
||||
// https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md
|
||||
const swaggerExplorerOptions = {
|
||||
swaggerOptions: {
|
||||
validatorUrl: '127.0.0.1'
|
||||
},
|
||||
explorer: true
|
||||
}
|
||||
|
||||
const swaggerDocs = swaggerJSDoc(swaggerUiOptions)
|
||||
|
||||
export { swaggerDocs, swaggerExplorerOptions }
|
||||
@@ -0,0 +1,17 @@
|
||||
import express, { Request, Response } from 'express'
|
||||
import swaggerUi from 'swagger-ui-express'
|
||||
import { swaggerDocs, swaggerExplorerOptions } from './configs/swagger.config'
|
||||
|
||||
const app = express()
|
||||
const port = 6655
|
||||
|
||||
app.get('/', (req: Request, res: Response) => {
|
||||
res.redirect('/api-docs')
|
||||
})
|
||||
|
||||
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocs, swaggerExplorerOptions))
|
||||
|
||||
app.listen(port, () => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Flowise API documentation server listening on port ${port}`)
|
||||
})
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["es2017"],
|
||||
"target": "es2017" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
||||
"experimentalDecorators": true /* Enable experimental support for TC39 stage 2 draft decorators. */,
|
||||
"emitDecoratorMetadata": true /* Emit design-type metadata for decorated declarations in source files. */,
|
||||
"module": "commonjs" /* Specify what module code is generated. */,
|
||||
"outDir": "dist",
|
||||
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
|
||||
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
||||
"strict": true /* Enable all strict type-checking options. */,
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
|
||||
"sourceMap": true,
|
||||
"strictPropertyInitialization": false,
|
||||
"declaration": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in New Issue
Block a user