@@ -399,63 +399,76 @@ private function getPropertySchema(PropertyMetadata $propertyMetadata) : \ArrayO
399
399
$ propertySchema ['description ' ] = $ description ;
400
400
}
401
401
402
- if (null == $ type = $ propertyMetadata ->getType ()) {
402
+ if (null === $ type = $ propertyMetadata ->getType ()) {
403
403
return $ propertySchema ;
404
404
}
405
405
406
- $ valueSchema = new \ArrayObject ();
407
- $ valueType = $ type ->isCollection () ? $ type ->getCollectionValueType () : $ type ;
408
-
409
- switch ($ valueType ? $ valueType ->getBuiltinType () : null ) {
410
- case Type::BUILTIN_TYPE_STRING :
411
- $ valueSchema ['type ' ] = 'string ' ;
412
- break ;
413
-
414
- case Type::BUILTIN_TYPE_INT :
415
- $ valueSchema ['type ' ] = 'integer ' ;
416
- break ;
417
-
418
- case Type::BUILTIN_TYPE_FLOAT :
419
- $ valueSchema ['type ' ] = 'number ' ;
420
- break ;
421
-
422
- case Type::BUILTIN_TYPE_BOOL :
423
- $ valueSchema ['type ' ] = 'boolean ' ;
424
- break ;
425
-
426
- case Type::BUILTIN_TYPE_OBJECT :
427
- if (null === $ className = $ valueType ->getClassName ()) {
428
- break ;
429
- }
430
-
431
- if (is_subclass_of ($ className , \DateTimeInterface::class)) {
432
- $ valueSchema ['type ' ] = 'string ' ;
433
- $ valueSchema ['format ' ] = 'date-time ' ;
434
- break ;
435
- }
436
-
437
- if (!$ this ->resourceClassResolver ->isResourceClass ($ className )) {
438
- break ;
439
- }
440
-
441
- if (true === $ propertyMetadata ->isReadableLink ()) {
442
- $ valueSchema ['$ref ' ] = sprintf ('#/definitions/%s ' , $ this ->resourceMetadataFactory ->create ($ className )->getShortName ());
443
- break ;
444
- }
445
-
446
- $ valueSchema ['type ' ] = 'string ' ;
447
- $ valueSchema ['format ' ] = 'uri ' ;
448
- break ;
406
+ $ isCollection = $ type ->isCollection ();
407
+ if (null === $ valueType = $ isCollection ? $ type ->getCollectionValueType () : $ type ) {
408
+ $ builtinType = 'string ' ;
409
+ $ className = null ;
410
+ } else {
411
+ $ builtinType = $ valueType ->getBuiltinType ();
412
+ $ className = $ valueType ->getClassName ();
449
413
}
450
414
451
- if ($ type ->isCollection ()) {
452
- $ propertySchema ['type ' ] = 'array ' ;
453
- $ propertySchema ['items ' ] = $ valueSchema ;
454
- } else {
455
- $ propertySchema = new \ArrayObject ((array ) $ propertySchema + (array ) $ valueSchema );
415
+ $ valueSchema = $ this ->getType ($ builtinType , $ isCollection , $ className , $ propertyMetadata ->isReadableLink ());
416
+
417
+ return new \ArrayObject ((array ) $ propertySchema + $ valueSchema );
418
+ }
419
+
420
+ /**
421
+ * Gets the Swagger's type corresponding to the given PHP's type.
422
+ *
423
+ * @param string $type
424
+ *
425
+ * @param bool $isCollection
426
+ * @param string $className
427
+ * @param bool $readableLink
428
+ *
429
+ * @return array
430
+ */
431
+ private function getType (string $ type , bool $ isCollection , string $ className = null , bool $ readableLink = null ) : array
432
+ {
433
+ if ($ isCollection ) {
434
+ return ['type ' => 'array ' , 'items ' => $ this ->getType ($ type , false , $ className , $ readableLink )];
435
+ }
436
+
437
+ if (Type::BUILTIN_TYPE_STRING === $ type ) {
438
+ return ['type ' => 'string ' ];
439
+ }
440
+
441
+ if (Type::BUILTIN_TYPE_INT === $ type ) {
442
+ return ['type ' => 'integer ' ];
443
+ }
444
+
445
+ if (Type::BUILTIN_TYPE_FLOAT === $ type ) {
446
+ return ['type ' => 'number ' ];
447
+ }
448
+
449
+ if (Type::BUILTIN_TYPE_BOOL === $ type ) {
450
+ return ['type ' => 'boolean ' ];
456
451
}
457
452
458
- return $ propertySchema ;
453
+ if (Type::BUILTIN_TYPE_OBJECT === $ type ) {
454
+ if (null === $ className ) {
455
+ return ['type ' => 'string ' ];
456
+ }
457
+
458
+ if (is_subclass_of ($ className , \DateTimeInterface::class)) {
459
+ return ['type ' => 'string ' , 'format ' => 'date-time ' ];
460
+ }
461
+
462
+ if (!$ this ->resourceClassResolver ->isResourceClass ($ className )) {
463
+ return ['type ' => 'string ' ];
464
+ }
465
+
466
+ if (true === $ readableLink ) {
467
+ return ['$ref ' => sprintf ('#/definitions/%s ' , $ this ->resourceMetadataFactory ->create ($ className )->getShortName ())];
468
+ }
469
+ }
470
+
471
+ return ['type ' => 'string ' ];
459
472
}
460
473
461
474
/**
@@ -490,6 +503,24 @@ private function computeDoc(Documentation $documentation, \ArrayObject $definiti
490
503
return $ doc ;
491
504
}
492
505
506
+ private function getFiltersParameters (string $ resourceClass , string $ operationName , ResourceMetadata $ resourceMetadata ) : array
507
+ {
508
+ $ parameters = new \ArrayObject ();
509
+ foreach ($ resourceMetadata ->getCollectionOperationAttribute ($ operationName , 'filters ' , [], true ) as $ filter ) {
510
+ foreach ($ filter ->getDescription ($ resourceClass ) as $ variable => $ data ) {
511
+ $ parameter = [
512
+ 'name ' => $ variable ,
513
+ 'in ' => 'query ' ,
514
+ 'required ' => $ data ['required ' ],
515
+ 'type ' => $ this ->getType ($ data ['type ' ])
516
+ ];
517
+
518
+ $ data ['swagger ' ] ?? $ parameter = $ data ['swagger ' ] + $ parameter ;
519
+ $ parameters [] = $ parameter ;
520
+ }
521
+ }
522
+ }
523
+
493
524
/**
494
525
* {@inheritdoc}
495
526
*/
0 commit comments