2
2
3
3
namespace Swaggest \PhpCodeBuilder \Markdown ;
4
4
5
- use Swaggest \CodeBuilder \CodeBuilder ;
6
5
use Swaggest \CodeBuilder \TableRenderer ;
7
6
use Swaggest \JsonSchema \Schema ;
8
7
use Swaggest \PhpCodeBuilder \PhpCode ;
@@ -27,6 +26,8 @@ class TypeBuilder
27
26
*/
28
27
public $ types = [];
29
28
29
+ public $ uniqueTypeSchemas = [];
30
+
30
31
public $ file = '' ;
31
32
32
33
public function __construct ()
@@ -315,14 +316,10 @@ private function hasConstraints($schema)
315
316
return false ;
316
317
}
317
318
318
- private function makeTypeDef (Schema $ schema , $ path )
319
+ public function renderTypeDef (Schema $ schema, $ typeName , $ path )
319
320
{
320
- $ tn = $ this ->typeName ($ schema , $ path , true );
321
- $ typeName = $ this ->typeName ($ schema , $ path );
322
- $ this ->processed ->attach ($ schema , $ typeName );
323
-
324
321
$ head = '' ;
325
- if (!empty ($ schema ->title ) && $ schema ->title != $ tn ) {
322
+ if (!empty ($ schema ->title ) && $ schema ->title != $ typeName ) {
326
323
$ head .= $ schema ->title . "\n" ;
327
324
}
328
325
@@ -353,12 +350,12 @@ private function makeTypeDef(Schema $schema, $path)
353
350
}
354
351
}
355
352
356
- $ tnl = strtolower ($ tn );
353
+ $ tnl = strtolower ($ typeName );
357
354
358
355
$ res = <<<MD
359
356
360
357
361
- ### <a id=" $ tnl"></a> $ tn
358
+ ### <a id=" $ tnl"></a> $ typeName
362
359
$ head
363
360
364
361
MD ;
@@ -384,6 +381,7 @@ private function makeTypeDef(Schema $schema, $path)
384
381
->setColDelimiter ('| ' )
385
382
->setHeadRowDelimiter ('- ' )
386
383
->setOutlineVertical (true )
384
+ ->multilineCellDelimiter ('<br> ' )
387
385
->setShowHeader ();
388
386
389
387
$ res .= "\n\n" ;
@@ -419,6 +417,7 @@ private function makeTypeDef(Schema $schema, $path)
419
417
->setColDelimiter ('| ' )
420
418
->setHeadRowDelimiter ('- ' )
421
419
->setOutlineVertical (true )
420
+ ->multilineCellDelimiter ('<br> ' )
422
421
->setShowHeader ();
423
422
424
423
}
@@ -427,7 +426,23 @@ private function makeTypeDef(Schema $schema, $path)
427
426
428
427
MD ;
429
428
429
+ return $ res ;
430
+ }
431
+
432
+ private function makeTypeDef (Schema $ schema , $ path )
433
+ {
434
+ $ tn = $ this ->typeName ($ schema , $ path , true );
435
+ $ typeName = $ this ->typeName ($ schema , $ path );
436
+ $ this ->processed ->attach ($ schema , $ typeName );
437
+
438
+ $ res = $ this ->renderTypeDef ($ schema , $ tn , $ path );
439
+
440
+ if (isset ($ this ->uniqueTypeSchemas [$ res ])) {
441
+ return $ this ->uniqueTypeSchemas [$ res ];
442
+ }
443
+
430
444
$ this ->types [$ typeName ] = $ res ;
445
+ $ this ->uniqueTypeSchemas [$ res ] = $ typeName ;
431
446
$ this ->file .= $ res ;
432
447
433
448
return $ typeName ;
0 commit comments