init
Create a new typegen.jsonc configuration file with a starter template.
Usage
sh
sparktype initOptions
The init command has no options. It always creates typegen.jsonc in the current directory.
Behavior
Running sparktype init:
- Checks if
typegen.jsoncalready exists - If not, creates a new file with a starter template
- Prints the path to the created file
Output:
Created: typegen.jsoncGenerated Template
jsonc
{
"$schema": "https://hntrl.github.io/sparktype/schema.json",
// Named spec sources - supports multiple specs
"specs": {
"api": {
"path": "./openapi.yaml"
}
},
// Output configurations
"outputs": [
{
"path": "./src/types/api.ts",
"format": "typescript",
"spec": "api"
}
],
// Global options
"options": {
"dereferenceRefs": true,
"generateEnums": true,
"nullableHandling": "optional"
}
}Exit Codes
| Code | Meaning |
|---|---|
0 | File created successfully |
1 | File already exists or write failed |
After Initialization
After running init:
Update the spec path: Change
./openapi.yamlto your actual OpenAPI spec locationUpdate the output path: Change
./src/types/api.tsto where you want generated typesAdjust options: Review the global options and modify as needed
Run generate:
shsparktype generate
Alternative: Manual Creation
If you prefer to create the config manually, see the Configuration Overview for the full schema documentation.
Minimum required config:
jsonc
{
"specs": {
"api": { "path": "./openapi.yaml" }
},
"outputs": [
{
"path": "./types/api.ts",
"format": "typescript",
"contents": ["api:*"]
}
]
}