Download the PHP package gdnacho/poob without Composer
On this page you can find all versions of the php package gdnacho/poob. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package poob
Short Description Input/Output DTO generator, validator, and OpenAPI docs generator.
License MIT
Informations about the package poob
Poob
Poob – Input/Output DTO generator, validator, and OpenAPI docs generator.
Quickly create Input DTOs, Output DTOs, and Field definitions using Symfony Validator. Input DTOs are automatically validated through a value resolver, as well as OpenAPI docs generation.
The goal is to provide a less opinionated micro-framework than API Platform, and a bundle like Nelmio/ApiDocBundle without the annotation boilerplate.
Features
- Generate Input DTOs (
poob:make:input-dto <name>) - Generate Output DTOs (
poob:make:output-dto <name>) - Generate Field definitions (
poob:make:field <name>) - Automatic request validation using a value resolver (
RequestInputResolver) - Organizes generated classes under
/src/Api:/InputDto/OutputDto/Field
- Generate API docs (
poob:make:docs)
Installation
Add Poob to your Symfony project via Composer:
Then initialize (This will create the directories /src/Api and /config/packages/poob_api.yaml):
Usage
Controller
$datais automatically populated from the request and validated, using the UsernameInput DTO.- For GET requests, Poob reads the query parameters.
- For POST, PUT, PATCH, or other request methods, Poob parses and validates the JSON request body.
- If validation fails, the value resolver throws a
ValidationException, which can be handled by an event listener. - The
from()method from the Output DTO takes any object and serializes it. This example, thus, responds:
Optionally, you can also map requests directly to an unvalidated array if the parameter is named $requestData:
Input DTO
Field
Output DTO
Output DTO Helpers
All Output DTOs should extend OutputDto. This provides two convenient static methods:
from(object $source): static: Creates a new DTO from any object, such as entities.collection(iterable $items): array: Converts a list of objects into an array of DTOs. Uses from() internally for each item.
API Docs generation
You may generate rudimentary OpenAPI documentation for your API with the poob:make:docs command.
Poob will scan all your routes (With a prefix of /api by default) and Input DTOs schema and validation rules to generate it. $ref is not yet supported.
You can configure your API docs in config/packages/poob_api.yaml:
Description & Summary attributes
You may use these attributes atop controllers for the API docs generation:
You can also use description for properties in InputDTOs:
Full CRUD controller example
Contributing
Poob is just a small package with not a lot of thought put into it, mostly for me to use in my own projects. Regardless, contributions as small as just submitting issues are welcome.
"u gota get a groov!!!"
All versions of poob with dependencies
symfony/http-kernel Version ^8.0
symfony/routing Version ^8.0
symfony/console Version ^8.0
symfony/validator Version ^8.0
symfony/filesystem Version ^8.0
symfony/dependency-injection Version ^8.0
symfony/config Version ^8.0
symfony/yaml Version ^8.0