Blue Brain BioExplorer
jsonPropertyMap.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2018, EPFL/Blue Brain Project
3  * All rights reserved. Do not distribute without permission.
4  * Responsible Author: Jonas Karlsson <jonas.karlsson@epfl.ch>
5  *
6  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
7  *
8  * This library is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Lesser General Public License version 3.0 as published
10  * by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #pragma once
23 
24 #include "jsonSerialization.h"
25 
29 
30 namespace
31 {
32 inline std::string matchEnum(const std::vector<std::string>& enums,
33  const int32_t value)
34 {
35  const bool inRange =
36  value >= 0 && static_cast<size_t>(value) < enums.size();
37  return inRange ? enums[static_cast<size_t>(value)] : "InvalidEnum";
38 }
39 } // namespace
40 
41 namespace core
42 {
43 namespace
44 {
45 std::string camelCaseToSnakeCase(const std::string& camelCase)
46 {
47  return core::string_utils::camelCaseToSeparated(camelCase, '_');
48 }
49 
50 std::string snakeCaseToCamelCase(const std::string& snakeCase)
51 {
52  return core::string_utils::separatedToCamelCase(snakeCase, '_');
53 }
54 
55 // Make a (movable) rapidjson string
56 rapidjson::Value make_value_string(
57  const std::string& str, rapidjson::Document::AllocatorType& allocator)
58 {
59  rapidjson::Value val;
60  val.SetString(str.c_str(), str.length(), allocator);
61  return val;
62 }
63 
64 // Make a (movable) rapidjson snake_case string from the given camelCase string.
65 rapidjson::Value make_json_string(const std::string& camelCase,
66  rapidjson::Document::AllocatorType& allocator)
67 {
68  return make_value_string(camelCaseToSnakeCase(camelCase), allocator);
69 }
70 
71 template <typename T>
72 void addDefaultValue(rapidjson::Document& document,
73  rapidjson::Document::AllocatorType& allocator,
74  const T& value)
75 {
76  document.AddMember(rapidjson::StringRef("default"), value, allocator);
77 }
78 
79 template <>
80 void addDefaultValue(rapidjson::Document& document,
81  rapidjson::Document::AllocatorType& allocator,
82  const std::string& value)
83 {
84  document.AddMember(rapidjson::StringRef("default"),
85  make_value_string(value, allocator).Move(), allocator);
86 }
87 
88 template <typename T, size_t S>
89 void addDefaultValueArray(rapidjson::Document& document,
90  rapidjson::Document::AllocatorType& allocator,
91  const std::array<T, S>& value)
92 {
93  rapidjson::Value arr(rapidjson::kArrayType);
94  for (const auto v : value)
95  arr.PushBack(v, allocator);
96  document.AddMember(rapidjson::StringRef("default"), arr, allocator);
97 }
98 
99 template <>
100 void addDefaultValue(rapidjson::Document& document,
101  rapidjson::Document::AllocatorType& allocator,
102  const std::array<double, 2>& value)
103 {
104  addDefaultValueArray(document, allocator, value);
105 }
106 
107 template <>
108 void addDefaultValue(rapidjson::Document& document,
109  rapidjson::Document::AllocatorType& allocator,
110  const std::array<int32_t, 2>& value)
111 {
112  addDefaultValueArray(document, allocator, value);
113 }
114 template <>
115 void addDefaultValue(rapidjson::Document& document,
116  rapidjson::Document::AllocatorType& allocator,
117  const std::array<double, 3>& value)
118 {
119  addDefaultValueArray(document, allocator, value);
120 }
121 template <>
122 void addDefaultValue(rapidjson::Document& document,
123  rapidjson::Document::AllocatorType& allocator,
124  const std::array<int32_t, 3>& value)
125 {
126  addDefaultValueArray(document, allocator, value);
127 }
128 template <>
129 void addDefaultValue(rapidjson::Document& document,
130  rapidjson::Document::AllocatorType& allocator,
131  const std::array<double, 4>& value)
132 {
133  addDefaultValueArray(document, allocator, value);
134 }
135 
136 // Create JSON schema for given property and add it to the given properties
137 // parent.
138 template <typename T>
139 void _addPropertySchema(const Property& prop, rapidjson::Value& properties,
140  rapidjson::Document::AllocatorType& allocator)
141 {
142  using namespace rapidjson;
143 
144  Document jsonSchema;
145  if (prop.enums.empty())
146  {
147  auto value = prop.get<T>();
148  jsonSchema = staticjson::export_json_schema(&value, &allocator);
149  jsonSchema.AddMember(StringRef("title"),
150  StringRef(prop.metaData.label.c_str()), allocator);
151  addDefaultValue(jsonSchema, allocator, value);
152  jsonSchema.AddMember(StringRef("readOnly"), prop.readOnly(), allocator);
153  const auto minValue = prop.min<T>();
154  const auto maxValue = prop.max<T>();
155  const bool hasLimits = maxValue - minValue != 0;
156  if (hasLimits)
157  {
158  if (jsonSchema.HasMember("minimum"))
159  jsonSchema["minimum"] = minValue;
160  else
161  jsonSchema.AddMember(StringRef("minimum"), minValue, allocator);
162 
163  if (jsonSchema.HasMember("maximum"))
164  jsonSchema["maximum"] = maxValue;
165  else
166  jsonSchema.AddMember(StringRef("maximum"), maxValue, allocator);
167  }
168  else
169  {
170  if (jsonSchema.HasMember("minimum"))
171  jsonSchema.RemoveMember("minimum");
172  if (jsonSchema.HasMember("maximum"))
173  jsonSchema.RemoveMember("maximum");
174  }
175  }
176  else
177  {
178  jsonSchema.SetObject();
179  jsonSchema.AddMember(StringRef("type"), StringRef("string"), allocator);
180  jsonSchema.AddMember(StringRef("title"),
181  StringRef(prop.metaData.label.c_str()), allocator);
182  jsonSchema.AddMember(StringRef("readOnly"), prop.readOnly(), allocator);
183 
184  // Specialized enum code
185  auto value = prop.get<int32_t>();
186  const auto valueStr = matchEnum(prop.enums, value);
187  addDefaultValue(jsonSchema, allocator, valueStr);
188 
189  Value enumerations(kArrayType);
190  for (const auto& name : prop.enums)
191  enumerations.PushBack(StringRef(name.data(), name.size()),
192  allocator);
193  jsonSchema.AddMember(StringRef("enum"), enumerations, allocator);
194  }
195  properties.AddMember(make_json_string(prop.name, allocator).Move(),
196  jsonSchema, allocator);
197 }
198 
199 // Create JSON schema for given bool property and add it to the given properties
200 // parent.
201 template <>
202 void _addPropertySchema<bool>(const Property& prop,
203  rapidjson::Value& properties,
204  rapidjson::Document::AllocatorType& allocator)
205 {
206  using namespace rapidjson;
207  auto value = prop.get<bool>();
208  auto jsonSchema = staticjson::export_json_schema(&value, &allocator);
209  jsonSchema.AddMember(StringRef("title"),
210  StringRef(prop.metaData.label.c_str()), allocator);
211  addDefaultValue(jsonSchema, allocator, value);
212  jsonSchema.AddMember(StringRef("readOnly"), prop.readOnly(), allocator);
213  properties.AddMember(make_json_string(prop.name, allocator).Move(),
214  jsonSchema, allocator);
215 }
216 
217 // Create JSON schema for string property and add it to the given properties
218 // parent.
219 template <>
220 void _addPropertySchema<std::string>(
221  const Property& prop, rapidjson::Value& properties,
222  rapidjson::Document::AllocatorType& allocator)
223 {
224  using namespace rapidjson;
225 
226  const bool isEnum = !prop.enums.empty();
227  auto value = prop.get<std::string>();
228 
229  Document jsonSchema;
230 
231  if (isEnum)
232  {
233  jsonSchema.SetObject();
234  jsonSchema.AddMember(StringRef("type"), StringRef("string"), allocator);
235  Value enumerations(kArrayType);
236  for (const auto& name : prop.enums)
237  enumerations.PushBack(StringRef(name.data(), name.size()),
238  allocator);
239  jsonSchema.AddMember(StringRef("enum"), enumerations, allocator);
240  }
241  else
242  {
243  jsonSchema = staticjson::export_json_schema(&value, &allocator);
244  }
245 
246  addDefaultValue(jsonSchema, allocator, value);
247  jsonSchema.AddMember(StringRef("readOnly"), prop.readOnly(), allocator);
248  jsonSchema.AddMember(StringRef("title"),
249  StringRef(prop.metaData.label.c_str()), allocator);
250  properties.AddMember(make_json_string(prop.name, allocator).Move(),
251  jsonSchema, allocator);
252 }
253 
254 // Create JSON schema for given array property and add it to the given
255 // properties parent.
256 template <typename T, int S>
257 void _addArrayPropertySchema(const Property& prop, rapidjson::Value& properties,
258  rapidjson::Document::AllocatorType& allocator)
259 {
260  using namespace rapidjson;
261  auto value = prop.get<std::array<T, S>>();
262  auto jsonSchema = staticjson::export_json_schema(&value, &allocator);
263  jsonSchema.AddMember(StringRef("title"),
264  StringRef(prop.metaData.label.c_str()), allocator);
265  addDefaultValue(jsonSchema, allocator, value);
266 
267  properties.AddMember(make_json_string(prop.name, allocator).Move(),
268  jsonSchema, allocator);
269 }
270 
271 // Serialize given array property to JSON.
272 template <typename T>
273 void _arrayPropertyToJson(rapidjson::Document& document, Property& prop)
274 {
275  rapidjson::Value array(rapidjson::kArrayType);
276  for (const auto& val : prop.get<T>())
277  array.PushBack(val, document.GetAllocator());
278 
279  document.AddMember(
280  make_json_string(prop.name, document.GetAllocator()).Move(), array,
281  document.GetAllocator());
282 }
283 } // namespace
284 
285 // Create JSON schema for a property map and add it to the given propSchema
286 // parent.
287 void _addPropertyMapSchema(const PropertyMap& propertyMap,
288  const std::string& title,
289  rapidjson::Document::AllocatorType& allocator,
290  rapidjson::Value& propSchema)
291 {
292  using namespace rapidjson;
293  propSchema.AddMember(StringRef("title"), StringRef(title.c_str()),
294  allocator);
295  propSchema.AddMember(StringRef("type"), StringRef("object"), allocator);
296 
297  Value properties(kObjectType);
298  for (auto prop : propertyMap.getProperties())
299  {
300  switch (prop->type)
301  {
303  _addPropertySchema<double>(*prop, properties, allocator);
304  break;
305  case Property::Type::Int:
306  _addPropertySchema<int32_t>(*prop, properties, allocator);
307  break;
309  _addPropertySchema<std::string>(*prop, properties, allocator);
310  break;
312  _addPropertySchema<bool>(*prop, properties, allocator);
313  break;
315  _addArrayPropertySchema<double, 2>(*prop, properties, allocator);
316  break;
318  _addArrayPropertySchema<int32_t, 2>(*prop, properties, allocator);
319  break;
321  _addArrayPropertySchema<double, 3>(*prop, properties, allocator);
322  break;
324  _addArrayPropertySchema<int32_t, 3>(*prop, properties, allocator);
325  break;
327  _addArrayPropertySchema<double, 4>(*prop, properties, allocator);
328  break;
329  }
330  }
331 
332  propSchema.AddMember(StringRef("properties"), properties, allocator);
333 }
334 
335 // Create JSON schema for a list of property maps and add it to the given oneOf
336 // parent.
338  const std::vector<std::pair<std::string, PropertyMap>>& objs,
339  rapidjson::Document::AllocatorType& allocator, rapidjson::Value& oneOf)
340 {
341  using namespace rapidjson;
342  for (const auto& obj : objs)
343  {
344  Value propSchema(kObjectType);
345  _addPropertyMapSchema(obj.second, obj.first, allocator, propSchema);
346  oneOf.PushBack(propSchema, allocator);
347  }
348 }
349 
350 // Create JSON schema for an RPC request returning one of the provided property
351 // maps.
353  const RpcDescription& desc,
354  const std::vector<std::pair<std::string, PropertyMap>>& objs)
355 {
356  using namespace rapidjson;
357  auto schema = _buildJsonRpcSchema(desc);
358  auto& allocator = schema.GetAllocator();
359 
360  Value returns(kObjectType);
361  Value oneOf(kArrayType);
362  _addPropertyMapOneOfSchema(objs, allocator, oneOf);
363  returns.AddMember(StringRef("oneOf"), oneOf, allocator);
364  schema.AddMember(StringRef("returns"), returns, allocator);
365 
366  Value params(kArrayType);
367  schema.AddMember(StringRef("params"), params, allocator);
368 
369  StringBuffer buffer;
370  Writer<StringBuffer> writer(buffer);
371  schema.Accept(writer);
372  return buffer.GetString();
373 }
374 
375 // Create JSON schema for an RPC request returning the provided property map.
377  const PropertyMap& obj)
378 {
379  using namespace rapidjson;
380  auto schema = _buildJsonRpcSchema(desc);
381  auto& allocator = schema.GetAllocator();
382 
383  Value returns(kObjectType);
384  _addPropertyMapSchema(obj, "", allocator, returns);
385  schema.AddMember(StringRef("returns"), returns, allocator);
386 
387  Value params(kArrayType);
388  schema.AddMember(StringRef("params"), params, allocator);
389 
390  StringBuffer buffer;
391  Writer<StringBuffer> writer(buffer);
392  schema.Accept(writer);
393  return buffer.GetString();
394 }
395 
396 // Create JSON schema for an RPC request accepting the input property map and
397 // returning the output property map.
399  const RpcParameterDescription& desc, const PropertyMap& input,
400  const PropertyMap& output)
401 {
402  using namespace rapidjson;
403  auto schema = _buildJsonRpcSchema(desc);
404  auto& allocator = schema.GetAllocator();
405 
406  Value returns(kObjectType);
407  _addPropertyMapSchema(output, "", allocator, returns);
408  schema.AddMember(StringRef("returns"), returns, allocator);
409 
410  Value params(kArrayType);
411  Value param(kObjectType);
412  _addPropertyMapSchema(input, desc.paramName, allocator, param);
413  params.PushBack(param, allocator);
414  schema.AddMember(StringRef("params"), params, allocator);
415 
416  StringBuffer buffer;
417  Writer<StringBuffer> writer(buffer);
418  schema.Accept(writer);
419  return buffer.GetString();
420 }
421 
422 // Create JSON schema for an RPC notification accepting one of the provided
423 // property maps.
425  const RpcParameterDescription& desc,
426  const std::vector<std::pair<std::string, PropertyMap>>& objs)
427 {
428  using namespace rapidjson;
429  auto schema = _buildJsonRpcSchema(desc);
430  auto& allocator = schema.GetAllocator();
431 
432  bool retVal;
433  auto retSchema = staticjson::export_json_schema(&retVal);
434  schema.AddMember(StringRef("returns"), retSchema, allocator);
435 
436  Value params(kArrayType);
437  Value oneOf(kArrayType);
438  Value returns(kObjectType);
439  _addPropertyMapOneOfSchema(objs, allocator, oneOf);
440  returns.AddMember(StringRef("oneOf"), oneOf, allocator);
441  params.PushBack(returns, allocator);
442  schema.AddMember(StringRef("params"), params, allocator);
443 
444  StringBuffer buffer;
445  Writer<StringBuffer> writer(buffer);
446  schema.Accept(writer);
447  return buffer.GetString();
448 }
449 
450 // Create JSON schema for an RPC notification accepting the provided property
451 // map.
453  const RpcParameterDescription& desc, const PropertyMap& properties)
454 {
455  using namespace rapidjson;
456  auto schema = _buildJsonRpcSchema(desc);
457  auto& allocator = schema.GetAllocator();
458 
459  bool retVal;
460  auto retSchema = staticjson::export_json_schema(&retVal);
461  schema.AddMember(StringRef("returns"), retSchema, allocator);
462 
463  Value params(kArrayType);
464  Value returns(kObjectType);
465  _addPropertyMapSchema(properties, desc.paramName, allocator, returns);
466  params.PushBack(returns, allocator);
467  schema.AddMember(StringRef("params"), params, allocator);
468 
469  StringBuffer buffer;
470  Writer<StringBuffer> writer(buffer);
471  schema.Accept(writer);
472  return buffer.GetString();
473 }
474 
475 // Create JSON schema for an object where its properties is a oneOf list of the
476 // given property maps.
477 template <>
478 std::string buildJsonSchema(
479  std::vector<std::pair<std::string, PropertyMap>>& objs,
480  const std::string& title)
481 {
482  using namespace rapidjson;
483 
484  Document schema(kObjectType);
485  auto& allocator = schema.GetAllocator();
486  schema.AddMember(StringRef("type"), StringRef("object"), allocator);
487  schema.AddMember(StringRef("title"), StringRef(title.c_str()), allocator);
488  Value oneOf(kArrayType);
489  _addPropertyMapOneOfSchema(objs, allocator, oneOf);
490  schema.AddMember(StringRef("oneOf"), oneOf, allocator);
491 
492  StringBuffer buffer;
493  Writer<StringBuffer> writer(buffer);
494  schema.Accept(writer);
495  return buffer.GetString();
496 }
497 
498 // Create JSON schema for the given property map.
499 template <>
500 std::string buildJsonSchema(const PropertyMap& property,
501  const std::string& title)
502 {
503  using namespace rapidjson;
504 
505  Document schema(kObjectType);
506  auto& allocator = schema.GetAllocator();
507  _addPropertyMapSchema(property, title, allocator, schema);
508 
509  StringBuffer buffer;
510  Writer<StringBuffer> writer(buffer);
511  schema.Accept(writer);
512  return buffer.GetString();
513 }
514 } // namespace core
515 
516 template <>
517 inline std::string to_json(const core::PropertyMap& obj)
518 {
519  using namespace rapidjson;
520  using core::Property;
521  Document json(kObjectType);
522  auto& allocator = json.GetAllocator();
523 
524  for (auto prop : obj.getProperties())
525  {
526  switch (prop->type)
527  {
529  json.AddMember(
530  core::make_json_string(prop->name, allocator).Move(),
531  prop->get<double>(), allocator);
532  break;
533  case Property::Type::Int:
534  if (prop->enums.empty())
535  {
536  json.AddMember(
537  core::make_json_string(prop->name, allocator).Move(),
538  prop->get<int32_t>(), allocator);
539  }
540  else
541  {
542  auto enumStr = matchEnum(prop->enums, prop->get<int32_t>());
543  json.AddMember(
544  core::make_json_string(prop->name, allocator).Move(),
545  core::make_value_string(enumStr, allocator).Move(),
546  allocator);
547  }
548  break;
550  json.AddMember(
551  core::make_json_string(prop->name, allocator).Move(),
552  core::make_value_string(prop->get<std::string>(), allocator)
553  .Move(),
554  allocator);
555  break;
557  json.AddMember(
558  core::make_json_string(prop->name, allocator).Move(),
559  prop->get<bool>(), allocator);
560  break;
562  core::_arrayPropertyToJson<std::array<double, 2>>(json, *prop);
563  break;
565  core::_arrayPropertyToJson<std::array<int32_t, 2>>(json, *prop);
566  break;
568  core::_arrayPropertyToJson<std::array<double, 3>>(json, *prop);
569  break;
571  core::_arrayPropertyToJson<std::array<int32_t, 3>>(json, *prop);
572  break;
574  core::_arrayPropertyToJson<std::array<double, 4>>(json, *prop);
575  break;
576  }
577  }
578 
579  StringBuffer buffer;
580  Writer<StringBuffer> writer(buffer);
581  json.Accept(writer);
582  return buffer.GetString();
583 }
584 
586 
587 template <typename T>
588 T getValue(const rapidjson::GenericValue<rapidjson::UTF8<>>& v);
589 template <>
590 double getValue(const rapidjson::GenericValue<rapidjson::UTF8<>>& v)
591 {
592  return v.GetDouble();
593 }
594 template <>
595 int32_t getValue(const rapidjson::GenericValue<rapidjson::UTF8<>>& v)
596 {
597  return v.GetInt();
598 }
599 template <>
600 std::string getValue(const rapidjson::GenericValue<rapidjson::UTF8<>>& v)
601 {
602  return v.GetString();
603 }
604 template <>
605 bool getValue(const rapidjson::GenericValue<rapidjson::UTF8<>>& v)
606 {
607  return v.GetBool();
608 }
609 
611 
612 template <typename T>
613 bool isValue(const rapidjson::GenericValue<rapidjson::UTF8<>>& v);
614 template <>
615 bool isValue<double>(const rapidjson::GenericValue<rapidjson::UTF8<>>& v)
616 {
617  return v.IsDouble();
618 }
619 template <>
620 bool isValue<int>(const rapidjson::GenericValue<rapidjson::UTF8<>>& v)
621 {
622  return v.IsInt();
623 }
624 template <>
625 bool isValue<std::string>(const rapidjson::GenericValue<rapidjson::UTF8<>>& v)
626 {
627  return v.IsString();
628 }
629 template <>
630 bool isValue<bool>(const rapidjson::GenericValue<rapidjson::UTF8<>>& v)
631 {
632  return v.IsBool();
633 }
634 
636 
637 template <typename T, size_t S>
638 bool get_array(const rapidjson::Value& v, std::array<T, S>& val)
639 {
640  if (!(v.IsArray() && v.Size() == S))
641  return false;
642 
643  int j = 0;
644  for (const auto& i : v.GetArray())
645  {
646  if (!isValue<T>(i))
647  return false;
648  val[j++] = getValue<T>(i);
649  }
650  return true;
651 }
652 template <typename T>
653 bool get_property(const rapidjson::Value& v, T& val)
654 {
655  if (!isValue<T>(v))
656  return false;
657  val = getValue<T>(v);
658 
659  return true;
660 }
661 
662 template <>
663 inline bool from_json(core::PropertyMap& obj, const std::string& json)
664 {
665  obj.merge(jsonToPropertyMap(json));
666  return true;
667 }
668 
669 core::PropertyMap jsonToPropertyMap(const std::string& json)
670 {
671  using namespace rapidjson;
672  using core::Property;
673  Document document;
674  document.Parse(json.c_str());
675 
676  core::PropertyMap map;
677 
678  if (!document.IsObject())
679  return map;
680 
681  for (const auto& m : document.GetObject())
682  {
683  const auto propName = core::snakeCaseToCamelCase(m.name.GetString());
684 
685  const auto trySetProperty = [&](auto val) {
686  if (get_property(m.value, val))
687  {
688  map.setProperty({propName, val, {propName}});
689  return true;
690  }
691  return false;
692  };
693 
694  const auto trySetArray = [&](auto val) {
695  if (get_array(m.value, val))
696  {
697  map.setProperty({propName, val, {propName}});
698  return true;
699  }
700  return false;
701  };
702 
703  if (trySetProperty(double(0)))
704  continue;
705  if (trySetProperty(int32_t(0)))
706  continue;
707  if (trySetProperty(std::string("")))
708  continue;
709  if (trySetProperty(bool(false)))
710  continue;
711  if (trySetArray(std::array<double, 2>{{0, 0}}))
712  continue;
713  if (trySetArray(std::array<int32_t, 2>{{0, 0}}))
714  continue;
715  if (trySetArray(std::array<double, 3>{{0, 0, 0}}))
716  continue;
717  if (trySetArray(std::array<int32_t, 3>{{0, 0, 0}}))
718  continue;
719  if (trySetArray(std::array<double, 4>{{0, 0, 0, 0}}))
720  continue;
721  }
722 
723  return map;
724 }
void setProperty(const Property &newProperty)
Definition: PropertyMap.h:307
const auto & getProperties() const
Definition: PropertyMap.h:373
void merge(const PropertyMap &input)
bool get_array(const rapidjson::Value &v, std::array< T, S > &val)
T getValue(const rapidjson::GenericValue< rapidjson::UTF8<>> &v)
std::string to_json(const core::PropertyMap &obj)
bool isValue(const rapidjson::GenericValue< rapidjson::UTF8<>> &v)
bool isValue< double >(const rapidjson::GenericValue< rapidjson::UTF8<>> &v)
core::PropertyMap jsonToPropertyMap(const std::string &json)
bool isValue< bool >(const rapidjson::GenericValue< rapidjson::UTF8<>> &v)
bool get_property(const rapidjson::Value &v, T &val)
bool isValue< int >(const rapidjson::GenericValue< rapidjson::UTF8<>> &v)
std::string separatedToCamelCase(const std::string &separated, const char separator)
Definition: StringUtils.cpp:74
std::string camelCaseToSeparated(const std::string &camelCase, const char separator)
Definition: StringUtils.cpp:57
std::string buildJsonRpcSchemaRequestPropertyMaps(const RpcDescription &desc, const std::vector< std::pair< std::string, PropertyMap >> &objs)
std::string buildJsonRpcSchemaNotifyPropertyMaps(const RpcParameterDescription &desc, const std::vector< std::pair< std::string, PropertyMap >> &objs)
void _addPropertyMapSchema(const PropertyMap &propertyMap, const std::string &title, rapidjson::Document::AllocatorType &allocator, rapidjson::Value &propSchema)
rapidjson::Document _buildJsonRpcSchema(const RpcDescription &desc)
Definition: jsonUtils.h:78
bool from_json(T &obj, const std::string &json, PRE preUpdateFunc=[] {}, POST postUpdateFunc=[] {})
std::string buildJsonSchema(std::vector< std::pair< std::string, PropertyMap >> &objs, const std::string &title)
std::string buildJsonRpcSchemaRequestPropertyMap(const RpcDescription &desc, const PropertyMap &obj)
std::string buildJsonRpcSchemaNotifyPropertyMap(const RpcParameterDescription &desc, const PropertyMap &properties)
void _addPropertyMapOneOfSchema(const std::vector< std::pair< std::string, PropertyMap >> &objs, rapidjson::Document::AllocatorType &allocator, rapidjson::Value &oneOf)
@ vector
Definition: CommonTypes.h:68