Skip to content

Commit 4f10538

Browse files
Add comprehensive GitHub Copilot instructions for repository development workflow (#59)
* Initial plan * Add comprehensive GitHub Copilot instructions with validated commands and timing expectations Co-authored-by: jasonblanchard <1238532+jasonblanchard@users.noreply.github.com> --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: jasonblanchard <1238532+jasonblanchard@users.noreply.github.com>
1 parent 6cfb279 commit 4f10538

File tree

1 file changed

+233
-0
lines changed

1 file changed

+233
-0
lines changed

.github/copilot-instructions.md

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
# OpenAPI TypeScript Server
2+
3+
OpenAPI TypeScript Server is a CLI and minimal runtime library that helps you implement type-safe APIs documented by OpenAPI. This is a monorepo with framework-agnostic core functionality and Express adapter.
4+
5+
Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.
6+
7+
## Working Effectively
8+
9+
### Node.js Version Requirement - CRITICAL
10+
11+
- **REQUIRED**: Node.js >= 23.6.0 (specified in .nvmrc and package.json)
12+
- Current examples and tests use TypeScript files directly which requires Node.js 23+ experimental TypeScript support
13+
- If you have an older Node.js version, you MUST upgrade first or many commands will fail
14+
15+
### Bootstrap and Build Process
16+
17+
- Install dependencies: `npm ci` -- takes 30 seconds. NEVER CANCEL. Set timeout to 60+ minutes.
18+
- Check code formatting: `npm run format:check` -- takes 2 seconds
19+
- Build all packages: `npm run build:packages` -- takes 5 seconds
20+
- Generate examples: `npm run gen:examples` -- takes 5 seconds
21+
- TypeScript type checking: `npm run typecheck` -- takes 3 seconds
22+
- Run tests: `npm test` -- takes 1 second (requires Node.js 23+)
23+
24+
### Complete Development Setup Sequence
25+
26+
```bash
27+
# 1. Ensure Node.js version (CRITICAL)
28+
node --version # Must be >= 23.6.0
29+
30+
# 2. Install dependencies
31+
npm ci # NEVER CANCEL: Takes 30 seconds
32+
33+
# 3. Build packages
34+
npm run build:packages # Takes 5 seconds
35+
36+
# 4. Generate examples (validates CLI tools work)
37+
npm run gen:examples # Takes 5 seconds
38+
39+
# 5. Validate everything
40+
npm run format:check # Takes 2 seconds
41+
npm run typecheck # Takes 3 seconds
42+
npm test # Takes 1 second (requires Node.js 23+)
43+
```
44+
45+
## Repository Structure
46+
47+
### Core Packages
48+
49+
- `packages/openapi-typescript-server`: Core CLI and type generation
50+
- `packages/openapi-typescript-server-express`: Express framework adapter
51+
- `packages/openapi-typescript-server-runtime`: Shared runtime utilities
52+
53+
### Examples
54+
55+
- `examples/docs`: Basic petstore API example with full server setup
56+
- `examples/kitchensink`: More complex API demonstrating various features
57+
- `examples/petstore`: Standard petstore example
58+
59+
### Key Files
60+
61+
- `.nvmrc`: Specifies required Node.js version (v23.6.0)
62+
- `package.json`: Workspace configuration and scripts
63+
- `tsconfig.json`: TypeScript configuration for entire monorepo
64+
65+
## CLI Tools and Code Generation
66+
67+
### OpenAPI TypeScript Type Generation
68+
69+
```bash
70+
# Generate TypeScript types from OpenAPI spec
71+
npx openapi-typescript ./openapi.yaml --output ./gen/schema.d.ts
72+
```
73+
74+
### Server Interface Generation
75+
76+
```bash
77+
# Generate server interface from OpenAPI spec
78+
npx openapi-typescript-server ./openapi.yaml --types ./schema.d.ts --output ./gen/server.ts
79+
```
80+
81+
### Complete Workflow Example
82+
83+
```bash
84+
# In any example directory (e.g., examples/docs):
85+
openapi-typescript ./openapi.yaml --output ./gen/schema.d.ts
86+
openapi-typescript-server ./openapi.yaml --types ./schema.d.ts --output ./gen/server.ts
87+
```
88+
89+
## Running and Testing
90+
91+
### Run Example Applications
92+
93+
**IMPORTANT**: Requires Node.js >= 23.6.0
94+
95+
```bash
96+
# Navigate to an example
97+
cd examples/docs
98+
99+
# Start the server (with hot reload)
100+
npm run start # Runs: node --watch cmd/index.ts
101+
102+
# Server will be available at http://localhost:8080
103+
```
104+
105+
### Test API Endpoints
106+
107+
```bash
108+
# Test the petstore API
109+
curl -X POST http://localhost:8080/api/v3/speak/123 \
110+
-H "Content-Type: application/json" \
111+
-d '{"sound":"grrrr"}'
112+
113+
# Expected response:
114+
# {"greeting":"Pet 123 says \"grrrr\""}
115+
```
116+
117+
### Run Tests
118+
119+
**NOTE**: Tests require Node.js >= 23.6.0 to run TypeScript files directly
120+
121+
```bash
122+
# Run all tests across workspace
123+
npm test
124+
125+
# Run tests for specific package
126+
cd packages/openapi-typescript-server-express
127+
npm test
128+
```
129+
130+
## Validation Scenarios
131+
132+
### CRITICAL: Always Run These After Changes
133+
134+
1. **Build Validation**: `npm run build:packages` - Must complete successfully
135+
2. **Format Check**: `npm run format:check` - Must pass for CI
136+
3. **Type Checking**: `npm run typecheck` - Must pass with no errors
137+
4. **Code Generation**: `npm run gen:examples` - Must regenerate without errors
138+
5. **Test Suite**: `npm test` - Must pass (requires Node.js 23+)
139+
140+
### Manual Validation After Server Changes
141+
142+
1. Start an example server: `cd examples/docs && npm run start`
143+
2. Test API endpoint: `curl -X POST http://localhost:8080/api/v3/speak/123 -H "Content-Type: application/json" -d '{"sound":"test"}'`
144+
3. Verify JSON response: `{"greeting":"Pet 123 says \"test\""}`
145+
4. Test error endpoint: `curl http://localhost:8080/api/v3/uhoh`
146+
5. Verify error response with status 418
147+
148+
### Before Committing
149+
150+
- ALWAYS run `npm run format` to auto-fix formatting issues
151+
- ALWAYS run the complete validation sequence above
152+
- The CI pipeline (.github/workflows/test.yaml) will fail if formatting or builds fail
153+
154+
## Common Issues and Solutions
155+
156+
### Node.js Version Mismatch
157+
158+
**Problem**: `TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"`
159+
**Solution**: Upgrade to Node.js >= 23.6.0. The project uses experimental TypeScript support.
160+
161+
### Build Failures
162+
163+
**Problem**: `npm run build:packages` fails
164+
**Solution**:
165+
166+
1. Run `npm ci` to ensure dependencies are properly installed
167+
2. Check TypeScript compilation with `npm run typecheck`
168+
3. Verify all workspace packages have built correctly
169+
170+
### Test Failures
171+
172+
**Problem**: Tests not running or failing unexpectedly
173+
**Solution**:
174+
175+
1. Ensure Node.js >= 23.6.0
176+
2. Run `npm run build:packages` first
177+
3. Check individual test files in packages/_/src/_.test.ts
178+
179+
## Development Tips
180+
181+
### Working with OpenAPI Specs
182+
183+
- Always validate your OpenAPI spec before generation
184+
- Use `--types ./schema.d.ts` path relative to output directory
185+
- Re-run generation after any spec changes: `npm run gen:examples`
186+
187+
### Monorepo Navigation
188+
189+
- Use `npm run <script> --workspaces` to run scripts across all packages
190+
- Build packages before working on examples: `npm run build:packages`
191+
- Each package has its own package.json with specific scripts
192+
193+
### Code Quality
194+
195+
- Format code: `npm run format`
196+
- Check formatting: `npm run format:check`
197+
- Type check: `npm run typecheck`
198+
- All of these must pass for CI to succeed
199+
200+
## Time Expectations - NEVER CANCEL Commands
201+
202+
- `npm ci`: 30 seconds - NEVER CANCEL, set timeout to 60+ minutes
203+
- `npm run build:packages`: 5 seconds
204+
- `npm run gen:examples`: 5 seconds
205+
- `npm run typecheck`: 3 seconds
206+
- `npm run format:check`: 2 seconds
207+
- `npm test`: 1 second (when Node.js version is correct)
208+
209+
## Files You'll Frequently Need
210+
211+
### Package Manifests
212+
213+
```
214+
ls -la [repo-root]
215+
.github/
216+
.nvmrc
217+
package.json # Root workspace config
218+
packages/ # Core packages
219+
├── openapi-typescript-server/
220+
├── openapi-typescript-server-express/
221+
└── openapi-typescript-server-runtime/
222+
examples/ # Example applications
223+
├── docs/
224+
├── kitchensink/
225+
└── petstore/
226+
```
227+
228+
### Key Package Files
229+
230+
- `packages/openapi-typescript-server/src/cli/index.ts`: Main CLI entry point
231+
- `packages/openapi-typescript-server-express/src/index.ts`: Express adapter
232+
- `examples/docs/app.ts`: Complete Express server setup example
233+
- `examples/docs/api.ts`: API handler implementation example

0 commit comments

Comments
 (0)