@@ -309,6 +309,9 @@ private function copyTo(SchemaBuilder $schemaBuilder)
309
309
return $ schemaBuilder ;
310
310
}
311
311
312
+ /**
313
+ * @throws \Swaggest\JsonSchema\InvalidValue
314
+ */
312
315
private function processOther ()
313
316
{
314
317
static $ skip = null , $ emptySchema = null , $ names = null ;
@@ -384,6 +387,10 @@ private function processOther()
384
387
}
385
388
}
386
389
390
+ /**
391
+ * @throws Exception
392
+ * @throws \Exception
393
+ */
387
394
private function processLogic ()
388
395
{
389
396
$ names = Schema::names ();
@@ -392,8 +399,11 @@ private function processLogic()
392
399
if ($ this ->schema ->$ keyword !== null ) {
393
400
$ schema = $ this ->schema ->$ keyword ;
394
401
$ path = $ this ->path . '-> ' . $ keyword ;
395
- if ($ schema instanceof Schema && !empty ($ schema ->getFromRefs ())) {
396
- $ path = $ schema ->getFromRefs ()[0 ];
402
+ if ($ schema instanceof Schema) {
403
+ $ path = $ this ->pathFromDescription ($ path , $ schema );
404
+ if (!empty ($ schema ->getFromRefs ())) {
405
+ $ path = $ schema ->getFromRefs ()[0 ];
406
+ }
397
407
}
398
408
$ this ->result ->addSnippet (
399
409
$ this ->copyTo (new SchemaBuilder (
@@ -411,6 +421,7 @@ private function processLogic()
411
421
if ($ this ->schema ->$ keyword !== null ) {
412
422
foreach ($ this ->schema ->$ keyword as $ index => $ schema ) {
413
423
$ path = $ this ->path . "-> {$ keyword }[ {$ index }] " ;
424
+ $ path = $ this ->pathFromDescription ($ path , $ schema );
414
425
if ($ schema instanceof Schema && !empty ($ schema ->getFromRefs ())) {
415
426
$ path = $ schema ->getFromRefs ()[0 ];
416
427
}
@@ -442,9 +453,27 @@ private function processLogic()
442
453
}
443
454
}
444
455
456
+ /**
457
+ * @param string $path
458
+ * @param Schema $schema
459
+ * @return string
460
+ */
461
+ private function pathFromDescription ($ path , $ schema )
462
+ {
463
+ if ($ this ->phpBuilder ->namesFromDescriptions ) {
464
+ if ($ schema ->title && strlen ($ schema ->title ) < 30 ) {
465
+ $ path = $ this ->path . "-> {$ schema ->title }" ;
466
+ } elseif ($ schema ->description && strlen ($ schema ->description ) < 30 ) {
467
+ $ path = $ this ->path . "-> {$ schema ->description }" ;
468
+ }
469
+ }
470
+ return $ path ;
471
+ }
472
+
445
473
/**
446
474
* @return PhpCode
447
475
* @throws Exception
476
+ * @throws \Swaggest\JsonSchema\InvalidValue
448
477
*/
449
478
public function build ()
450
479
{
0 commit comments