pearmaster / asyncapi-codegen Goto Github PK
View Code? Open in Web Editor NEWUses an AsyncAPI 2.0 spec to generate C++ code
License: GNU General Public License v2.0
Uses an AsyncAPI 2.0 spec to generate C++ code
License: GNU General Public License v2.0
For python code generation, Paho provides message_callback_add()
which does a lot of the work we were doing manually by keeping track of topic-specific callbacks. Using message_callback_add()
will simplify things which is good.
When installing via pip install json-schema-codegen
, the following errors occur
ERROR: Could not find a version that satisfies the requirement jacobsjinjatoo (from json-schema-codegen->-r requirements.txt (line 1)) (from versions: none)
ERROR: No matching distribution found for jacobsjinjatoo (from json-schema-codegen->-r requirements.txt (line 1))
Appears jacobsjinjatoo project is listed as jacobs-jinja-too in PyPI
Hello, I've currently generated a C++ api from an api spec but the inclusion of
#include "/exceptions.hpp"
and
#include "rapidjson/document.h"
requires me to package my code and rapidjson inside of the boost library and is blocking compilation. Is that line referring to <boost/property_tree/exceptions.hpp>? Is there a way to only generate code that uses path list includes?
Validation does not happen as expected when the input AsyncApi spec have metacharacter '\d' in a pattern to match digits 0 to 9.
Issue seems to be because '\d' is not escaped correctly in the regex pattern string inside generated Validate() and hence considers it as character 'd' instead of digit.
Example:
Input AsyncApi spec have pattern: ^(?:(\d{4}-[0-1][0-9]-[0-3][0-9]))$
Generated Validate() is below and it does not validate as expected,
void testasyncapi::schema::Date::Validate(const std::string& testValue)
{
std::regex regexPattern("^(?:(\d{4}-[0-1][0-9]-[0-3][0-9]))$");
std::smatch regexMatch;
std::regex_match(testValue, regexMatch, regexPattern);
if (regexMatch.empty()) throw ::JsonSchemaException("The string value did not match the required regular expression pattern '^(?:(\d{4}-[0-1][0-9]-[0-3][0-9]))$'");
}
Note: Tested only for metacharacter '\d'.
Hi,
I have an issue building the example for python. C++ works great. Could you please help out?
System:
Windows 10
Python 3.10 (Conda)
Pip installed your requirements
Failure generating test '#/components/schemas/lightMeasuredPayload' for scheam {'type': 'object', 'properties': {'lumens': {'type': 'integer', 'minimum': 0, 'description': 'Light intensity measured in lumens.'}, 'sentAt': {'$ref': '#/components/schemas/sentAt'}}} when root is Spec
Traceback (most recent call last):
File "C:\Users{user}\Documents\projects\asyncapi-codegen\examples\example_py.py", line 23, in
pyGenerator.Generate(spec, stringcase.pascalcase(name), name)
File "C:\Users{user}\Documents\projects\asyncapi-codegen\asyncapicodegen\python_client.py", line 59, in Generate
self.GenerateTestsForType(wrappedSpec, 'schemas', lambda obj: obj)
File "C:\Users{user}\Documents\projects\asyncapi-codegen\asyncapicodegen\python_summary.py", line 48, in GenerateTestsForType
output = schemaGenerator.GenerateTestFromPath(schema, spec, ref)
File "C:\Miniconda3\envs\asyncapi-codegen\lib\site-packages\jsonschemacodegen\python.py", line 92, in GenerateTestFromPath
return self.GenerateTest(schema, root, class_name, filename_base, path)
File "C:\Miniconda3\envs\asyncapi-codegen\lib\site-packages\jsonschemacodegen\python.py", line 68, in GenerateTest
filename = self.resolver.py_test_filename(path)
AttributeError: 'SimpleResolver' object has no attribute 'py_test_filename'. Did you mean: 'py_filename'?
Class name is used instead of namespace in many lines of generated code resulting in build error.
Using streetlights-mqtt.yml example as input, the generated code have namespace streetlight (all lower case) and class name Streetlight (Uppercase S) (generated using "--name Streetlight")
The generated code incorrectly uses 'Streetlight::schema', "Streetlight::message" and "Streetlight::parameter" etc using class name 'Streetlight' instead of using namespace 'streetlight'.
The refereed yml file in the example files returns an 404.
That is in line 10 of examples/example_cpp.py: urlopen("https://raw.githubusercontent.com/asyncapi/asyncapi/master/examples/2.0.0/streetlights.yml")
Same goes for example/example_py.py
I suggest to include the example file with the example.
Cheers!
Say, the asyncapi doc have more than 1 parameter in a subscribe topic. Sample topic mentioned at bottom.
Building the cpp generated code throws below error:
src/asyncapi_test_client.cpp:215:56: error: ‘errorType’ was not declared in this scope
215 | _sendErrorCallback(device, errorType, inMsg);
cmd/{device}/dm/get-{errorType}:
description: The topic on which the device will receive a request to upload the specified error type.
parameters:
device:
$ref: '#/components/parameters/device'
errorType:
$ref: '#/components/parameters/errorType'
subscribe:
operationId: sendError
traits:
- $ref: '#/components/operationTraits/mqtt'
message:
$ref: '#/components/messages/getErrorRequest'
Workaround - I have to manually edit the generated code to declare errorType and get it using FromString() in ReceiveMessage() of *_client.cpp. But adding a workaround creates chaos while regenerating the code.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.