25 #pragma GCC diagnostic push
26 #pragma GCC diagnostic ignored "-Wshadow"
28 #include "staticjson/staticjson.hpp"
30 #pragma GCC diagnostic pop
33 #include "rapidjson/document.h"
34 #include "rapidjson/writer.h"
50 using namespace rapidjson;
51 auto schema = staticjson::export_json_schema(&obj);
52 schema.AddMember(StringRef(
"title"), StringRef(title.c_str()),
53 schema.GetAllocator());
56 Writer<StringBuffer> writer(buffer);
57 schema.Accept(writer);
58 return buffer.GetString();
64 const std::string& paramDescription,
67 using namespace rapidjson;
68 auto schema = staticjson::export_json_schema(&obj);
69 auto& allocator = schema.GetAllocator();
71 schema.AddMember(StringRef(
"name"), Value(paramName.c_str(), allocator),
73 schema.AddMember(StringRef(
"description"),
74 Value(paramDescription.c_str(), allocator), allocator);
80 using namespace rapidjson;
81 Document schema(kObjectType);
82 auto& allocator = schema.GetAllocator();
83 schema.AddMember(StringRef(
"title"), StringRef(desc.
methodName.c_str()),
85 schema.AddMember(StringRef(
"description"),
87 schema.AddMember(StringRef(
"type"), StringRef(
"method"), allocator);
98 template <
class P,
class R>
102 using namespace rapidjson;
104 auto& allocator = schema.GetAllocator();
107 auto retSchema = staticjson::export_json_schema(&retVal);
108 schema.AddMember(StringRef(
"returns"), retSchema, allocator);
110 Value params(kArrayType);
113 params.PushBack(paramSchema, allocator);
114 schema.AddMember(StringRef(
"params"), params, allocator);
117 Writer<StringBuffer> writer(buffer);
118 schema.Accept(writer);
119 return buffer.GetString();
122 template <
class P,
class R>
126 return buildJsonRpcSchemaRequest<P, R>(desc, obj);
138 using namespace rapidjson;
140 auto& allocator = schema.GetAllocator();
142 auto retSchema = staticjson::export_json_schema(&retVal);
143 schema.AddMember(StringRef(
"returns"), retSchema, allocator);
145 Value params(kArrayType);
146 schema.AddMember(StringRef(
"params"), params, allocator);
149 Writer<StringBuffer> writer(buffer);
150 schema.Accept(writer);
151 return buffer.GetString();
158 return buildJsonRpcSchemaRequestReturnOnly<R>(desc, retVal);
170 using namespace rapidjson;
172 auto& allocator = schema.GetAllocator();
174 Value params(kArrayType);
177 params.PushBack(paramSchema, allocator);
178 schema.AddMember(StringRef(
"params"), params, allocator);
181 Writer<StringBuffer> writer(buffer);
182 schema.Accept(writer);
183 return buffer.GetString();
190 return buildJsonRpcSchemaNotify<P>(desc, obj);
196 using namespace rapidjson;
198 auto& allocator = schema.GetAllocator();
200 schema.AddMember(StringRef(
"returns"), Value(kNullType), allocator);
202 Value params(kArrayType);
203 schema.AddMember(StringRef(
"params"), params, allocator);
206 Writer<StringBuffer> writer(buffer);
207 schema.Accept(writer);
208 return buffer.GetString();
rapidjson::Document _buildJsonRpcSchema(const RpcDescription &desc)
std::string buildJsonRpcSchemaNotify(const RpcParameterDescription &desc, P &obj)
rapidjson::Document getRPCParameterSchema(const std::string ¶mName, const std::string ¶mDescription, T &obj)
std::string buildJsonRpcSchemaRequestReturnOnly(const RpcDescription &desc, R &retVal)
std::string buildJsonSchema(std::vector< std::pair< std::string, PropertyMap >> &objs, const std::string &title)
std::string buildJsonRpcSchemaRequest(const RpcParameterDescription &desc, P &obj)
std::string methodDescription
std::string paramDescription