|
1 | | -# HyperFleet API Spec - AI Agent Context |
2 | | - |
3 | | -This repository generates the HyperFleet core OpenAPI specification from TypeSpec definitions. The GCP-specific contract lives in [hyperfleet-api-spec-gcp](https://github.com/openshift-hyperfleet/hyperfleet-api-spec-gcp), which imports shared models from this repo as the `hyperfleet` npm package. |
4 | | - |
5 | | -## Quick Reference |
6 | | - |
7 | | -**Build commands:** |
8 | | -```bash |
9 | | -npm run build # Generate core OpenAPI spec |
10 | | -./build-schema.sh # Same, via script directly |
11 | | -``` |
12 | | - |
13 | | -**Validation workflow:** |
14 | | -```bash |
15 | | -npm install # Install dependencies |
16 | | -./build-schema.sh # Build core OpenAPI 3.0 |
17 | | -ls -l schemas/core/openapi.yaml # Confirm output exists |
18 | | -``` |
19 | | - |
20 | | -## Key Concepts |
21 | | - |
22 | | -### Repository Layout |
23 | | - |
24 | | -``` |
25 | | -shared/ # Cross-provider models and services (published as the `hyperfleet` npm package) |
26 | | -core/ # Core-only models and internal services |
27 | | -main.tsp # Entry point — imports shared + core |
28 | | -schemas/core/ # Generated output (committed) |
29 | | -``` |
30 | | - |
31 | | -**When adding new models:** |
32 | | -- Cross-provider models → `shared/models/` |
33 | | -- Core-only models → `core/models/` |
34 | | -- GCP-specific → separate repo (`hyperfleet-api-spec-gcp`) |
35 | | - |
36 | | -### Public vs Internal APIs |
37 | | - |
38 | | -Status endpoints are split: |
39 | | -- `shared/services/statuses.tsp` - GET operations (external clients) |
40 | | -- `core/services/statuses-internal.tsp` - PUT operations (internal adapters only) and resource force-delete |
41 | | - |
42 | | -The split allows generating different API contracts per audience. Only `statuses.tsp` is imported by default. |
43 | | - |
44 | | -## Code Style |
45 | | - |
46 | | -### TypeSpec Conventions |
47 | | - |
48 | | -**Imports first, namespace second** (applies to service and model files; example `const` files do not declare a namespace): |
49 | | -```typescript |
50 | | -import "@typespec/http"; |
51 | | -import "../models/common/model.tsp"; |
52 | | - |
53 | | -namespace HyperFleet; |
54 | | -``` |
55 | | - |
56 | | -**Use decorators for HTTP semantics:** |
57 | | -```typescript |
58 | | -@route("/clusters") |
59 | | -interface Clusters { |
60 | | - @get list(): Cluster[] | Error; |
61 | | - @post create(@body cluster: ClusterInput): Cluster | Error; |
62 | | -} |
63 | | -``` |
64 | | - |
65 | | -**Model naming:** |
66 | | -- Resources: `Cluster`, `NodePool` (singular) |
67 | | -- Inputs: `ClusterInput`, `NodePoolInput` |
68 | | -- Provider-specific: `GCPClusterSpec`, `AWSClusterSpec` |
69 | | - |
70 | | -### File Organization |
71 | | - |
72 | | -``` |
73 | | -shared/models/{resource}/ |
74 | | - ├── model.tsp # Shared model definitions |
75 | | - └── interfaces.tsp # Optional: shared interfaces |
76 | | -
|
77 | | -shared/services/ |
78 | | - └── {resource}.tsp # Shared service endpoints |
79 | | -
|
80 | | -core/models/{resource}/ |
81 | | - └── model.tsp # Core-specific models |
82 | | -
|
83 | | -core/services/ |
84 | | - └── {resource}-internal.tsp # Internal-only endpoints |
85 | | -``` |
86 | | - |
87 | | -## Boundaries |
88 | | - |
89 | | -**DO NOT:** |
90 | | -- Modify generated files in `schemas/` or `tsp-output-core/` directly |
91 | | -- Add dependencies without checking TypeSpec version compatibility |
92 | | -- Auto-generate documentation - it degrades agent performance per research |
93 | | -- Commit `node_modules/` or build artifacts |
94 | | - |
95 | | -**DO:** |
96 | | -- Run `./build-schema.sh` and commit `schemas/core/openapi.yaml` with your changes |
97 | | -- Keep TypeSpec files focused (one resource per service file) |
98 | | -- Use semantic versioning for releases (automated on merge to main) |
99 | | - |
100 | | -## Common Tasks |
101 | | - |
102 | | -### Add a new endpoint to existing service |
103 | | - |
104 | | -```typescript |
105 | | -// shared/services/clusters.tsp |
106 | | -namespace HyperFleet; |
107 | | - |
108 | | -@route("/clusters") |
109 | | -interface Clusters { |
110 | | - // ... existing endpoints ... |
111 | | - |
112 | | - @get |
113 | | - @route("/{id}/health") |
114 | | - getHealth(@path id: string): HealthStatus | Error; |
115 | | -} |
116 | | -``` |
117 | | - |
118 | | -### Add a new resource |
119 | | - |
120 | | -1. Create model: |
121 | | -```typescript |
122 | | -// shared/models/health/model.tsp |
123 | | -import "@typespec/http"; |
124 | | - |
125 | | -model HealthStatus { |
126 | | - id: string; |
127 | | - state: "healthy" | "degraded" | "critical"; |
128 | | - lastChecked: utcDateTime; |
129 | | -} |
130 | | -``` |
131 | | - |
132 | | -2. Create service: |
133 | | -```typescript |
134 | | -// shared/services/health.tsp |
135 | | -import "@typespec/http"; |
136 | | -import "../models/health/model.tsp"; |
137 | | -import "../models/common/model.tsp"; |
138 | | - |
139 | | -namespace HyperFleet; |
140 | | - |
141 | | -@route("/health") |
142 | | -interface Health { |
143 | | - @get check(): HealthStatus | Error; |
144 | | -} |
145 | | -``` |
146 | | - |
147 | | -3. Import in `main.tsp`: |
148 | | -```typescript |
149 | | -import "./shared/services/health.tsp"; |
150 | | -``` |
151 | | - |
152 | | -4. Build: `npm run build` |
153 | | - |
154 | | -### Add provider-specific fields |
155 | | - |
156 | | -Provider-specific models live in the provider's own repository (e.g., `hyperfleet-api-spec-gcp`). See that repo for examples of how to extend core shared models. |
157 | | - |
158 | | -## Version Bump and Changelog |
159 | | - |
160 | | -When bumping the version in `main.tsp`, always update `CHANGELOG.md`: |
161 | | - |
162 | | -1. Keep `## [Unreleased]` at the top, then add a new version section as `## [X.Y.Z] - YYYY-MM-DD` |
163 | | -2. List changes under appropriate headings (`Added`, `Changed`, `Fixed`, `Removed`) |
164 | | -3. Update the comparison links at the bottom of the file |
165 | | -4. Follow [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) format |
166 | | - |
167 | | -## Validation Checklist |
168 | | - |
169 | | -Before submitting changes: |
170 | | - |
171 | | -- [ ] Dependencies installed: `npm install` |
172 | | -- [ ] Core schema builds: `./build-schema.sh` |
173 | | -- [ ] Schema file generated: `ls schemas/core/openapi.yaml` |
174 | | -- [ ] No TypeSpec compilation errors (check output) |
175 | | -- [ ] Schema passes linting: `spectral lint schemas/core/openapi.yaml` |
176 | | -- [ ] Changes committed including schema update |
177 | | -- [ ] PR description references related issue |
178 | | - |
179 | | -## Build System Details |
180 | | - |
181 | | -**The build-schema.sh script:** |
182 | | -1. Extracts the version from `main.tsp` and syncs it into `package.json` |
183 | | -2. Runs `node_modules/.bin/tsp compile main.tsp --output-dir tsp-output-core` |
184 | | -3. Moves output to `schemas/core/openapi.yaml` |
185 | | - |
186 | | -**Output locations:** |
187 | | -- TypeSpec temp: `tsp-output-core/schema/openapi.yaml` (auto-deleted) |
188 | | -- Final: `schemas/core/openapi.yaml` (committed) |
189 | | - |
190 | | -**Version sync:** `package.json` version is kept in lockstep with `main.tsp` automatically on every build. The CI consistency check (`git diff --exit-code`) enforces that both are committed together. |
191 | | - |
192 | | -## VS Code Extension Notes |
193 | | - |
194 | | -The TypeSpec extension may show false errors for models resolved only at compile time. Both the CLI and "Emit from TypeSpec" command work correctly. |
195 | | - |
196 | | -## Dependencies |
197 | | - |
198 | | -All TypeSpec libraries use version `^1.6.0` for consistency: |
199 | | -- `@typespec/compiler` - Core compiler |
200 | | -- `@typespec/http` - HTTP semantics |
201 | | -- `@typespec/openapi` - OpenAPI decorators |
202 | | -- `@typespec/openapi3` - OpenAPI 3.0 emitter |
203 | | -- `@typespec/rest` - REST conventions |
204 | | -- `@typespec/versioning` - API versioning support |
205 | | - |
206 | | -**Adding new TypeSpec libraries:** |
207 | | -```bash |
208 | | -npm install --save-dev @typespec/library-name@^1.6.0 |
209 | | -``` |
210 | | - |
211 | | -Match the version range to existing dependencies. |
212 | | - |
213 | | -## Release Process |
214 | | - |
215 | | -Releases are **fully automated** via GitHub Actions (`.github/workflows/release.yml`). |
216 | | - |
217 | | -On every push to `main`, the release workflow: |
218 | | -1. Extracts the version from the `@info` decorator in `main.tsp` |
219 | | -2. Skips if a tag for that version already exists |
220 | | -3. Builds the core OpenAPI schema |
221 | | -4. Creates an annotated Git tag (`vX.Y.Z`) |
222 | | -5. Publishes a GitHub Release with `core-openapi.yaml` attached |
223 | | - |
224 | | -The CI workflow (`.github/workflows/ci.yml`) enforces that the version in `main.tsp` is bumped from the latest release tag before a PR can be merged. |
225 | | - |
226 | | -To release a new version, simply bump the version in `main.tsp` and merge to `main`. |
227 | | - |
228 | | -## Architecture Context |
229 | | - |
230 | | -This repository is part of the HyperFleet project. For broader context: |
231 | | -- Architecture repo: https://github.com/openshift-hyperfleet/architecture |
232 | | -- Main API implementation: https://github.com/openshift-hyperfleet/hyperfleet-api |
233 | | - |
234 | | -The API implementation consumes the generated OpenAPI specs for validation and documentation. |
| 1 | +@AGENTS.md |
0 commit comments