valantic / pimcore-api-documentation
Auto generate API documentation for routes
Installs: 1 984
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 6
Forks: 0
Open Issues: 2
Requires
- php: ^8.2
- ext-json: *
- nelmio/api-doc-bundle: ^4.12
- pimcore/pimcore: ^11.0
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.8.2
- phpstan/extension-installer: ^1.4.1
- phpstan/phpstan: ^1.11.6
- phpstan/phpstan-deprecation-rules: ^1.2.0
- phpstan/phpstan-strict-rules: ^1.6.0
- rector/rector: ^1.2.0
- roave/security-advisories: dev-latest
README
This package is developed by valantic CEC Schweiz and is under active development.
Bundle is used for generating API documentation based on API controllers.
Requirements
- Pimcore >= 11.0.0
Installation
composer require valantic/pimcore-api-documentation
- Add
ValanticPimcoreApiDocumentationBundle
toconfig/bundles.php
Usage
class ProductController implements \Valantic\PimcoreApiDocumentationBundle\Http\Controller\ApiControllerInterface { use \Valantic\PimcoreApiDocumentationBundle\Controller\ApiControllerTrait; #[Route(path: '/product', name: 'rest_api_product_create', methods: Request::METHOD_POST)] public function create(ProductCreateRequest $request): ProductCreateResponse|\Valantic\PimcoreApiDocumentationBundle\Http\Response\BadRequestResponse { $errors = $this->validateRequest($request); if (count($errors) !== 0) { return new \Valantic\PimcoreApiDocumentationBundle\Http\Response\BadRequestResponse($errors); } return new ProductCreateResponse(/* ... */); } } use Symfony\Component\Validator\Constraints as Assert; class ProductCreateRequest implements \Valantic\PimcoreApiDocumentationBundle\Http\Request\Contracts\HasJsonPayload { #[Assert\NotBlank] public ?string $name = null; #[Assert\NotBlank] public ?string $description = null; } class ProductCreateResponse implements \Valantic\PimcoreApiDocumentationBundle\Http\Response\ApiResponseInterface { public static function status(): int { return \Symfony\Component\HttpFoundation\Response::HTTP_CREATED; } public static function getDtoClass(): string|false { return ProductCreateDto::class; } } class ProductCreateDto { public function __construct( public ?int $id, ) {} }