Package: asyncapi-codegen
AsyncAPI Codegenasyncapi-codegeninterprets an AsyncAPI spec and generates code and documentation accordingly.   Only MQTT is supported.There are two parts to this:Interpret the AsyncAPI spec into Python classes in ways that makes it easier to use.Use Jinja2 templates to create the code.TerminologyWith pub/sub architecture, the broker is a server and everything is a client to it.  As such, is is useful to define the general nature of clients to differentiate roles between clients.Aprovideris the MQTT service that provides functionality. The AsyncAPI spec describes the behavior of the provider.
Autilizeris the MQTT client that consumes the functionality.  When the AsyncAPI spec uses "publish" and "subscribe" terms, it is the utilizer that does the described action.Supported LanguagesLanaguageMQTT LibraryJSON LibraryJSON Schema LibraryC++Mosquitto ClientrapidjsonBuilt-in via json-schema-codegenPythonPaho MQTTPython built-inNoneFeatures:FeaturePythonC++Enforces JSON SchemaNoYesDocumentation FormatsFormats:Markdown (with significant HTML), suitable for display on GitLab.Output filesThe generator creates the following types of output files:client interface.  This is the main interface for publishing or subscribing to messages.servers.  Represents a connection to a server.   Currently, onlyunauthenticated MQTTconnections are supported.  Aserver objectis provided to aclient interfaceto establish the connection to the broker/server.parameters.  These are just schema objects.messages.  Currently, these are just schema objects.  However, in the future these objects will also take protocol-specific message bindings.schemas. These are structures that always enforce schema compliance and provide (de-)serialization methods to rapidjson Value objects (which can thus be used to create JSON strings).Generated code files should be annotated fordoxygendocument generation, or at least that is the goal.Installationpip3installasyncapi-codegenPython requirements for running code generatorSee alsorequirements.txtpython 3.10jinja2stringcasejson-schema-codegenpyyamlPython Code GenerationRequirements for the generated python codepython 3.7parsepaho-mqttC++ Code GenerationRequirements for the generated C++ codeboost (boost::optional and boost::variant among others)rapidjson 1.1C++11Using DockerUtilizer codeTo generate utilizer/client C++ code for an AsyncAPI spec, you could run this docker command, carefully adjusting the volume mounting to the directory containing the specs and the directory for the output.When the YAML uses the words "publish" and "subscribe", the utilizer will perform those MQTT actions.dockerrun--rm-t\-v$(pwd)/examples:/specs\-v$(pwd)/output:/output\--user$UID:$GID\docker.io/pearmaster/asyncapi-codegen:latest\--yaml/specs/streetlights-mqtt.yml\--nameStreetlights\--cppProvider codeIf you'd like instead to generate C++ code for the provider, you can append--progtype providerto the docker command to look like:dockerrun--rm-t\-v$(pwd)/examples:/specs\-v$(pwd)/output:/output\--user$UID:$GID\docker.io/pearmaster/asyncapi-codegen:latest\--yaml/specs/streetlights-mqtt.yml\--nameStreetlights\--cpp\--progtypeproviderMarkdown documentationThis command will generate documentation for utilizers.  The entire spec is output in one big markdown file.dockerrun--rm-t\-v$(pwd)/examples:/specs\-v$(pwd)/output:/output\--user$UID:$GID\docker.io/pearmaster/asyncapi-codegen:latest\--yaml/specs/streetlights-mqtt.yml\--nameStreetlights--markdownLicenseGPLv2