Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: interactive swagger-ui auto-generated API docs from express #1812

Open
wants to merge 7 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Flowise has 3 different modules in a single mono repository.
- `server`: Node backend to serve API logics
- `ui`: React frontend
- `components`: Third-party nodes integrations
- `api-documentation`: Auto-generated swagger-ui API docs from express

### Prerequisite

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"packages/*",
"flowise",
"ui",
"components"
"components",
"api-documentation"
],
"scripts": {
"build": "turbo run build",
Expand Down
6 changes: 6 additions & 0 deletions packages/api-documentation/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ignore": ["**/*.spec.ts", ".git", "node_modules"],
"watch": ["src"],
"exec": "npx kill-port 6655 && node dist/index.js",
"ext": "ts, yml"
}
14 changes: 14 additions & 0 deletions packages/api-documentation/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "api-documentation",
"version": "1.0.0",
"description": "Flowise API documentation server",
"scripts": {
"dev": "concurrently \"yarn watch\" \"nodemon\"",
"watch": "tsc --watch"
},
"license": "SEE LICENSE IN LICENSE.md",
"dependencies": {
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.0"
}
}
46 changes: 46 additions & 0 deletions packages/api-documentation/src/configs/swagger.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//@ts-ignore
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 express, based on a swagger.yml file. \n\n This module works only when running Flowise in dev mode. \n\n The result is living documentation for Flowise API served via http://localhost:6655/api-docs route.',
termsOfService: 'https://flowiseai.com',
license: {
name: 'FlowiseAI',
url: 'https://github.com/FlowiseAI/Flowise/blob/main/LICENSE.md'
},
contact: {
name: 'Octavian FlowiseAI',
email: '[email protected]'
}
},
servers: [
{
url: 'http://localhost:3000/api/v1',
description: 'Flowise Server Dev Mode'
}
]
},
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 }
18 changes: 18 additions & 0 deletions packages/api-documentation/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import express, { Request, Response } from 'express'
//@ts-ignore
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}`)
})
Loading
Loading