Skip to content

Commit 82ad919

Browse files
author
Andres Sevillano
committed
Remove confusing bookmarks elements
1 parent 2f408a0 commit 82ad919

File tree

2 files changed

+43
-39
lines changed

2 files changed

+43
-39
lines changed

json/schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
"imp": {
2323
"description": "Impressions rock",
2424
"type": "array",
25+
"title": "Impression",
2526
"metatype": "std::vector<Impression>",
26-
"bookmarkSource": "#impression",
2727
"items": {
28-
"title": "Impression",
29-
"bookmarkTarget": "impression",
3028
"type": "object",
29+
"title": "Impression",
3130
"metatype" : "struct Impression",
3231
"properties": {
3332
"id": {
@@ -95,6 +94,7 @@
9594
"deals": {
9695
"type": "array",
9796
"metatype": "std::vector<Deal>",
97+
"title": "Deal",
9898
"items": {
9999
"title": "Deal",
100100
"type": "object",

src/boilerplateCodeDoc.cpp

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,25 @@ using Required = std::vector<std::string>;
145145
using OneOf = std::vector<Required>;
146146
struct Property {
147147
bool required {false};
148+
std::string element {};
148149
std::string scope {};
149150
std::string name {};
150151
std::string type {};
151152
std::string description {};
152153
std::string title {};
153154
std::string parentTitle {};
155+
std::string parentType {};
154156
std::string metatype {};
155157
std::string parentMetatype {};
156158
std::string metainfo {};
157159
std::string bookmark_source {};
158160
std::string bookmark_target {};
159-
Property(bool req, std::string sco, std::string nam, std::string typ, std::string des, std::string tit,
161+
Property(bool req, std::string elm, std::string sco, std::string nam, std::string typ, std::string ptyp, std::string des, std::string tit,
160162
std::string par, std::string met, std::string pm, std::string inf, std::string bs, std::string bt)
161-
: required{req}, scope{std::move(sco)}, name{std::move(nam)}, type{std::move(typ)}, description{std::move(des)}, title{std::move(tit)},
162-
parentTitle{std::move(par)}, metatype{std::move(met)}, parentMetatype{std::move(pm)}, metainfo{std::move(inf)},
163+
: required{req}, element{std::move(elm)},
164+
scope{std::move(sco)}, name{std::move(nam)}, type{std::move(typ)}, parentType{std::move(ptyp)},
165+
description{std::move(des)}, title{std::move(tit)}, parentTitle{std::move(par)},
166+
metatype{std::move(met)}, parentMetatype{std::move(pm)}, metainfo{std::move(inf)},
163167
bookmark_source{std::move(bs)}, bookmark_target{std::move(bt)} {}
164168
};
165169
using Properties = std::map<std::string, Property>;
@@ -209,9 +213,21 @@ static void processProperties(const OneOf& oneOf, const Required& required, Prop
209213
}
210214
}
211215

212-
// by default "scope" will be "optional"
213216
for(auto&& p : properties) {
214-
if( p.second.scope.empty() ) { p.second.scope = "optional"; }
217+
218+
auto&& e {p.second}; //alias
219+
220+
// by default "scope" will be "optional"
221+
if( e.scope.empty() ) { e.scope = "optional"; }
222+
223+
// get ready in a lazy way for HTML table internal links
224+
if (e.type == "object" || e.type == "array" ) {
225+
if( e.bookmark_source.empty() ) { e.bookmark_source = "#" + (e.title.empty()?e.parentTitle:e.title); }
226+
}
227+
if( e.parentType == "object" || e.parentType == "array" ) {
228+
if( e.bookmark_target.empty() ) { e.bookmark_target = e.parentTitle; }
229+
}
230+
215231
}
216232

217233
}
@@ -258,9 +274,11 @@ static void SetProperties(const rapidjson::Document& document, std::string eleme
258274
std::string title {}; // optional
259275
getString(document, element, "/properties/", name, "/title", title);
260276
std::string parentTitle {}; // optional
261-
getString(document, element, "", "", "/title", parentTitle);
277+
getString(document, element, "", "", "/title", parentTitle);
262278
std::string parentMetatype {}; // required
263279
if(not getString(document, element, "", "", "/metatype", parentMetatype)) { continue; }
280+
std::string parentType {}; // required
281+
if(not getString(document, element, "", "", "/type", parentType)) { continue; }
264282
std::string metatype {}; // required
265283
if(not getString(document, element, "/properties/", name, "/metatype", metatype)) { continue; }
266284
std::string metainfo {}; // optional
@@ -271,7 +289,7 @@ static void SetProperties(const rapidjson::Document& document, std::string eleme
271289
getString(document, element, "/properties/", name, "/bookmarkSource", bookmark_source);
272290
std::string bookmark_target {}; // optional
273291
getString(document, element, "", "", "/bookmarkTarget", bookmark_target);
274-
properties.emplace(std::make_pair(name, Property{false, scope, name, type, description, title,
292+
properties.emplace(std::make_pair(name, Property{false, element, scope, name, type, parentType, description, title,
275293
parentTitle, metatype, parentMetatype, metainfo, bookmark_source, bookmark_target}));
276294
}
277295

@@ -288,10 +306,12 @@ static void SetProperties(const rapidjson::Document& document, std::string eleme
288306
getString(document, element, "/items/properties/", name, "/description", description);
289307
std::string title {}; // optional
290308
getString(document, element, "/items/properties/", name, "/title", title);
291-
std::string parentTitle {}; // optional
309+
std::string parentTitle {}; // optional
292310
getString(document, element, "/items", "", "/title", parentTitle);
293-
std::string parentMetatype {}; // optional
294-
getString(document, element, "/items", "", "/metatype", parentMetatype);
311+
std::string parentType {}; // required
312+
if(not getString(document, element, "/items", "", "/type", parentType)) { continue; }
313+
std::string parentMetatype {}; // required
314+
if(not getString(document, element, "/items", "", "/metatype", parentMetatype)) { continue; }
295315
std::string metatype {}; // optional
296316
getString(document, element, "/items/properties/", name, "/metatype", metatype);
297317
std::string metainfo {}; // optional
@@ -302,7 +322,7 @@ static void SetProperties(const rapidjson::Document& document, std::string eleme
302322
getString(document, element, "/items/properties/", name, "/bookmarkSource", bookmark_source);
303323
std::string bookmark_target {}; // optional
304324
getString(document, element, "/items", "", "/bookmarkTarget", bookmark_target);
305-
properties.emplace(std::make_pair(name, Property{false, scope, name, type, description, title,
325+
properties.emplace(std::make_pair(name, Property{false, element, scope, name, type, parentType, description, title,
306326
parentTitle, metatype, parentMetatype, metainfo, bookmark_source, bookmark_target}));
307327
}
308328

@@ -323,7 +343,7 @@ static void SetProperties(const rapidjson::Document& document, std::string eleme
323343
oneOf.emplace_back(temp);
324344
}
325345
}
326-
}
346+
}
327347
}
328348
processProperties(oneOf, required, properties); // what is required
329349
lambda(properties); // apply filter
@@ -509,46 +529,30 @@ if( not jsonSchema.cpp_filename.empty() && not header.empty() ) {
509529
}
510530
return boilerplateOperator(jsonSchema, *this, [this, namespace_id = jsonSchema.namespace_id](const Properties& properties) {
511531

512-
/*
532+
static std::string rapidjsonPointerInfo {};
533+
513534
if(properties.size() > 0) {
514535

515536
// supposed metatype is a must
516-
std::string parentMetatype {};
517-
parentMetatype = properties.begin()->second.parentMetatype;
518-
if( parentMetatype.empty() ) { return; } // required
537+
std::string parentType {};
538+
parentType = properties.begin()->second.parentType;
539+
if( parentType.empty() ) { return; } // required
519540

520541
// if nothing is implemented, do nothing
521542
bool nothing_implemented {true};
522543
for(const auto& p : properties) {
523544
if( implemented(p.second.metainfo) ) { nothing_implemented = false; break; }
524545
}
525546
if( nothing_implemented ) {
526-
filtered = "\n// " + parentMetatype + ": all their properties are not implemented\n\n" + filtered;
547+
filtered = "\n// " + parentType + ": all their properties are not implemented\n\n" + filtered;
527548
return;
528549
}
529550

530-
std::string addition {};
531-
if( not namespace_id.empty() ) { addition += "namespace " + namespace_id + " {\n"; }
532-
addition += "\n" + parentMetatype + " {\n\n";
533-
534-
for(const auto& p : properties) {
535-
536-
if( not implemented(p.second.metainfo) ) { addition += "// " + p.second.name + ": " + p.second.metainfo + "\n"; continue; }
537-
538-
std::string metatype {p.second.metatype};
539-
if( metatype.empty() ) { continue; } // required
540-
std::string name {p.second.name};
541-
if( name.empty() ) { continue; } // required
542-
543-
if( not p.second.description.empty() ) { addition += "///@ brief " + p.second.description + "\n"; }
544-
addition += metatype + " " + name + " {};\n";
545-
}
551+
rapidjsonPointerInfo += properties.begin()->second.element + "\n";
546552

547-
addition += "\n}; // " + parentMetatype + "\n";
548-
if( not namespace_id.empty() ) { addition += "\n} // namespace " + namespace_id + "\n\n"; }
553+
std::string addition {rapidjsonPointerInfo + "\n"};
549554

550555
filtered = addition + filtered;
551556
}
552-
*/
553557
}); // return boilerplateOperator
554558
} // operator()

0 commit comments

Comments
 (0)