6
6
class JSONSchemaMarkdown {
7
7
constructor ( ) {
8
8
/**
9
- * Object containing the schema
9
+ * Object containing the schema
10
10
* @type {Object }
11
11
*/
12
12
this . schema = null ;
@@ -113,7 +113,7 @@ class JSONSchemaMarkdown {
113
113
// set this as base path to children.
114
114
path = "#" + data [ "$id" ] ;
115
115
}
116
- //
116
+ //
117
117
this . typeGeneric ( name , data , level , path ) ;
118
118
119
119
if ( typeof data . type === "string" ) {
@@ -133,7 +133,7 @@ class JSONSchemaMarkdown {
133
133
}
134
134
}
135
135
}
136
-
136
+
137
137
/**
138
138
* This is the shared template for all other types.
139
139
* You may want to override this method to change the order of information in your documentation.
@@ -157,7 +157,7 @@ class JSONSchemaMarkdown {
157
157
}
158
158
159
159
/**
160
- *
160
+ *
161
161
* @param {name } name The JSON property name
162
162
* @param {Object } data The JS data for the schema
163
163
* @param {integer } level Indentation level
@@ -186,29 +186,29 @@ class JSONSchemaMarkdown {
186
186
}
187
187
188
188
/**
189
- *
189
+ *
190
190
* @param {name } name The JSON property name
191
191
* @param {Object } data The JS data for the schema
192
192
* @param {integer } level Indentation level
193
193
* @param {String } path String describing the path of the property
194
194
*/
195
195
typeBoolean ( name , data , level , path ) {
196
-
196
+
197
197
}
198
198
199
199
/**
200
- *
200
+ *
201
201
* @param {name } name The JSON property name
202
202
* @param {Object } data The JS data for the schema
203
203
* @param {integer } level Indentation level
204
204
* @param {String } path String describing the path of the property
205
205
*/
206
206
typeNull ( name , data , level , path ) {
207
-
207
+
208
208
}
209
209
210
210
/**
211
- *
211
+ *
212
212
* @param {name } name The JSON property name
213
213
* @param {Object } data The JS data for the schema
214
214
* @param {integer } level Indentation level
@@ -229,7 +229,7 @@ class JSONSchemaMarkdown {
229
229
}
230
230
231
231
/**
232
- *
232
+ *
233
233
* @param {name } name The JSON property name
234
234
* @param {Object } data The JS data for the schema
235
235
* @param {integer } level Indentation level
@@ -247,7 +247,7 @@ class JSONSchemaMarkdown {
247
247
}
248
248
249
249
/**
250
- *
250
+ *
251
251
* @param {name } name The JSON property name
252
252
* @param {Object } data The JS data for the schema
253
253
* @param {integer } level Indentation level
@@ -313,11 +313,11 @@ class JSONSchemaMarkdown {
313
313
* @see https://json-schema.org/understanding-json-schema/reference/object.html#property-names
314
314
* @param {boolean } bool
315
315
* @param {Integer } level Indentation level
316
- *
316
+ *
317
317
*/
318
318
writeAdditionalProperties ( bool , level ) {
319
319
if ( this . notEmpty ( bool ) ) {
320
- if ( bool ) {
320
+ if ( ! bool ) {
321
321
this . writeLine ( "This schema <u>does not</u> accept additional properties." , level ) ;
322
322
} else {
323
323
this . writeLine ( "This schema accepts additional properties." , level ) ;
@@ -330,7 +330,7 @@ class JSONSchemaMarkdown {
330
330
* @see https://json-schema.org/understanding-json-schema/reference/generic.html#comments
331
331
* @param {String } comment The comment
332
332
* @param {Integer } level Indentation level
333
- *
333
+ *
334
334
*/
335
335
writeComment ( comment , level ) {
336
336
if ( this . notEmpty ( comment ) ) {
@@ -343,7 +343,7 @@ class JSONSchemaMarkdown {
343
343
* @see https://json-schema.org/understanding-json-schema/reference/generic.html
344
344
* @param {* } value The default value
345
345
* @param {Integer } level Indentation level
346
- *
346
+ *
347
347
*/
348
348
writeDefault ( value , level ) {
349
349
if ( this . notEmpty ( value ) ) {
@@ -356,7 +356,7 @@ class JSONSchemaMarkdown {
356
356
* @see https://json-schema.org/understanding-json-schema/reference/generic.html
357
357
* @param {String } description The description may include markdown
358
358
* @param {Integer } level Indentation level
359
- *
359
+ *
360
360
*/
361
361
writeDescription ( description , level ) {
362
362
if ( this . notEmpty ( description ) ) {
@@ -368,7 +368,7 @@ class JSONSchemaMarkdown {
368
368
* Write *.enum as a list.
369
369
* @param {array } list Enumerated values
370
370
* @param {Integer } level Indentation level
371
- *
371
+ *
372
372
*/
373
373
writeEnum ( list , level ) {
374
374
if ( this . notEmpty ( list ) ) {
@@ -381,7 +381,7 @@ class JSONSchemaMarkdown {
381
381
* @see https://json-schema.org/understanding-json-schema/reference/string.html#format
382
382
* @param {String } format Format of string
383
383
* @param {Integer } level Indentation level
384
- *
384
+ *
385
385
*/
386
386
writeFormat ( format , level ) {
387
387
if ( this . notEmpty ( format ) ) {
@@ -394,7 +394,7 @@ class JSONSchemaMarkdown {
394
394
* @see https://json-schema.org/understanding-json-schema/reference/generic.html
395
395
* @param {array } list Examples
396
396
* @param {Integer } level Indentation level
397
- *
397
+ *
398
398
*/
399
399
writeExamples ( list , level ) {
400
400
if ( this . notEmpty ( list ) ) {
@@ -406,7 +406,7 @@ class JSONSchemaMarkdown {
406
406
/**
407
407
* @param {String } header The header to be written
408
408
* @param {Integer } level Header level [H1, H2, H3, H4, H5]
409
- *
409
+ *
410
410
*/
411
411
writeHeader ( header , level = 1 ) {
412
412
if ( this . notEmpty ( header ) ) {
@@ -419,7 +419,7 @@ class JSONSchemaMarkdown {
419
419
* @see https://json-schema.org/understanding-json-schema/structuring.html#the-id-property
420
420
* @param {String } id the schema's $id
421
421
* @param {Integer } level Indentation level
422
- *
422
+ *
423
423
*/
424
424
writeId ( id , level ) {
425
425
if ( this . notEmpty ( id ) ) {
@@ -431,7 +431,7 @@ class JSONSchemaMarkdown {
431
431
* Write array as markdown list
432
432
* @param {array } list Mixed array to list
433
433
* @param {Integer } level Indentation level
434
- *
434
+ *
435
435
*/
436
436
writeList ( list , level = 1 ) {
437
437
if ( this . notEmpty ( list ) ) {
@@ -446,7 +446,7 @@ class JSONSchemaMarkdown {
446
446
* Write notation for inclusive minimum and maximum.
447
447
* @param {number } min Inclusive minimim
448
448
* @param {number } max Inclusive maximum
449
- *
449
+ *
450
450
*/
451
451
writeMinMax ( min , max ) {
452
452
if ( this . notEmpty ( min ) && this . notEmpty ( max ) ) {
@@ -462,7 +462,7 @@ class JSONSchemaMarkdown {
462
462
* Write notation for exclusive minimum and maximum.
463
463
* @param {number } min Exclusive minimim
464
464
* @param {number } max Exclusive maximum
465
- *
465
+ *
466
466
*/
467
467
writeMinMaxExlusive ( min , max ) {
468
468
if ( this . notEmpty ( min ) ) {
@@ -480,7 +480,7 @@ class JSONSchemaMarkdown {
480
480
* @see https://json-schema.org/understanding-json-schema/reference/numeric.html#multiples
481
481
* @param {Number } number Regular Expression that string must match.
482
482
* @param {Integer } level Indentation level
483
- *
483
+ *
484
484
*/
485
485
writeMultipleOf ( number , level ) {
486
486
if ( this . notEmpty ( number ) ) {
@@ -492,7 +492,7 @@ class JSONSchemaMarkdown {
492
492
* @see https://json-schema.org/understanding-json-schema/reference/string.html#regular-expressions
493
493
* @param {String } pattern Regular Expression that string must match.
494
494
* @param {Integer } level Indentation level
495
- *
495
+ *
496
496
*/
497
497
writePattern ( pattern , level ) {
498
498
if ( this . notEmpty ( pattern ) ) {
@@ -505,7 +505,7 @@ class JSONSchemaMarkdown {
505
505
* @see https://json-schema.org/understanding-json-schema/reference/object.html#property-names
506
506
* @param {String } data Schema object
507
507
* @param {Integer } level Indentation level
508
- *
508
+ *
509
509
*/
510
510
writePropertyNames ( data , level ) {
511
511
if ( this . notEmpty ( data ) && this . notEmpty ( data . pattern ) ) {
@@ -518,7 +518,7 @@ class JSONSchemaMarkdown {
518
518
* @param {Integer } level Indentation level
519
519
* @param {String } path String describing the path of the property
520
520
* @param {boolean } required Property is required (True or False [default])
521
- *
521
+ *
522
522
*/
523
523
writePropertyName ( prop , level , path , required = false ) {
524
524
this . indent ( level ) ;
@@ -534,7 +534,7 @@ class JSONSchemaMarkdown {
534
534
* @see https://json-schema.org/understanding-json-schema/structuring.html#reuse
535
535
* @param {String } ref $ID, path, or URI
536
536
* @param {Integer } level Indentation level
537
- *
537
+ *
538
538
*/
539
539
writeRef ( ref , level ) {
540
540
if ( this . notEmpty ( ref ) ) {
@@ -546,7 +546,7 @@ class JSONSchemaMarkdown {
546
546
* Writes the path for reference purposes
547
547
* @param {Integer } level Indentation level
548
548
* @param {String } path String describing the path of the property
549
- *
549
+ *
550
550
*/
551
551
writePath ( level , path ) {
552
552
if ( this . notEmpty ( path ) ) {
@@ -559,7 +559,7 @@ class JSONSchemaMarkdown {
559
559
* @see https://json-schema.org/understanding-json-schema/basics.html#declaring-a-json-schema
560
560
* @param {String } uri
561
561
* @param {Integer } level Indentation level
562
- *
562
+ *
563
563
*/
564
564
writeSchema ( uri , level ) {
565
565
if ( this . notEmpty ( uri ) ) {
@@ -571,7 +571,7 @@ class JSONSchemaMarkdown {
571
571
* Writes a section name
572
572
* @param {String } name
573
573
* @param {Integer } level Indentation level
574
- *
574
+ *
575
575
*/
576
576
writeSectionName ( name , level = 1 ) {
577
577
if ( this . notEmpty ( name ) ) {
@@ -583,7 +583,7 @@ class JSONSchemaMarkdown {
583
583
* @see https://json-schema.org/understanding-json-schema/basics.html#the-type-keyword
584
584
* @param {String } type
585
585
* @param {Integer } level Indentation level
586
- *
586
+ *
587
587
*/
588
588
writeType ( type , level ) {
589
589
if ( this . notEmpty ( type ) ) {
@@ -599,7 +599,7 @@ class JSONSchemaMarkdown {
599
599
* @see https://json-schema.org/understanding-json-schema/reference/array.html#uniqueness
600
600
* @param {boolean } bool
601
601
* @param {Integer } level Indentation level
602
- *
602
+ *
603
603
*/
604
604
writeUniqueItems ( bool , level ) {
605
605
if ( this . notEmpty ( bool ) ) {
@@ -612,7 +612,7 @@ class JSONSchemaMarkdown {
612
612
/**
613
613
* Below are utility methods.
614
614
**/
615
-
615
+
616
616
/**
617
617
* Handles finding correct method for different schema types.
618
618
* @param {String } type The schema type/
@@ -641,7 +641,7 @@ class JSONSchemaMarkdown {
641
641
* @param {Integer } level Indentation level
642
642
* @param {string } indentChar Character to use for indentation. Defaults to this.indentChar
643
643
* @param {type } listChar Character to use for list
644
- *
644
+ *
645
645
*/
646
646
indent ( level , indentChar = false , listChar = ' - ' ) {
647
647
if ( level > 1 ) {
@@ -656,7 +656,7 @@ class JSONSchemaMarkdown {
656
656
* Converts boolean to string "true" or "false"
657
657
* @param {type } bool
658
658
* @returns {String }
659
- *
659
+ *
660
660
*/
661
661
valueBool ( bool ) {
662
662
if ( typeof bool === "string" ) {
@@ -670,7 +670,7 @@ class JSONSchemaMarkdown {
670
670
* Convert mixed values into markdown notation.
671
671
* @param {mixed } value
672
672
* @returns {String }
673
- *
673
+ *
674
674
*/
675
675
valueFormat ( value ) {
676
676
if ( value === "true" || value === "false" ) {
@@ -689,7 +689,7 @@ class JSONSchemaMarkdown {
689
689
* Handles line break logic.
690
690
* @param {String } text
691
691
* @param {Integer } level Indentation level
692
- *
692
+ *
693
693
*/
694
694
writeLine ( text = "" , level = 1 ) {
695
695
this . indent ( level ) ;
@@ -698,7 +698,7 @@ class JSONSchemaMarkdown {
698
698
this . markdown += "\n" ;
699
699
}
700
700
}
701
-
701
+
702
702
/**
703
703
* Prepare $ref as a link.
704
704
* @param {String } ref The schema $ref
@@ -730,7 +730,7 @@ class JSONSchemaMarkdown {
730
730
* Check if value is empty
731
731
* @param {* } value
732
732
* @returns {Boolean }
733
- *
733
+ *
734
734
*/
735
735
empty ( value ) {
736
736
return typeof value === "undefined"
@@ -743,7 +743,7 @@ class JSONSchemaMarkdown {
743
743
* Check if value is NOT empty
744
744
* @param {* } value
745
745
* @returns {Boolean }
746
- *
746
+ *
747
747
*/
748
748
notEmpty ( value ) {
749
749
return ! this . empty ( value ) ;
@@ -752,7 +752,7 @@ class JSONSchemaMarkdown {
752
752
/**
753
753
* Append error to errors array
754
754
* @param {String } error Error message
755
- *
755
+ *
756
756
*/
757
757
error ( error ) {
758
758
this . errors . push ( error ) ;
@@ -765,4 +765,4 @@ class JSONSchemaMarkdown {
765
765
*/
766
766
if ( typeof module !== "undefined" ) {
767
767
module . exports . JSONSchemaMarkdown = JSONSchemaMarkdown ;
768
- }
768
+ }
0 commit comments