hiranthaR / Json-to-Dart-Model

Json to Dart Model extension can convert JSON objects into Dart data classes. It supports pure Dart class conversion, Flutter-recommended JSON serialization using annotations, Freezed support, Effective Dart:Style, and many more features. Currently, it has more than 135,000 installs.
https://marketplace.visualstudio.com/items?itemName=hirantha.json-to-dart
MIT License
93 stars 17 forks source link

Multiple model.jsonc files #56

Closed Prn-Ice closed 3 years ago

Prn-Ice commented 3 years ago

Is there an existing issue for this?

Current Behavior

Currently I can create a general models.jsonc in the root of my project that generates all my models in one folder.

Expected Behavior

I use something similar to reso coders clean architecture and all my models are not to be stored in one folder but within the feature for which they were created like this:

lib//app/modules/
├── account
│   ├── data
│   │   ├── set_username_request.dart
│   │   ├── update_user_request.dart
│   ├── repository
│   │   ├── account_client.dart
│   │   ├── account_client.g.dart
│   │   └── account_repository.dart
│   ├── views
│   │   ├── account_view.dart
│   │   └── verify_pin_changed_view.dart
│   └── widgets
│       ├── account_header.dart
│       ├── account_options.dart
├── home
│   ├── data
│   │   ├── coin_metadata.dart
│   │   └── coin_metadata.g.dart
│   ├── repository
│   │   ├── coin_metadata_client.dart
│   │   ├── coin_metadata_client.g.dart
│   │   └── coin_metadata_repository.dart
│   ├── services
│   │   └── coin_metadata_service.dart
│   ├── views
│   │   ├── home_view.dart
│   │   └── wallet_view.dart
│   └── widgets
│       ├── announcement_indicator.dart
│       └── wallets_section.dart
├── information
│   ├── data
│   │   ├── announcements_response.dart
│   │   └── announcements_response.g.dart
│   ├── repository
│   │   ├── announcements_client.dart
│   │   ├── announcements_client.g.dart
│   │   ├── announcements_client.http
│   │   └── announcements_repository.dart
│   ├── services
│   │   └── announcements_service.dart
│   ├── views
│   │   └── information_view.dart
│   └── widgets
│       └── announcement_bottom_sheet.dart
└── withdraw
    ├── data
    │   ├── withdrawal_response.dart
    │   ├── withdrawal_response.g.dart
    │   ├── withdrawals_response.dart
    │   ├── withdrawals_response.g.dart
    │   ├── withdraw_request.dart
    │   └── withdraw_request.g.dart
    ├── repository
    │   ├── withdrawal_client.dart
    │   ├── withdrawal_client.g.dart
    │   └── withdraw_repository.dart
    ├── views
    │   └── withdraw_view.dart
    └── widgets
        └── select_withdrawal_bank_account_bottom_sheet.dart

Would be nice if I could have a model.jsonc file for each data folder that I update as the API responses change.

Steps To Reproduce

No response

Version

3.3.5

Relevant JSON syntax

No response

Anything else?

No response

iamarnas commented 3 years ago

@Prn-Ice Hi :wave:

Thank you for your suggestion. The generator has a secret key when you run models from the models.jsonc. By adding key __path you can override the default path and navigate your models where you want and how your want, it is up to your risk because it is not documented yet and is in the beta state. Would be nice if you can test it and report issues. For example, in your case to navigate your coin_metadata models to home directory. It should look like this :point_down:

[
    {
          // The sorting is important first class then path. 
      "__className": "coin_metadata",
          "__path": "/lib/app/modules/home/data" // <- override default path with a new one by adding '__path' key.
      // the rest json data...
    },
    {
         "__className": "coin_metadata_client",
     "__path": "/lib/app/modules/home/repository"
     // the rest json data...
    },
    {
         "__className": "coin_metadata_repository",
     "__path": "/lib/app/modules/home/repository"
     // the rest json data...
    },
    {
     "__className": "coin_metadata_service",
     "__path": "/lib/app/modules/home/services"
     // the rest json data...
    }
]

OBS! and you need to update to the 3.3.6 version. I have corrected some bugs.

Hope you will like this :smiley:

Prn-Ice commented 3 years ago

Thanks a lot, I'll check it out.

Prn-Ice commented 3 years ago

Wow, it woorks thank you.

iamarnas commented 3 years ago

@Prn-Ice Hi. I need to test one more secret feature.

} 
    "trailers": [
      {
        "key": "Trailer",
        "dimension": null,
        // Be adding ".trailer_type" you can force generator to generate new type. 
        // Result : `TrailerType type;`  instead `Type type;`
        // It works only with not primitive types. 
        "type.trailer_type": {
            //... 
         }
      }
    ],
},

Report any issues. Have a fun coding 😉