GithubHelp home page GithubHelp logo

torian257x / json2dto Goto Github PK

View Code? Open in Web Editor NEW

This project forked from atymic/json2dto

0.0 0.0 0.0 3.21 MB

Generate Data Transfer Objects directly from JSON objects

Home Page: https://json2dto.atymic.dev

License: GNU General Public License v3.0

Dockerfile 0.91% PHP 51.40% JavaScript 5.20% HTML 1.13% Vue 37.59% CSS 3.77%

json2dto's Introduction

Json 2 DTO

Build Status StyleCI Latest Version on Packagist Total Downloads

Spatie's 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
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.

CLI Tool

Prefer to use the tool locally? You can install json2dto via composer and generate files directly from json files.

composer global require atymic/json2dto # Install Globally

composer 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

# 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] [--] <namespace> [<json>]

Arguments:
  namespace                       Namespace to generate the class(es) in
  json                            File containing the json string

Options:
      --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

json2dto's People

Contributors

atymic avatar dependabot[bot] avatar hornet-wing avatar mfn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.