Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/atymic/json2dto
Generate Data Transfer Objects directly from JSON objects
https://github.com/atymic/json2dto
dto laravel spatie vue
Last synced: 11 days ago
JSON representation
Generate Data Transfer Objects directly from JSON objects
- Host: GitHub
- URL: https://github.com/atymic/json2dto
- Owner: atymic
- License: gpl-3.0
- Created: 2020-01-04T22:33:00.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-07-11T02:09:33.000Z (over 1 year ago)
- Last Synced: 2024-10-11T09:45:07.126Z (27 days ago)
- Topics: dto, laravel, spatie, vue
- Language: PHP
- Homepage: https://json2dto.atymic.dev
- Size: 900 KB
- Stars: 127
- Watchers: 3
- Forks: 19
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Json 2 DTO
[![Build Status](https://img.shields.io/github/workflow/status/atymic/json2dto/PHP?style=flat-square)](https://github.com/atymic/json2dto/actions)
[![StyleCI](https://styleci.io/repos/231837839/shield)](https://styleci.io/repos/231837839)
[![Latest Version on Packagist](https://img.shields.io/packagist/v/atymic/json2dto.svg?style=flat-square)](https://packagist.org/packages/atymic/json2dto)
[![Total Downloads](https://img.shields.io/packagist/dt/atymic/json2dto.svg?style=flat-square)](https://packagist.org/packages/atymic/json2dto)[Spatie's Data Transfer Object](https://github.com/spatie/data-transfer-object) library is awesome, but typing out DTOs
can quickly become a chore. Inspired by Json2Typescript style tools, we built one for PHP DTOs.## Web Version
Try it out at [https://json2dto.atymic.dev](https://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, the
tool will create a zip file.[![](https://repository-images.githubusercontent.com/231837839/14ed4680-2fb2-11ea-81fe-f06c5038b0dd)](https://json2dto.atymic.dev)
## CLI Tool
Prefer to use the tool locally? You can install `json2dto` via composer and generate files directly from json files.
```bash
composer global require atymic/json2dto # Install Globallycomposer require atymic/json2dto --dev # Install locally in a project
```### Usage
The tool accepts json input either as a filename (second argument) or via `stdin`.
You should run the tool in the root of your project (where your `composer.json` is located) as it will resolve namespaces
based on your PSR4 autoloading config. If you aren't using PSR4, your generated folder structure might not match.#### Examples
```bash
# 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 stdin
wget http://example.com/cat.json | ./vendor/bin/json2dto generate "App\DTO" -name Cat
```#### Usage
```
json2dto generate [options] [--] []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 message
```