Skip to content

Commit

Permalink
Improve comment description formatting in JSDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop committed Dec 18, 2023
1 parent 57f9213 commit db97da5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
26 changes: 13 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion src/JSDoc/TypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,14 @@ private function makeObjectTypeDef(Schema $schema, $path)

private function description(Schema $schema)
{
$res = str_replace("\n", " ", $schema->title . $schema->description);
$res = str_replace("\n", " ", trim($schema->title));
if (trim($schema->description)) {
if ($res) {
$res .= ". ";
}

$res .= str_replace("\n", " ", trim($schema->description));
}
if ($res) {
return ' - ' . rtrim($res, '.') . '.';
}
Expand Down
4 changes: 2 additions & 2 deletions tests/src/PHPUnit/JSDoc/JSDocTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function testJsonSchema()
"Person": {
"type": "object",
"properties": {
"name": {"type": "string", "description": "Person name."},
"name": {"type": "string", "title":" Name ", "description": "The name of the person."},
"age": {"type": "integer"},
"isMale": {"type": "boolean"},
"partner": {"$ref": "#/definitions/Person"},
Expand All @@ -37,7 +37,7 @@ public function testJsonSchema()
/**
* @typedef Person
* @type {Object}
* @property {String} name - Person name.
* @property {String} name - Name. The name of the person.
* @property {Number} age
* @property {Boolean} isMale
* @property {Person} partner
Expand Down

0 comments on commit db97da5

Please sign in to comment.