File tree Expand file tree Collapse file tree 3 files changed +48
-1
lines changed
tests/src/PHPUnit/Markdown Expand file tree Collapse file tree 3 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
4
4
The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.0.0/ ) ,
5
5
and this project adheres to [ Semantic Versioning] ( https://semver.org/spec/v2.0.0.html ) .
6
6
7
+ ## [ 0.2.36] - 2022-09-16
8
+
9
+ ### Added
10
+ - Table of contents in Markdown generator.
11
+
7
12
## [ 0.2.35] - 2022-01-02
8
13
9
14
### Fixes
@@ -103,6 +108,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
103
108
### Fixed
104
109
- Description trimming bug.
105
110
111
+ [ 0.2.36 ] : https://github.com/swaggest/php-code-builder/compare/v0.2.35...v0.2.36
106
112
[ 0.2.35 ] : https://github.com/swaggest/php-code-builder/compare/v0.2.34...v0.2.35
107
113
[ 0.2.34 ] : https://github.com/swaggest/php-code-builder/compare/v0.2.33...v0.2.34
108
114
[ 0.2.33 ] : https://github.com/swaggest/php-code-builder/compare/v0.2.32...v0.2.33
Original file line number Diff line number Diff line change @@ -21,6 +21,12 @@ class TypeBuilder
21
21
22
22
public $ addNamePrefix = '' ;
23
23
24
+ /**
25
+ * Map of type name to type doc.
26
+ * @var array<string,string>
27
+ */
28
+ public $ types = [];
29
+
24
30
public $ file = '' ;
25
31
26
32
public function __construct ()
@@ -223,7 +229,7 @@ public function getTypeString($schema, $path = '')
223
229
}
224
230
225
231
if ($ schema ->format !== null ) {
226
- $ or []= 'Format: ` ' . $ schema ->format . '` ' ;
232
+ $ or [] = 'Format: ` ' . $ schema ->format . '` ' ;
227
233
}
228
234
229
235
$ res = '' ;
@@ -421,11 +427,34 @@ private function makeTypeDef(Schema $schema, $path)
421
427
422
428
MD ;
423
429
430
+ $ this ->types [$ typeName ] = $ res ;
424
431
$ this ->file .= $ res ;
425
432
426
433
return $ typeName ;
427
434
}
428
435
436
+ public function sortTypes ()
437
+ {
438
+ ksort ($ this ->types );
439
+ }
440
+
441
+ public function tableOfContents ()
442
+ {
443
+ if (count ($ this ->types ) === 0 ) {
444
+ return '' ;
445
+ }
446
+
447
+ $ res = '# Types ' . "\n\n" ;
448
+
449
+ foreach ($ this ->types as $ name => $ doc ) {
450
+ $ res .= ' * ' . $ name . "\n" ;
451
+ }
452
+
453
+ $ res .= "\n\n" ;
454
+
455
+ return $ res ;
456
+ }
457
+
429
458
private function description (Schema $ schema )
430
459
{
431
460
$ res = str_replace ("\n" , " " , $ schema ->title . $ schema ->description );
Original file line number Diff line number Diff line change @@ -69,5 +69,17 @@ public function testJsonSchema()
69
69
70
70
MD
71
71
, $ tb ->file );
72
+
73
+ $ tb ->sortTypes ();
74
+ $ this ->assertSame (<<<'MD'
75
+ # Types
76
+
77
+ * [`Person`](#person)
78
+ * [`Unit`](#unit)
79
+
80
+
81
+
82
+ MD
83
+ , $ tb ->tableOfContents ());
72
84
}
73
85
}
You can’t perform that action at this time.
0 commit comments