Skip to content

Commit 9a87626

Browse files
authored
docs: adding comprehensive documentation for usage (#21)
1 parent e897044 commit 9a87626

4 files changed

Lines changed: 227 additions & 0 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Available Commands:
5656
Flags:
5757
-d, --debug Enable debug mode
5858
-h, --help help for chargeflow
59+
-m, --model string Charging-station model for vendor/model-specific schema selection
60+
-V, --vendor string Charging-station vendor for vendor/model-specific schema selection
5961
-v, --version string OCPP version to use (1.6, 2.0.1 or 2.1) (default "1.6")
6062
```
6163

@@ -72,6 +74,12 @@ Additionally, you can specify a custom path to vendor-specific OCPP schemas usin
7274
> You can also validate multiple OCPP messages from a file using the `-f` flag.
7375
> The file should be a newline-separated list of JSON strings.
7476
77+
For more detailed usage, see the documentation:
78+
79+
- [Validating messages from a file](docs/validate-from-file.md)
80+
- [Custom and vendor-specific schemas](docs/custom-schemas.md)
81+
- [Remote schema registry](docs/remote-registry.md)
82+
7583
## License
7684

7785
This project is licensed under the MIT License - see the [LICENSE](LICENSE.md) file for details.

docs/custom-schemas.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Custom and vendor-specific schemas
2+
3+
ChargeFlow ships with built-in schemas for all supported OCPP versions. You can extend or override
4+
these with your own JSON schemas to handle vendor-specific extensions or non-standard field
5+
constraints.
6+
7+
## Vendor- and model-specific validation
8+
9+
Pass `--vendor` (`-V`) and/or `--model` (`-m`) to select schemas scoped to a specific charging
10+
station. When both flags are provided, ChargeFlow looks for schemas registered under that
11+
vendor/model combination before falling back to the standard built-in schemas.
12+
13+
```bash
14+
chargeflow --vendor Acme --model FastCharger validate \
15+
'[2, "1", "BootNotification", {"chargePointVendor": "Acme", "chargePointModel": "FastCharger"}]'
16+
```
17+
18+
## Loading schemas from a local directory
19+
20+
Use `--schemas` (`-a`) on the `validate` command to point ChargeFlow at a folder of custom JSON
21+
schema files. File names must match the OCPP action name they cover, e.g.
22+
`BootNotificationRequest.json`. Custom schemas **replace** the built-in schemas for the actions
23+
they cover.
24+
25+
```bash
26+
chargeflow validate --schemas ./vendor-schemas \
27+
'[2, "1", "BootNotification", {"chargePointVendor": "Acme", "chargePointModel": "FastCharger"}]'
28+
```
29+
30+
Combining vendor/model flags with a custom schema folder is the typical pattern for validating
31+
messages from a specific charging station:
32+
33+
```bash
34+
chargeflow --vendor Acme --model FastCharger \
35+
validate --schemas ./vendor-schemas -f messages.txt -o report.json
36+
```
37+
38+
## Schema file naming convention
39+
40+
Schema files must be named after the OCPP action with a `.json` extension:
41+
42+
```
43+
BootNotificationRequest.json
44+
BootNotificationResponse.json
45+
DataTransfer.json
46+
...
47+
```
48+
49+
ChargeFlow strips the `.json` suffix and uses the remaining string as the action name when
50+
registering the schema internally.

docs/remote-registry.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Remote schema registry
2+
3+
ChargeFlow can push schemas to and remove schemas from a Kafka-compatible schema registry such as
4+
[Confluent Schema Registry](https://docs.confluent.io/platform/current/schema-registry/index.html)
5+
or [Redpanda Schema Registry](https://docs.redpanda.com/current/manage/schema-reg/).
6+
7+
All `schema` subcommands share a set of common flags for the registry URL and authentication.
8+
9+
## Common flags
10+
11+
| Flag | Description | Default |
12+
|------|-------------|---------|
13+
| `--url` | Remote schema registry URL (required) ||
14+
| `--auth-type` | Authentication type: `basic`, `bearer`, `api-key`, or omit for none ||
15+
| `--username` | Username for basic authentication ||
16+
| `--password` | Password for basic authentication ||
17+
| `--bearer-token` | Bearer token ||
18+
| `--api-key` | API key value ||
19+
| `--api-key-header` | Header name for the API key | `X-API-Key` |
20+
| `--custom-header` | Custom header name ||
21+
| `--custom-value` | Custom header value ||
22+
| `--timeout` | Request timeout | `5s` |
23+
24+
## Registering schemas
25+
26+
Use `schema register` to upload JSON schemas to the registry.
27+
28+
### Register a single schema file
29+
30+
`--action` is required when registering a single file.
31+
32+
```bash
33+
chargeflow schema --url http://localhost:8081 \
34+
register --file BootNotificationRequest.json --action BootNotificationRequest
35+
```
36+
37+
### Register all schemas from a directory
38+
39+
ChargeFlow reads every `.json` file in the directory and derives the action name from the file name.
40+
41+
```bash
42+
chargeflow schema --url http://localhost:8081 --version 2.0.1 \
43+
register --dir ./schemas
44+
```
45+
46+
### Register vendor-specific schemas
47+
48+
Supply `--vendor` and `--model` on the root command to scope the schemas to a specific charging
49+
station make and model.
50+
51+
```bash
52+
chargeflow --vendor Acme --model FastCharger \
53+
schema --url http://localhost:8081 \
54+
register --dir ./vendor-schemas
55+
```
56+
57+
## Deleting schemas
58+
59+
Use `schema remove` to delete schemas from the registry. Exactly one of `--action`, `--file`, or
60+
`--dir` must be specified.
61+
62+
### Delete by action name
63+
64+
```bash
65+
chargeflow schema --url http://localhost:8081 \
66+
remove --action BootNotificationRequest
67+
```
68+
69+
### Derive the action from a file name
70+
71+
ChargeFlow strips the `.json` suffix and uses the result as the action name.
72+
73+
```bash
74+
chargeflow schema --url http://localhost:8081 \
75+
remove --file BootNotificationRequest.json
76+
```
77+
78+
### Delete all schemas matching a directory
79+
80+
Removes every schema whose action name matches a `.json` file found in the directory.
81+
82+
```bash
83+
chargeflow schema --url http://localhost:8081 \
84+
remove --dir ./schemas
85+
```
86+
87+
### Delete vendor-specific schemas
88+
89+
```bash
90+
chargeflow --vendor Acme --model FastCharger \
91+
schema --url http://localhost:8081 \
92+
remove --action DataTransfer
93+
```
94+
95+
## Authentication examples
96+
97+
### Basic authentication
98+
99+
```bash
100+
chargeflow schema --url http://registry:8081 \
101+
--auth-type basic --username admin --password secret \
102+
register --dir ./schemas
103+
```
104+
105+
### Bearer token
106+
107+
```bash
108+
chargeflow schema --url https://registry.example.com \
109+
--auth-type bearer --bearer-token eyJ... \
110+
register --file MySchema.json --action MyAction
111+
```
112+
113+
### API key
114+
115+
The default header is `X-API-Key`. Override it with `--api-key-header` if your registry uses a
116+
different header name.
117+
118+
```bash
119+
chargeflow schema --url https://registry.example.com \
120+
--auth-type api-key --api-key abc123 \
121+
register --dir ./schemas
122+
```
123+
124+
### Custom header
125+
126+
```bash
127+
chargeflow schema --url https://registry.example.com \
128+
--custom-header X-Registry-Auth --custom-value my-secret \
129+
register --dir ./schemas
130+
```

docs/validate-from-file.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Validating messages from a file
2+
3+
Use the `-f` flag to read OCPP messages from a file instead of passing them as a command-line
4+
argument. Each line must be a single, complete OCPP JSON string; blank lines are ignored.
5+
6+
```bash
7+
chargeflow validate -f messages.txt
8+
```
9+
10+
Example `messages.txt`:
11+
12+
```
13+
[2, "1", "BootNotification", {"chargePointVendor": "TestVendor", "chargePointModel": "TestModel"}]
14+
[2, "2", "Heartbeat", {}]
15+
[3, "1", {"status": "Accepted", "currentTime": "2024-01-01T00:00:00Z", "interval": 300}]
16+
```
17+
18+
> [!NOTE]
19+
> Response messages (type `3`) require the `--response-type` flag so ChargeFlow knows which schema
20+
> to validate against, e.g. `--response-type BootNotificationResponse`.
21+
22+
## Saving the report to a file
23+
24+
Use `-o` to write the validation report to a file instead of stdout. Supported extensions are
25+
`.json`, `.csv`, and `.txt`.
26+
27+
```bash
28+
chargeflow validate -f messages.txt -o report.json
29+
chargeflow validate -f messages.txt -o report.csv
30+
chargeflow validate -f messages.txt -o report.txt
31+
```
32+
33+
## Specifying the OCPP version
34+
35+
The default version is `1.6`. Use `--version` (`-v`) to change it.
36+
37+
```bash
38+
chargeflow --version 2.0.1 validate -f messages.txt -o report.json
39+
```

0 commit comments

Comments
 (0)