Skip to content

Commit 6634f16

Browse files
committed
Merge branch 'docs/api-docs' into update/FLOWISE_Release_2_2_7_billing_and_docs
2 parents 9fdeee8 + fa4e0b3 commit 6634f16

File tree

113 files changed

+27053
-1514
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+27053
-1514
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,6 @@ daisy/preview
170170

171171
# Used for anything personal dev scripts
172172
.local-scripts
173+
174+
**/swagger/yml
175+
**/swagger/md

packages/docs/devscripts/README.md

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Development Scripts
2+
3+
This directory contains utility scripts for development and maintenance tasks.
4+
5+
## OpenAPI Configuration Scripts
6+
7+
### update-openapi-config.js
8+
9+
This script updates all OpenAPI YAML files in the `openapi` directory with consistent configuration settings.
10+
11+
#### Features
12+
13+
1. **Add localhost server**: Adds `http://localhost:4000/api/v1` as a server option if not already present
14+
2. **Configure authentication**: Sets up Bearer token authentication with a fixed API key value
15+
3. **Update security references**: Updates all security references to use the Bearer token authentication
16+
17+
#### Prerequisites
18+
19+
- Node.js installed
20+
- js-yaml package installed
21+
22+
#### Installation
23+
24+
If you haven't installed the required dependencies:
25+
26+
```bash
27+
cd packages/docs
28+
npm install js-yaml
29+
# or with pnpm
30+
pnpm add js-yaml
31+
```
32+
33+
#### Usage
34+
35+
Run the script from the `packages/docs` directory:
36+
37+
```bash
38+
node devscripts/update-openapi-config.js
39+
```
40+
41+
After running the script, you need to regenerate the API documentation:
42+
43+
```bash
44+
node generate-api-docs.js
45+
```
46+
47+
Then build the documentation site:
48+
49+
```bash
50+
npm run build
51+
# or with pnpm
52+
pnpm run build
53+
```
54+
55+
#### How It Works
56+
57+
1. The script reads all YAML files in the `openapi` directory
58+
2. For each file, it:
59+
- Adds the localhost server if not already present
60+
- Configures Bearer token authentication
61+
- Updates all security references to use Bearer token authentication
62+
- Writes the updated YAML back to the file
63+
64+
### switch-auth-method.js
65+
66+
This script allows you to switch between Bearer token and API key authentication methods in all OpenAPI YAML files.
67+
68+
#### Features
69+
70+
1. **Switch authentication method**: Change between Bearer token and API key authentication
71+
2. **Update security references**: Updates all security references to use the selected authentication method
72+
3. **Consistent API key value**: Maintains the same API key value across all files
73+
74+
#### Usage
75+
76+
Run the script from the `packages/docs` directory, specifying the authentication method:
77+
78+
```bash
79+
# Switch to Bearer token authentication
80+
node devscripts/switch-auth-method.js bearer
81+
82+
# Switch to API key authentication
83+
node devscripts/switch-auth-method.js apikey
84+
```
85+
86+
After running the script, you need to regenerate the API documentation:
87+
88+
```bash
89+
node generate-api-docs.js
90+
```
91+
92+
#### How It Works
93+
94+
1. The script reads all YAML files in the `openapi` directory
95+
2. For each file, it:
96+
- Updates the security schemes based on the specified authentication method
97+
- Updates all security references to use the selected authentication method
98+
- Writes the updated YAML back to the file
99+
100+
### add-localhost-server.js
101+
102+
This script adds or updates the localhost server in all OpenAPI YAML files without changing the authentication method.
103+
104+
#### Features
105+
106+
1. **Add localhost server**: Adds a localhost server if not already present
107+
2. **Update existing server**: Updates an existing localhost server if found
108+
3. **Configurable port**: Allows specifying a custom port (default: 4000)
109+
110+
#### Usage
111+
112+
Run the script from the `packages/docs` directory, optionally specifying a port:
113+
114+
```bash
115+
# Use default port (4000)
116+
node devscripts/add-localhost-server.js
117+
118+
# Specify a custom port
119+
node devscripts/add-localhost-server.js 3000
120+
```
121+
122+
After running the script, you need to regenerate the API documentation:
123+
124+
```bash
125+
node generate-api-docs.js
126+
```
127+
128+
#### How It Works
129+
130+
1. The script reads all YAML files in the `openapi` directory
131+
2. For each file, it:
132+
- Checks if a localhost server already exists
133+
- Adds a new localhost server or updates the existing one
134+
- Writes the updated YAML back to the file
135+
136+
## Customization
137+
138+
To modify the scripts for different requirements:
139+
140+
1. **Change the localhost URL**: Update the `url` property in the `localhostServer` object or use the port parameter
141+
2. **Change the authentication method**: Modify the `securitySchemes` object or use the switch-auth-method.js script
142+
3. **Change the API key value**: Update the `API_KEY_VALUE` constant in the script
143+
144+
## Troubleshooting
145+
146+
If you encounter issues:
147+
148+
1. **YAML parsing errors**: Check that your YAML files are valid
149+
2. **File not found errors**: Ensure the script is run from the correct directory
150+
3. **Authentication not updating**: Check that the security references are being properly updated
151+
152+
## Complete Workflow for Updating API Documentation
153+
154+
1. **Update OpenAPI files**: Make your changes to the YAML files in the `openapi` directory
155+
2. **Add localhost server**: `node devscripts/add-localhost-server.js [port]`
156+
3. **Choose authentication method**: `node devscripts/switch-auth-method.js [bearer|apikey]`
157+
4. **Regenerate API docs**: `node generate-api-docs.js`
158+
5. **Build the site**: `npm run build` or `pnpm run build`
159+
6. **Test locally**: `npm run serve` or `pnpm run serve`
160+
161+
Alternatively, you can use the all-in-one script:
162+
163+
```bash
164+
node devscripts/update-openapi-config.js
165+
node generate-api-docs.js
166+
npm run build
167+
npm run serve
168+
```
169+
170+
This workflow ensures that all OpenAPI files have consistent server and authentication configurations while preserving your specific API endpoint changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Add Localhost Server Script
3+
*
4+
* This script adds or updates the localhost server in all OpenAPI YAML files
5+
* without changing the authentication method.
6+
*
7+
* Usage: node add-localhost-server.js [port]
8+
* Default port: 4000
9+
*/
10+
11+
const fs = require('fs')
12+
const path = require('path')
13+
const yaml = require('js-yaml')
14+
15+
// Get the port from command line arguments or use default
16+
const args = process.argv.slice(2)
17+
const port = args[0] || '4000'
18+
19+
const openApiDir = path.join(__dirname, '..', 'openapi')
20+
const files = fs.readdirSync(openApiDir).filter((file) => file.endsWith('.yaml'))
21+
22+
for (const file of files) {
23+
const filePath = path.join(openApiDir, file)
24+
const content = fs.readFileSync(filePath, 'utf8')
25+
26+
try {
27+
const doc = yaml.load(content)
28+
29+
// Add localhost server if not already present
30+
if (doc.servers) {
31+
const localhostServer = {
32+
url: `http://localhost:${port}/api/v1`,
33+
description: 'Local development server'
34+
}
35+
36+
// Check if localhost server already exists
37+
const localhostServerIndex = doc.servers.findIndex((server) => server.url.includes('localhost'))
38+
39+
if (localhostServerIndex === -1) {
40+
// Add new localhost server
41+
doc.servers.push(localhostServer)
42+
console.log(`Added localhost server to ${file}`)
43+
} else {
44+
// Update existing localhost server
45+
doc.servers[localhostServerIndex] = localhostServer
46+
console.log(`Updated localhost server in ${file}`)
47+
}
48+
} else {
49+
// Create servers array with localhost server
50+
doc.servers = [
51+
{
52+
url: `http://localhost:${port}/api/v1`,
53+
description: 'Local development server'
54+
}
55+
]
56+
console.log(`Created servers array with localhost server in ${file}`)
57+
}
58+
59+
// Write the updated YAML back to the file
60+
const updatedYaml = yaml.dump(doc, { lineWidth: -1 })
61+
fs.writeFileSync(filePath, updatedYaml, 'utf8')
62+
} catch (e) {
63+
console.error(`Error processing ${file}:`, e)
64+
}
65+
}
66+
67+
console.log(`All OpenAPI files have been updated with localhost server on port ${port}.`)

0 commit comments

Comments
 (0)