check
Compare generated files against current OpenAPI specifications to detect drift.
Usage
sparktype check [options]Options
| Option | Alias | Description |
|---|---|---|
--config <path> | -c | Path to configuration file |
Purpose
The check command verifies that your generated type files match what would be generated from the current OpenAPI specifications. It's designed for CI/CD pipelines to ensure generated types stay in sync.
Key behaviors:
- Does not modify any files
- Compares existing files against expected output
- Exits with code
1if any files are out of sync - Shows detailed diff of what changed
Examples
Basic Check
sparktype checkOutput when in sync:
Checking ./src/types/api.ts... OK
Checking ./src/schemas/api.ts... OK
All files are in sync.Output when out of sync:
Checking ./src/types/api.ts... MISMATCH
User:
+ email: string (added)
~ name: string -> string | undefined
Checking ./src/schemas/api.ts... OK
1 file(s) out of sync. Run 'sparktype generate' to update.Missing Files
If a generated file doesn't exist:
Checking ./src/types/api.ts... MISSING
1 file(s) out of sync. Run 'sparktype generate' to update.Custom Config Path
sparktype check --config ./config/typegen.jsoncExit Codes
| Code | Meaning |
|---|---|
0 | All files are in sync |
1 | One or more files are out of sync or missing |
Diff Output
When files differ, check shows a structured diff:
Checking ./src/types/api.ts... MISMATCH
+ NewType (added)
- RemovedType (removed)
ChangedType:
+ newField: string (added)
- oldField: number (removed)
~ modifiedField: string -> numberDiff Symbols
| Symbol | Meaning |
|---|---|
+ | Added (type or property) |
- | Removed (type or property) |
~ | Changed (shows old → new value) |
Workflow Recommendations
Fail Early
Run check early in your CI pipeline, before tests or builds:
jobs:
lint:
# ...
check-types:
# ...
test:
needs: [lint, check-types]
# ...Require Regeneration
When check fails, developers should:
- Run
sparktype generatelocally - Review the changes
- Commit the updated files
Don't Auto-Generate in CI
Avoid running generate in CI and committing automatically. This hides spec changes from code review.
Instead:
- Run
checkin CI (fails if out of sync) - Require developers to run
generatelocally - Include generated files in code review
Comparison vs Generation
| Aspect | generate | check |
|---|---|---|
| Modifies files | Yes | No |
| Exit code on diff | N/A | 1 |
| Shows diff | No | Yes |
| Use case | Development | CI/CD |
Troubleshooting
False Positives
If check reports differences but generate produces the same file:
- Ensure you're using the same sparktype version in CI and locally
- Check for line ending differences (CRLF vs LF)
- Verify the same config options are used
Performance
For large specs, check may take a few seconds. Cache dependencies in CI:
- uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}