The WebSocket protocol allows sending messages back-and-forth between a server and a client, but it does not define the structure of these messages. They can be strings or blobs, but how these strings/blobs are structured is left to the user.
This is not a bad thing - you want this layer of abstraction to be simple so it'll be easy to implement and to build on - but with HTTP - which is similar in that way (you can only send plaintext with some headers) there are many protocols built on top of it that add this structure: OpenAPI, OData, XML-RPC and many more.
Some of these protocols offer schema generators - you write your protocol's specification once in the protocol's favorite format, and it generates types and/or functions for using your protocol in many different languages.
I tried looking for something similar for WebSocket, but all I could find is AsyncAPI. It has a generator, which can output using templates - but it only has templates for Java (Spring, actually), HTML and Markdown (the last two are for generating docs) and googling for third-party templates yielded nothing (except results from their issue tracker, which has some requests to add templates for more languages).
Is there anything more complete than AsyncAPI? If this is the best we have I'll use that - good documentation generation is already a bonus, and I can probably contribute myself templates for the languages I use - but if there is something better I'd rather just use that.








I'm not looking for a subprotocol - what I'm looking for is more of an API specification.
Consider, for example, this JSON-RPC example (taken from Wikipedia):
The JSON-RPC protocol says:
jsonrpcstring field that defines the JSON-RPC protocol version.idinteger field that identifies the message.methodstring field that says what command you want to call.paramsobject(/array) field that provides parameters for the command.jsonrpcstring field that defines the JSON-RPC protocol version.idinteger field that is the same as the request it responds to.resultfield that holds the result of the request.What I'm looking for is something that'll allow me to define:
subtractmethod:minuendnumeric parameter that specifies the number to subtract from.subtrahendnumeric parameter that specifies the number to subtract.OpenAPI and OData seem to have that, but they are REST-centric. XML-RPC has this, but being XML it is needlessly complicated and burdensome. I was hoping to find something similar to AsyncAPI - though if there is something, maybe the fact it cannot be easily found implies that it will not have wide language support either...