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

file name with .model.dart #43

Closed Miamoto-Musashi closed 3 years ago

Miamoto-Musashi commented 3 years ago

I'm using Hive Object Converter to introduce Hive notations into models

Would be nice to automate the process and have Json to Dart let me decide the output pattern so that the other plugin can find the generated files

iamarnas commented 3 years ago

@Miamoto-Musashi Hi 👋

Thanks for suggestion. I don't use Hive and don't know how it's important. If you should have option to put enhancement filename it's not same as change file name manually? Because anyway you would need put in somewhere filename to tell for Json to Dart Model which name you want to add.

Miamoto-Musashi commented 3 years ago

Hi @iamarnas, I'm using jsonc generator as far as I know the only attribute I can play with is__className, to make the other plugin find the models I should use __className: Address.model or similar but then I will find that class name everywhere on the code so it would be nice to have Address class generated in address.model.dart file. Hive is quite popular in the community bye my knowledge.

I was also looking to contribute but not so confident with node

iamarnas commented 3 years ago

Hi @Miamoto-Musashi

By using the jsonc file is a quick fix. I will add this suggestion to the list and try to integrate it as soon as possible and all suggestions how to be possible make it simple as possible for users are welcome. Right now I work with commands subscriptions, for example it will be possible to build jsonc file models from the right mouse button context menu.

iamarnas commented 3 years ago

Hi @Miamoto-Musashi

I added file name enhancement to the latest version. To test it you just need to separate your class name with a dot and after the dot, everything will be added as an enhancement name. Example: className.enhancementName you can play how you want with it, generator will try correct your mistakes. Can you test and see if it works as you expected? I have not documented it yet, it must be tested first.

Miamoto-Musashi commented 3 years ago

yes working, thank you.

very minor enhancement is the lint option, using dart linter the generated code violates sort_constructors_first rule

iamarnas commented 3 years ago

@Miamoto-Musashi

yes working, thank you.

Then now I can update documentation?

very minor enhancement is the lint option, using dart linter the generated code violates sort_constructors_first rule

It is a quick fix that i can add to the settings option with the next version.

Miamoto-Musashi commented 3 years ago

probably className should become fileName since it is really driving the file name just for clarity

iamarnas commented 3 years ago

probably className should become fileName since it is really driving the file name just for clarity

It not really driving the only file name. The __className is a base class name that holds all JSON generated context and is used for a file name for the map name and for syntax. I thought a lot about how I would describe this key to users and become that __className most used and most familiar to beginners.

Miamoto-Musashi commented 3 years ago

probably we can close this one?

iamarnas commented 3 years ago

probably we can close this one?

@Miamoto-Musashi Sure, if you not have any issues with this we can close this. I have waited until you test it properly.