|
| 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. |
0 commit comments