CLI tool that converts WIDL schemas to JSON, see also waPC and the WIDL Validator
$ npm install -g widl2json
$ widl2json schema.widl --pretty --condensed
Will output:
{
"namespaces": [
{
"namespace": "greeting",
"interfaces": [
{
"operations": {
"sayHello": {
"name": "sayHello",
"parameters": {
"msg": {
"name": "msg",
"type": "string"
}
},
"type": "Response",
"unary": false
}
}
}
],
"types": [
{
"name": "Response",
"fields": {
"outgoing": {
"name": "outgoing",
"type": "string"
}
}
}
]
}
]
}
For the schema:
namespace "greeting"
interface {
sayHello(msg: string): Response
}
type Response {
outgoing: string
}
The WIDL Validator is very helpful for visualizing the structure of the WIDL tree.
$ widl2json schema-complex.widl --condensed | jq '.namespaces[].types[].name'
"Tests"
"Required"
"Optional"
"Maps"
"Lists"
"Thing"
```
### Output a markdown-formatted list of Namespaces and their interfaces:
```sh
$ widl2json schema-complex.widl --condensed | jq -r '.namespaces[] | "# Namespace `\(.namespace)`", (.interfaces[].operations[] | "- \(.name)(\(.parameters| map("\(.name):\(.type)")|join(", "))) => \(.type)") '
# Namespace `tests`
- testFunction(required:Required, optional:Optional, maps:Maps, lists:Lists) => Tests
- testUnary(tests:Tests) => Tests
- testDecode(tests:Tests) => string
widl2json <file> [options]
Convert WIDL schemas to JSON
Positionals:
file [string]
Options:
--version Show version number [boolean]
-h, --help Show help [boolean]
-t, --terse [boolean] [default: false]
-c, --condensed [boolean] [default: false]
-p, --pretty [boolean] [default: false]