Skip to content

Commit 6fc4b73

Browse files
committed
Added annotations collection
1 parent 2f19e75 commit 6fc4b73

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

modules/json-schema-forms.js

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,7 @@ $RefParser.dereference(url, (err, schema) => {
1515
});
1616
}
1717

18-
function generate(schema, title) {/*
19-
const cssLink = document.head.appendChild(
20-
document.createElement("link")
21-
);
22-
23-
cssLink.rel = "stylesheet";
24-
cssLink.type = "text/css";
25-
cssLink.href = "json-schema-forms.css";*/
18+
function generate(schema, title) {
2619
const form = document.createElement("form");
2720
form.classList.add("form-inline");
2821
form.appendChild(create(schema, title, {activated: true, required: true, enabled: true}));
@@ -46,7 +39,7 @@ function create(instance, id, state, arrayDatalist = null) {
4639
break;
4740

4841
case "boolean":
49-
element = (new JSCHBoolean(id, state)).instanceDiv;
42+
element = (new JSCHBoolean(id, instance, state)).instanceDiv;
5043
break;
5144

5245
case "integer":
@@ -240,7 +233,7 @@ class JSCHOneOf extends JSCHAnyOf {
240233
}
241234

242235
class JSCHInstance {
243-
constructor(id, state) {
236+
constructor(id, instance, state) {
244237
this.instanceDiv = document.createElement("div");
245238
this.instanceDiv.id = id;
246239
this.instanceDiv.classList.add("jsch-instance", "container-fluid");
@@ -252,6 +245,8 @@ class JSCHInstance {
252245

253246
this.headerDiv.classList.add("form-group");
254247

248+
this.annotations = collectAnnotations(instance);
249+
255250
if(state.required)
256251
this.instanceDiv.classList.add("required");
257252
else {
@@ -338,7 +333,7 @@ class JSCHInstance {
338333

339334
class JSCHUntyped extends JSCHInstance {
340335
constructor(id, instance, state, arrayDatalist = null) {
341-
super(id, state);
336+
super(id, instance, state);
342337

343338
this.instanceDiv.classList.add("jsch-untyped");
344339
this.headerDiv.appendChild(
@@ -421,7 +416,7 @@ class JSCHUntyped extends JSCHInstance {
421416

422417
class JSCHConst extends JSCHInstance {
423418
constructor(id, instance, state) {
424-
super(id, state);
419+
super(id, instance, state);
425420

426421
this.instanceDiv.classList.add("jsch-const");
427422
this.instanceDiv.classList.add("form-group");
@@ -468,7 +463,7 @@ class JSCHConst extends JSCHInstance {
468463

469464
class JSCHNull extends JSCHInstance {
470465
constructor(id, instance, state) {
471-
super(id, state);
466+
super(id, instance, state);
472467

473468
this.instanceDiv.classList.add("jsch-null");
474469
this.instanceDiv.classList.add("form-group");
@@ -523,7 +518,7 @@ class JSCHNull extends JSCHInstance {
523518

524519
class JSCHObject extends JSCHInstance {
525520
constructor(id, instance, state, arrayDatalist = null) {
526-
super(id, state);
521+
super(id, instance, state);
527522

528523
this.instanceDiv.classList.add("jsch-object");
529524
this.headerDiv.appendChild(
@@ -775,7 +770,7 @@ class JSCHObject extends JSCHInstance {
775770

776771
class JSCHArray extends JSCHInstance {
777772
constructor(id, instance, state, arrayDatalist = null) {
778-
super(id, state);
773+
super(id, instance, state);
779774

780775
this.instanceDiv.classList.add("jsch-array");
781776
this.headerDiv.appendChild(
@@ -954,8 +949,8 @@ class JSCHArray extends JSCHInstance {
954949
}
955950

956951
class JSCHLiteralInstance extends JSCHInstance {
957-
constructor(id, state) {
958-
super(id, state);
952+
constructor(id, instance, state) {
953+
super(id, instance, state);
959954

960955
this.instanceDiv.classList.add("form-group");
961956

@@ -1019,8 +1014,8 @@ class JSCHLiteralInstance extends JSCHInstance {
10191014
}
10201015

10211016
class JSCHBoolean extends JSCHLiteralInstance {
1022-
constructor(id, state) {
1023-
super(id, state);
1017+
constructor(id, instance, state) {
1018+
super(id, instance, state);
10241019

10251020
this.instanceDiv.classList.add("jsch-boolean");
10261021
this.instanceDiv.classList.add("custom-control", "custom-checkbox");
@@ -1056,7 +1051,7 @@ class JSCHBoolean extends JSCHLiteralInstance {
10561051

10571052
class JSCHString extends JSCHLiteralInstance {
10581053
constructor(id, instance, state, arrayDatalist = null) {
1059-
super(id, state);
1054+
super(id, instance, state);
10601055

10611056
this.instanceDiv.classList.add("jsch-string");
10621057
this.extractKeywords(instance);
@@ -1121,7 +1116,7 @@ class JSCHString extends JSCHLiteralInstance {
11211116

11221117
class JSCHInteger extends JSCHLiteralInstance {
11231118
constructor(id, instance, state, arrayDatalist = null) {
1124-
super(id, state);
1119+
super(id, instance, state);
11251120

11261121
this.instanceDiv.classList.add("jsch-integer");
11271122
this.extractKeywords(instance);
@@ -1193,7 +1188,7 @@ class JSCHInteger extends JSCHLiteralInstance {
11931188

11941189
class JSCHNumber extends JSCHLiteralInstance {
11951190
constructor(id, instance, state, arrayDatalist = null) {
1196-
super(id, state);
1191+
super(id, instance, state);
11971192

11981193
this.instanceDiv.classList.add("jsch-number");
11991194
this.extractKeywords(instance);
@@ -1367,6 +1362,24 @@ function beautifyId(id) {
13671362
return id.split("__").pop();
13681363
}
13691364

1365+
function collectAnnotations(instance) {
1366+
const annotations = new Object();
1367+
1368+
if(instance.title !== undefined)
1369+
annotations.title = instance.title;
1370+
1371+
if(instance.description !== undefined)
1372+
annotations.description = instance.description;
1373+
1374+
if(instance.default !== undefined)
1375+
annotations.default = instance.default;
1376+
1377+
if(instance.examples !== undefined)
1378+
annotations.examples = instance.examples;
1379+
1380+
return annotations;
1381+
}
1382+
13701383
function htmlizeRegex(pattern) {
13711384
// TODO
13721385
return pattern;

0 commit comments

Comments
 (0)