PHP SDK to generate JSON-RPC documentation from symfony constraint
See yoanm/symfony-jsonrpc-params-sf-constraints-doc for automatic dependency injection.
- Symfony v3/4 PHP >=7.1 :
v0.x
- Symfony v4/5 PHP >=7.2 :
v1.0
- Symfony v4.4/5.4/6.x PHP ^8.0 :
v1.1
Create the transformer :
use Yoanm\JsonRpcParamsSymfonyConstraintDoc\App\Helper\ConstraintPayloadDocHelper;
use Yoanm\JsonRpcParamsSymfonyConstraintDoc\App\Helper\DocTypeHelper;
use Yoanm\JsonRpcParamsSymfonyConstraintDoc\App\Helper\MinMaxHelper;
use Yoanm\JsonRpcParamsSymfonyConstraintDoc\App\Helper\StringDocHelper;
use Yoanm\JsonRpcParamsSymfonyConstraintDoc\App\Helper\TypeGuesser;
use Yoanm\JsonRpcParamsSymfonyConstraintDoc\Infra\Transformer\ConstraintToParamsDocTransformer;
$constraintPayloadDocHelper = new ConstraintPayloadDocHelper();
$transformer = new ConstraintToParamsDocTransformer(
new DocTypeHelper(
$constraintPayloadDocHelper,
new TypeGuesser()
),
new StringDocHelper(),
new MinMaxHelper(),
$constraintPayloadDocHelper
);
Then use it with single constraint or a list of :
use Symfony\Component\Validator\Constraints as ConstraintNS;
use Yoanm\JsonRpcServerDoc\Domain\Model\Type\ObjectDoc;
use Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc;
$constraint = new ConstraintNS\Collection([
'a' => new ConstraintNS\Type('string'),
'b' => new ConstraintNS\Type('integer'),
'c' => new ConstraintNS\Type('bool')
]);
/** @var ObjectDoc $constraintDoc */
$constraintDoc = $transformer->transform($constraint);
/** @var StringDoc $constraintDoc2 */
$constraintDoc2 = $transformer->transformList([
new ConstraintNS\Type('string'),
new ConstraintNS\NotNull()
]);