|
| 1 | +# Hoist Core OpenAPI Specification |
| 2 | + |
| 3 | +This directory contains the OpenAPI 3.0 specification for hoist-core's HTTP API, covering all |
| 4 | +controller endpoints provided by the framework plugin. |
| 5 | + |
| 6 | +## Files |
| 7 | + |
| 8 | +| File | Purpose | |
| 9 | +|------|---------| |
| 10 | +| `openapi.yaml` | The OpenAPI 3.0.3 spec β 122 paths across 30 tags | |
| 11 | +| `validate-openapi.sh` | Shell wrapper to run validation | |
| 12 | +| `validate-openapi.py` | Python validation script β cross-references spec against controller source | |
| 13 | + |
| 14 | +## Using the Spec |
| 15 | + |
| 16 | +### Swagger UI |
| 17 | + |
| 18 | +Serve the spec with any Swagger UI instance: |
| 19 | + |
| 20 | +```bash |
| 21 | +# Quick local viewer via Docker |
| 22 | +docker run -p 8080:8080 -e SWAGGER_JSON=/spec/openapi.yaml \ |
| 23 | + -v $(pwd)/openapi:/spec swaggerapi/swagger-ui |
| 24 | + |
| 25 | +# Or use the online editor at https://editor.swagger.io |
| 26 | +# (paste/upload openapi.yaml) |
| 27 | +``` |
| 28 | + |
| 29 | +### Code Generation / Mocking |
| 30 | + |
| 31 | +The spec can be used with standard OpenAPI tooling: |
| 32 | + |
| 33 | +```bash |
| 34 | +# Generate a mock server with Prism |
| 35 | +npx @stoplight/prism-cli mock openapi/openapi.yaml |
| 36 | + |
| 37 | +# Generate client SDKs with openapi-generator |
| 38 | +npx @openapitools/openapi-generator-cli generate \ |
| 39 | + -i openapi/openapi.yaml -g typescript-fetch -o generated/client |
| 40 | +``` |
| 41 | + |
| 42 | +### Redoc Documentation |
| 43 | + |
| 44 | +```bash |
| 45 | +npx @redocly/cli preview-docs openapi/openapi.yaml |
| 46 | +``` |
| 47 | + |
| 48 | +## Validation |
| 49 | + |
| 50 | +Run the validation script to verify the spec matches the current codebase: |
| 51 | + |
| 52 | +```bash |
| 53 | +# From project root |
| 54 | +./openapi/validate-openapi.sh |
| 55 | + |
| 56 | +# Or directly |
| 57 | +python3 openapi/validate-openapi.py /path/to/hoist-core |
| 58 | +``` |
| 59 | + |
| 60 | +The script checks: |
| 61 | +1. **YAML syntax** β ensures the file parses correctly |
| 62 | +2. **Endpoint coverage** β scans every `*Controller.groovy` file, extracts public actions, |
| 63 | + and verifies each has a corresponding path entry in the spec |
| 64 | +3. **Schema validation** (optional) β suggests running `@redocly/cli lint` for full |
| 65 | + OpenAPI 3.0 schema compliance |
| 66 | + |
| 67 | +For full schema validation, install one of: |
| 68 | +```bash |
| 69 | +npm install -g @redocly/cli # Recommended |
| 70 | +npm install -g swagger-cli # Alternative |
| 71 | +``` |
| 72 | + |
| 73 | +## Updating the Spec |
| 74 | + |
| 75 | +When adding or modifying controller endpoints in hoist-core: |
| 76 | + |
| 77 | +### Adding a New Endpoint |
| 78 | + |
| 79 | +1. Add the endpoint to the appropriate section in `openapi.yaml`: |
| 80 | + - **Core endpoints** (XhController, XhViewController) β top of paths section |
| 81 | + - **Admin REST CRUD** (extends AdminRestController) β "ADMIN REST CRUD" section |
| 82 | + - **Admin non-REST** β "ADMIN NON-REST ENDPOINTS" section |
| 83 | + - **Cluster admin** β "ADMIN CLUSTER ENDPOINTS" section |
| 84 | + |
| 85 | +2. Follow the existing patterns: |
| 86 | + - Use the correct tag from the `tags` list |
| 87 | + - Include `operationId` as `{controllerUrlName}.{action}` |
| 88 | + - Document parameters, request body, and response schema |
| 89 | + - Note required roles in the `description` field |
| 90 | + |
| 91 | +3. Run validation: `./openapi/validate-openapi.sh` |
| 92 | + |
| 93 | +### Adding a New REST Controller |
| 94 | + |
| 95 | +If the controller extends `AdminRestController`, add 8 path entries following the pattern |
| 96 | +of existing REST controllers: |
| 97 | +- `GET /rest/{name}` β read (list) |
| 98 | +- `GET /rest/{name}/{id}` β read (single) |
| 99 | +- `POST /rest/{name}` β create |
| 100 | +- `PUT /rest/{name}` β update |
| 101 | +- `DELETE /rest/{name}/{id}` β delete |
| 102 | +- `POST /rest/{name}/bulkUpdate` β bulk update |
| 103 | +- `POST /rest/{name}/bulkDelete` β bulk delete |
| 104 | +- `GET /rest/{name}/lookupData` β lookup data |
| 105 | + |
| 106 | +### Adding a New Domain Model |
| 107 | + |
| 108 | +Add the schema to `components.schemas` in the spec, following existing examples |
| 109 | +(e.g., `AppConfig`, `Monitor`, `Preference`). |
| 110 | + |
| 111 | +### Conventions |
| 112 | + |
| 113 | +- **Tags**: Group endpoints by feature area. Use `Admin: ` prefix for admin endpoints. |
| 114 | +- **Operation IDs**: `{controllerUrlName}.{actionName}` (e.g., `configAdmin.read`) |
| 115 | +- **Roles**: Document required roles in endpoint descriptions, not in the schema itself |
| 116 | + (since roles are enforced server-side and may vary by deployment). |
| 117 | +- **Response schemas**: Use `$ref` to domain model schemas where possible. Use inline |
| 118 | + `type: object` for dynamic/app-specific response shapes. |
| 119 | + |
| 120 | +## Endpoint Coverage Summary |
| 121 | + |
| 122 | +| Category | Controllers | Endpoints | |
| 123 | +|----------|------------|-----------| |
| 124 | +| Core (XhController) | 1 | 27 | |
| 125 | +| Views (XhViewController) | 1 | 7 | |
| 126 | +| Proxy | 1 | 1 | |
| 127 | +| Admin REST CRUD | 6 | 48 | |
| 128 | +| Admin Non-REST | 10 | 25 | |
| 129 | +| Admin Cluster | 7 | 16 | |
| 130 | +| **Total** | **26** | **122** | |
0 commit comments