- Notifications
You must be signed in to change notification settings - Fork21
Generate Data Transfer Objects directly from JSON objects
License
atymic/json2dto
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Spatie's Data Transfer Object library is awesome, but typing out DTOscan quickly become a chore. Inspired by Json2Typescript style tools, we built one for PHP DTOs.
Try it out athttps://json2dto.atymic.dev
The web version has all of the same tools as the cli version in an easy to use GUI. When generating nested DTOs, thetool will create a zip file.
Prefer to use the tool locally? You can installjson2dto via composer and generate files directly from json files.
composer global require atymic/json2dto# Install Globallycomposer require atymic/json2dto --dev# Install locally in a project
The tool accepts json input either as a filename (second argument) or viastdin.
You should run the tool in the root of your project (where yourcomposer.json is located) as it will resolve namespacesbased on your PSR4 autoloading config. If you aren't using PSR4, your generated folder structure might not match.
# Generate PHP 7.4 typed DTO./vendor/bin/json2dto generate"App\DTO" test.json -name"Test" --typed# Generate PHP 8.0 typed DTO (DTO V3)./vendor/bin/json2dto generate"App\DTO" test.json -name"Test" --v3# Generate a flexible DTO (with nested DTOs)./vendor/bin/json2dto generate"App\DTO" test.json -name"Test" --nested --flexible# Generate a DTO from stdinwget http://example.com/cat.json| ./vendor/bin/json2dto generate"App\DTO" -name Cat
json2dto generate [options] [--] <namespace> [<json>]Arguments: namespace Namespace to generate the class(es) in json File containing the json stringOptions: --nested Generate nested DTOs --typed Generate PHP >= 7.4 strict typing --flexible Generate a flexible DTO --dry Dry run, print generated files --v3 Generate V3 DTO -h, --help Display this help messageAbout
Generate Data Transfer Objects directly from JSON objects
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.