Description
Machine readable definitions in specs (or out-of-band) makes it possible for tools to use that information for a variety of purposes:
- Generating binding code, as in the case of Web IDL
- Generating basic existence tests, as with idlharness.js
- Automating detection of missing documentation for MDN
Possible additional benefits depending on the solution:
- Translating to other things, like OpenRPC or OpenAPI
- If there are types of any sort, then less type checking in prose
- If the mechanism for defining endpoints is built into spec preprocessors like Bikeshed, then it would make it easier to define feature-specific automation in other specs, like in Permissions
Previous discussions is in #1462 (comment):
@foolip it would be great if this protocol could be machine readable as it would simplify the creation of rudimental bindings that can be used to build a framework with higher level abstractions as well as for documentation. For example: the Chrome DevTools protocol is maintained as a pure json file and is used to build its documentation page as well as CDP modules like chrome-remote-interface. This can safe a lot of time and duplication for adopters building packages around the protocol.
Another example is from the WebdriverIO project where I've defined a custom JSON format of the WebDriver spec that is used to autogenerate a minimal functional binding. While I think a spec text is not necessarily suited as user documentation - being able to have the ability for type checks especially in the JS ecosystem would be very beneficial.
A while ago I tried to convert the current WebDriver protocol into an OpenAPI spec and was able to generate a page like this: https://webdriver.github.io/webdriver/. I can imagine that it should be not that difficult to build a bikeshed pre processor that reads an OpenAPI spec and coverts it into a spec document.
I would be happy to help contribute and drive the effort for a machine readable spec if you all think it is worthwhile.
I played around with OpenRPC when writing the explainer. There's an example here. I ran into some minor issues. The spec supports only one-way calls (no concept of bidi) so I ended up using tags to mark things as either "events" or "commands". The tooling support also seems pretty limited. There's a code gen tool but this supports only TypeScript and Rust at the moment.
AsyncAPI looks promising instead. It's more generic and can express both HTTP and WebSocket transports in the same file. It also has proper support for bidi communication through "channels".
Also briefly discussed in the 27 May 2020 meeting:
@christian-bromann: it would be good if we can have the definitions of API to be machine readable
... I would like to maintain an OpenAPI version of the spec at least@bwalderman: having a machine readable version of the spec is great, I am not familiar with OpenAPI
@jgraham: the machine readable version should be normative items to simplify things
@foolip: being able to extract this is great, but we can go patch BS if we need to, Tab will likely handle it
On that very last line, I'd like to clarify that I meant that @tabatkins would like accept patches, not that he'd do all the work for us :)