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 18 forks source link

Make generating models directory optional #15

Closed apgapg closed 3 years ago

apgapg commented 3 years ago

When we go into creating different modules in project, everytime I need to delete the extraneous models folder and move the inner files into outer parent. Not everytime one needs to generate models dir. Hence can we have a optional dialog asking to generate models dir?

iamarnas commented 3 years ago

@apgapg Hi, In your situation you should navigate to models map. if not exist create it.

/lib -> /models

After when generating is complete. Your map structure should look like this.

/lib -> /models -> /models

Last map keeps all your generated files in one place and completely separate. Your need just rename it to the base class name. Here's how my map structure looks like.

Skärmavbild 2021-02-04 kl  09 53 08

This structure allow your easy find and delete files. models.dart is dart barrel file which keep all exports of the base class.

Of course, it is possible to rename the models map with the users' base class name. But I think it is better to keep the same name to avoid overriding (OBS!! As in your situation :)) and it makes possible to find faster and easier generated files in the long list for the next processes.

Like you see in my case I see it with the red color :D

apgapg commented 3 years ago

I agree with what you said. Keeping all models in one folder is standard practice. But in my case, each module contains its own model's dir with child being folder for grouping different models. No worries, one can do manually moving of files after generation. Also, it's a one-time process so no hurt in doing that.

Thanks for the quick reply @iamarnas

iamarnas commented 3 years ago

@apgapg Hi, I have added a new feature to the Json to Dart Model generator. Now your can build your modules from the single file. It give you more flexibility and you can configure generator how your want. Maybe you will find answer in this quastion. Read the documentation.

apgapg commented 3 years ago

@iamarnas This is a cool addition. Having a config file helps to maintain a hardcoded configuration. This will definitely help im future json model managing.

iamarnas commented 3 years ago

@iamarnas This is a cool addition. Having a config file helps to maintain a hardcoded configuration. This will definitely help im future json model managing.

Glad to see that it is useful :)

Miamoto-Musashi commented 3 years ago

would be definitely very useful to have this option for 2 reasons:

1- it is annoying to have to move all generated models from inner directories (last time a did a mv *.dart .. I was in the wrong folder and destroyed the whole project :) ) if I use other transformations on the models after generation I would like them to be in one single folder

2- there is the option that the inner folders contains same generated classes referenced twice in the json (this would be probably solved by #45 )

do you think we can reopen this request and handle it?

thanks

best

iamarnas commented 3 years ago

would be definitely very useful to have this option for 2 reasons:

1- it is annoying to have to move all generated models from inner directories, if I use other transformations on the models after generation I would like them to be in one single folder 2- there is the option that the inner folders contains same generated classes referenced twice in the json

do you think we can reopen this request and handle it?

thanks

best

@Miamoto-Musashi Hi 👋

This generator separates classes to different files and models folder, does not allow to mix them with others files in the same folder. You just need to rename it however you want. Men this will be improved with the next release. It will be possible to select the directory from the right mouse button context 😉 Everything will be able to run from the context menu. The worst which remains it to update the documentation.

iamarnas commented 3 years ago

@Miamoto-Musashi Hi,

Can you test the new features actions from the context and look if match your preferences. Would be nice to hear your opinion if it is possible to improve something more when it comes to easily run the conversion.

Miamoto-Musashi commented 3 years ago

Sure, you don't have to mix the files it's enough to replace with the last one, if the genereted contains errors we notice by compilation issue

Miamoto-Musashi commented 3 years ago

@Miamoto-Musashi Hi,

Can you test the new features actions from the context and look if match your preferences. Would be nice to hear your opinion if it is possible to improve something more when it comes to easily run the conversion.

the context generation works well ;)