Skip to content

Commit 6239d4f

Browse files
authored
Improve markdown generation (#48)
1 parent c338724 commit 6239d4f

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

composer.lock

+18-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Markdown/TypeBuilder.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public function getTypeString($schema, $path = '')
5656
if (!empty($schema->enum)) {
5757
$res = '';
5858
foreach ($schema->enum as $value) {
59-
$res .= '`' . var_export($value, true) . '`, ';
59+
$res .= '<br>`' . var_export($value, true) . '`, ';
6060
}
61-
return substr($res, 0, -2);
61+
return substr($res, 4, -2);
6262
}
6363

6464
if (!empty($schema->getFromRefs())) {
@@ -222,6 +222,10 @@ public function getTypeString($schema, $path = '')
222222
$or [] = '`Boolean`';
223223
}
224224

225+
if ($schema->format !== null) {
226+
$or []= 'Format: `' . $schema->format . '`';
227+
}
228+
225229
$res = '';
226230
foreach ($or as $item) {
227231
if (!empty($item) && $item !== '*') {
@@ -285,7 +289,6 @@ private static function constraints()
285289
$names->uniqueItems,
286290
$names->maxProperties,
287291
$names->minProperties,
288-
$names->format,
289292
];
290293
}
291294

@@ -320,7 +323,7 @@ private function makeTypeDef(Schema $schema, $path)
320323
if (!empty($schema->description)) {
321324
$head .= $schema->description . "\n";
322325
}
323-
326+
324327
$examples = [];
325328
if (!empty($schema->{self::EXAMPLES})) {
326329
$examples = $schema->{self::EXAMPLES};
@@ -354,7 +357,7 @@ private function makeTypeDef(Schema $schema, $path)
354357
355358
MD;
356359

357-
360+
358361
$rows = [];
359362
foreach (self::constraints() as $name) {
360363
if ($schema->$name !== null) {

tests/src/PHPUnit/Markdown/MarkdownTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testJsonSchema()
5050
5151
|Property |Type |Description |
5252
|----------|------------------------------|------------|
53-
|`name` |`'John'`, `'Jane'` |Person name.|
53+
|`name` |`'John'`, <br>`'Jane'` |Person name.|
5454
|`age` |`123` | |
5555
|`isMale` |`Boolean` | |
5656
|`partner` |[`Person`](#person) | |

0 commit comments

Comments
 (0)