This guide explains how to add a new module to the tcli command structure using a Swagger/OpenAPI JSON file.
- Quick start
- Prerequisites
- Command anatomy
- How sub-modules are created
- How API calls work
- Add a module (runtime)
- Add a module (source control)
- Troubleshooting
Use this guide if you are:
- adding a new Swagger/OpenAPI service as a
tclimodule - trying to understand how module -> sub-module -> API command is generated
- building chained test flows using
-formatand pipes
If you only want the minimum steps to add a module:
- Ensure tcli is installed (run
make installif~/.tcliis missing) - Copy your Swagger JSON to
~/.tcli/data/<module>.jsonNote: The
datafolder must exist inside~/.tcli. Do not create a file nameddata. - Add module entry in
~/.tcli/modules.yaml - Run
tcliand confirm your module appears - Run
tcli <module>and confirm sub-modules/commands appear
If any of these fail, see the troubleshooting section at the end.
Install/build tcli first.
Check if config exists:
ls ~/.tcliIf not found, run from the repository root:
make installThis creates $HOME/.tcli and copies:
config.yamlmodules.yamldata/
Quick verify:
tcliYou should see a list of supported modules.
Given a command like:
tcli pce pce-customer createCustomerThe parts are:
tcli-> CLI commandpce-> modulepce-customer-> sub-module (tag/group)createCustomer-> API operation/command
Pipelines can be chained with | where each command reads stdin from the previous command output.
In tcli, sub-modules come from Swagger/OpenAPI operation tags.
- Module is from
modules.yaml(namefield) - Sub-module is from each operation's
tagsvalue - API command is from operation
operationId
Example command:
tcli pce pce-customer createCustomerMapping:
pce-> module entry inmodules.yamlpce-customer-> tag on thecreateCustomerAPI operationcreateCustomer-> operationId in Swagger JSON
Example Swagger pattern:
{
"tags": [
{ "name": "pce-customer", "description": "API for Customer Management" },
{ "name": "pce-cron", "description": "Cron job APIs" }
],
"paths": {
"/customer": {
"post": {
"tags": ["pce-customer"],
"operationId": "createCustomer"
}
}
}
}- If root-level
tagsare missing,tclidiscovers tags from path operations. - If an operation has multiple tags, that operation can appear under each tagged sub-module.
- If an operation has no tag, it is exposed directly as a module-level command.
tcli pce
tcli pce pce-customerUse these to confirm sub-modules and API commands were generated as expected.
tcli reads Swagger/OpenAPI JSON for each module and uniquely identifies each REST API by operationId.
Generic pattern:
tcli <module> <sub-module> <operationId>Input and request behavior are derived from Swagger fields:
parameters-> path, query, header, and body inputs- HTTP verb + endpoint -> from operation under
paths consumes(Swagger 2.0) or requestcontent(OpenAPI 3) -> request content type
This is why tcli can map CLI input and stdin JSON to the API request shape directly from spec.
tcli supports sequential test execution and response-to-request transformation through shell pipelines.
- Sequential execution using
| - Response to request transformation using
-format - Built-in jq via
gojqfor lightweight JSON shaping
Example chaining:
tcli pce pce-customer getTenantByTenantId -tenantId tenant11 -format '{tenantId:.tenantId}' | \
tcli pce pce-cams-data createCamsDataFlow:
- First command fetches tenant data
-formatkeeps/transforms required fields (for exampletenantId)- Next command consumes transformed JSON as input and executes
This helps build setup -> action -> verify style test cases with minimal external tooling.
Use this path when you want the module available immediately on your machine.
Copy your service spec into:
~/.tcli/data/<your-module>.json
Example:
~/.tcli/data/pce.json
~/.tcli/data/carepack_service.json
Edit:
~/.tcli/modules.yaml
Add an entry under modules::
modules:
- name: pce
config: data/pce.json
description: pc entitlement Service api commands
- name: carepack
config: data/carepack_service.json
description: Carepack Service SwaggerNotes:
nameis the top-level CLI module (tcli <name> ...)configis relative to~/.tcli- Keep names lowercase and shell-friendly
Run:
tcliYou should see your new module in the supported module list.
Then inspect commands in your module:
tcli <your-module>Then inspect API commands under a sub-module:
tcli <your-module> <your-sub-module>Use this path when you want to share the module definition with the team.
- Add Swagger JSON to:
tools/data/<your-module>.json
- Add module entry in:
tools/modules.yaml
- Re-install to sync runtime config:
make installThis copies updated tools/modules.yaml and tools/data/* into ~/.tcli.
~/.tcliexists- Swagger file exists in
~/.tcli/data ~/.tcli/modules.yamlhas the new module entrytclilists the moduletcli <module>lists module commands/sub-modules
| Symptom | Likely cause | Fix |
|---|---|---|
| Module not visible | YAML syntax error | Check indentation in ~/.tcli/modules.yaml |
| Module not visible | Wrong config path | Use relative path (e.g., data/pce.json) |
| No sub-modules | Missing tags | Add tags to operations in Swagger JSON |
| API command missing | Missing operationId | Ensure operationId exists for endpoint |
| Source changes not reflected | Stale install | Run make install to sync ~/.tcli |