@@ -142,13 +142,14 @@ struct Property {
142
142
std::string title {};
143
143
std::string parentTitle {};
144
144
std::string metatype {};
145
+ std::string parentMetatype {};
145
146
std::string metainfo {};
146
147
std::string bookmark_source {};
147
148
std::string bookmark_target {};
148
149
Property (bool req, std::string sco, std::string nam, std::string typ, std::string des, std::string tit,
149
- std::string par, std::string met, std::string inf, std::string bs, std::string bt)
150
+ std::string par, std::string met, std::string pm, std::string inf, std::string bs, std::string bt)
150
151
: required{req}, scope{std::move (sco)}, name{std::move (nam)}, type{std::move (typ)}, description{std::move (des)}, title{std::move (tit)},
151
- parentTitle{std::move (par)}, metatype{std::move (met)}, metainfo{std::move (inf)},
152
+ parentTitle{std::move (par)}, metatype{std::move (met)}, parentMetatype{ std::move (pm)}, metainfo{std::move (inf)},
152
153
bookmark_source{std::move (bs)}, bookmark_target{std::move (bt)} {}
153
154
};
154
155
using Properties = std::map<std::string, Property>;
@@ -248,8 +249,10 @@ static void SetProperties(const rapidjson::Document& document, std::string eleme
248
249
getString (document, element, " /properties/" , name, " /title" , title);
249
250
std::string parentTitle {}; // optional
250
251
getString (document, element, " " , " " , " /title" , parentTitle);
251
- std::string metatype {}; // optional
252
- getString (document, element, " /properties/" , name, " /metatype" , metatype);
252
+ std::string parentMetatype {}; // required
253
+ if (not getString (document, element, " " , " " , " /metatype" , parentMetatype)) { continue ; }
254
+ std::string metatype {}; // required
255
+ if (not getString (document, element, " /properties/" , name, " /metatype" , metatype)) { continue ; }
253
256
std::string metainfo {}; // optional
254
257
getString (document, element, " /properties/" , name, " /metainfo" , metainfo);
255
258
std::string scope {}; // optional
@@ -259,7 +262,7 @@ static void SetProperties(const rapidjson::Document& document, std::string eleme
259
262
std::string bookmark_target {}; // optional
260
263
getString (document, element, " " , " " , " /bookmarkTarget" , bookmark_target);
261
264
properties.emplace (std::make_pair (name, Property{false , scope, name, type, description, title,
262
- parentTitle, metatype, metainfo, bookmark_source, bookmark_target}));
265
+ parentTitle, metatype, parentMetatype, metainfo, bookmark_source, bookmark_target}));
263
266
}
264
267
265
268
nextElement = element + " /properties/" ; // recursive call
@@ -277,6 +280,8 @@ static void SetProperties(const rapidjson::Document& document, std::string eleme
277
280
getString (document, element, " /items/properties/" , name, " /title" , title);
278
281
std::string parentTitle {}; // optional
279
282
getString (document, element, " /items" , " " , " /title" , parentTitle);
283
+ std::string parentMetatype {}; // optional
284
+ getString (document, element, " /items" , " " , " /metatype" , parentMetatype);
280
285
std::string metatype {}; // optional
281
286
getString (document, element, " /items/properties/" , name, " /metatype" , metatype);
282
287
std::string metainfo {}; // optional
@@ -288,7 +293,7 @@ static void SetProperties(const rapidjson::Document& document, std::string eleme
288
293
std::string bookmark_target {}; // optional
289
294
getString (document, element, " /items" , " " , " /bookmarkTarget" , bookmark_target);
290
295
properties.emplace (std::make_pair (name, Property{false , scope, name, type, description, title,
291
- parentTitle, metatype, metainfo, bookmark_source, bookmark_target}));
296
+ parentTitle, metatype, parentMetatype, metainfo, bookmark_source, bookmark_target}));
292
297
}
293
298
294
299
nextElement = element + " /items/properties/" ; // recursive call
@@ -401,3 +406,70 @@ bool boilerplateCodeDoc::JsonSchema2HTML::operator()(const boilerplateCodeDoc::J
401
406
return false ;
402
407
}
403
408
}
409
+
410
+ /* ***************************************************************************************/
411
+ /* ***************************************************************************************/
412
+ /* ***************************************************************************************/
413
+ /* ********************** ACTUAL LOGIC CODE **********************************************/
414
+ /* ***************************************************************************************/
415
+ /* ***************************************************************************************/
416
+ /* ***************************************************************************************/
417
+
418
+ static lambda_t cpp = [](const Properties& properties, std::string& filtered, std::string& namespace_id)
419
+ {
420
+ if (properties.size () > 0 ) {
421
+
422
+ // supposed metatype is a must
423
+ std::string parentMetatype {};
424
+ if ( properties.size () > 0 ) {
425
+ parentMetatype = properties.begin ()->second .parentMetatype ;
426
+ }
427
+ if ( parentMetatype.empty () ) { return ; } // required
428
+
429
+ for (const auto & p : properties) {
430
+
431
+ std::string metatype {p.second .metatype };
432
+ if ( metatype.empty () ) { return ; } // required
433
+
434
+ filtered += " \n parentMetatype: " + p.second .parentMetatype ;
435
+ filtered += " \n name: " + p.second .name ;
436
+ filtered += " \n metatype: " + p.second .metatype ;
437
+ filtered += " \n description: " + p.second .description ;
438
+ filtered += " \n\n " ;
439
+ }
440
+
441
+ }
442
+ };
443
+
444
+ bool boilerplateCodeDoc::JsonSchema2CPP::operator ()(const boilerplateCodeDoc::JsonSchema& jsonSchema)
445
+ {
446
+ if ( not jsonSchema.document_ptr ) {
447
+ error = boilerplateCodeDoc::ParseErrorCode::ERROR_PARSING_SCHEMA_JSON;
448
+ message = " Empty document pointer" ;
449
+ return false ;
450
+ }
451
+
452
+ rapidjson::Document& document {*reinterpret_cast <rapidjson::Document*>(jsonSchema.document_ptr )};
453
+ try {
454
+ if (document.IsNull () || not document.IsObject () ) {
455
+ error = boilerplateCodeDoc::ParseErrorCode::ERROR_PARSING_SCHEMA_JSON;
456
+ message = " Root element shouldn't be NULL" ;
457
+ return false ;
458
+ }
459
+
460
+ // std::string element {"#/properties/imp/items/properties/native"};
461
+ std::string element {" #" };
462
+ filtered = header;
463
+ SetProperties (document, element, filtered, cpp, namespace_id);
464
+ filtered += footer;
465
+
466
+ error = boilerplateCodeDoc::ParseErrorCode::OK;
467
+ message = to_string (error);
468
+ return true ;
469
+
470
+ } catch (...) {
471
+ error = boilerplateCodeDoc::ParseErrorCode::ERROR_PARSING_SCHEMA_JSON;
472
+ message = " Unexpected exception" ;
473
+ return false ;
474
+ }
475
+ }
0 commit comments