ScaleIT Bridge API is documented using OpenAPI 3.0.3 specification. The specification file is located at swagger.yaml in the project root.
- Go to Swagger Editor
- Click "File" → "Import file"
- Select
swagger.yamlfrom the project root - View interactive API documentation
Method A: Using PowerShell script (easiest)
# From project root
.\serve-swagger.ps1
# Or with custom port:
.\serve-swagger.ps1 -Port 8081Method B: Using npx (no installation needed)
npx swagger-ui-serve swagger.yaml
# Or with custom port:
npx swagger-ui-serve swagger.yaml -p 8081Method C: Global installation
npm install -g swagger-ui-serve
swagger-ui-serve swagger.yaml- Open browser:
http://localhost:3000(or your specified port)
-
Install Redoc CLI:
npm install -g redoc-cli
-
Generate HTML:
redoc-cli bundle swagger.yaml -o api-docs.html
-
Open
api-docs.htmlin browser
- Install "OpenAPI (Swagger) Editor" extension in VS Code
- Open
swagger.yaml - Click "Preview" button to view documentation
GET /health- Check service health
GET /devices- List all devicesGET /api/config- Get all device configurationsPOST /api/config/save- Save device configurationDELETE /api/config/{device_id}- Delete device configuration
POST /scalecmd- Execute scale command (readGross, readNet, tare, zero)
POST /api/shutdown- Gracefully shutdown serverPOST /api/start- Start server (if already running)
curl http://localhost:8080/healthcurl http://localhost:8080/devicescurl -X POST http://localhost:8080/scalecmd \
-H "Content-Type: application/json" \
-d '{"device_id": "scale1", "command": "readGross"}'curl -X POST http://localhost:8080/api/config/save \
-H "Content-Type: application/json" \
-d '{
"device_id": "scale1",
"config": {
"name": "Main Scale",
"manufacturer": "Dini Argeo",
"model": "C320",
"protocol": "ASCII",
"connection": {
"connection_type": "Tcp",
"host": "192.168.1.254",
"port": 4001
},
"timeout_ms": 5000,
"commands": {
"readGross": "READ",
"readNet": "REXT",
"tare": "TARE",
"zero": "ZERO"
},
"enabled": true
}
}'npx @openapitools/openapi-generator-cli generate \
-i swagger.yaml \
-g typescript-axios \
-o ./generated/typescript-clientnpx @openapitools/openapi-generator-cli generate \
-i swagger.yaml \
-g python \
-o ./generated/python-clientnpx @openapitools/openapi-generator-cli generate \
-i swagger.yaml \
-g rust \
-o ./generated/rust-clientWhen adding new endpoints or modifying existing ones:
- Update
swagger.yamlwith new endpoint definitions - Add request/response schemas to
components/schemas - Add examples for better clarity
- Update this README if needed
- Commit and push changes
Validate the OpenAPI specification:
# Using swagger-cli
npm install -g @apidevtools/swagger-cli
swagger-cli validate swagger.yaml
# Or using online validator
# https://editor.swagger.io/ - automatically validates on importThe Swagger documentation can be published to:
- GitHub Pages: Host the generated HTML
- SwaggerHub: Upload
swagger.yamlto SwaggerHub - Read the Docs: Include in project documentation
- API Gateway: Use for API gateway documentation