Best practice for configuring JSON objects in the `models.jsonc` file
iamarnas opened this issue · 7 comments
Proposal
Right now JSON to Dart model allows an override path for every JSON object by working with models.jsonc
file and default global configuration reads from the extension settings. To add more options and make more customizable outputs my recommended method is 👇
Recommended options:
"__options": {
"codeGenerator": "Default", // ['Default', 'JSON', 'Freezed']
"immutable": false,
"toString": "Default", // ['Default', 'Auto', 'Stringify', 'Dart']
"copyWith": false,
"equality": "Default", // ['Default', 'Equatable', 'Dart']
"targetDirectory": "/lib/src/models", // <- override path here
"runBuilder": false,
"sortConstructorsFirst": false,
"includeIfNull": false
},
Current options:
{
"__className": "user",
"__path": "/lib/src/models",
"name": "Name",
"id": 1010
}
We'd have:
{
"__className": "user",
"__options": {
"toString": "Dart",
"equality": "Dart",
"targetDirectory": "/lib/src/models"
},
"name": "Name",
"id": 1010
}
If someone has a better solution please suggest it in the comment with examples that other users would vote for the best one. I would be very grateful for any suggestion.
This looks good, but if it's at all possible, I'd rather have separate models.jsonc
files for each module.
I'm currently working on a medium-sized project and my models.jsonc
file is already getting pretty long.
I'm currently working on a medium-sized project and my models.jsonc file is already getting pretty long.
I understand 😄 I personally comment every class and use hotkeys to fold everything.
This looks good, but if it's at all possible, I'd rather have separate
models.jsonc
files for each module.
Everything is possible, only time and work are required. I have created models.jsonc
file for easier and faster edit JSON objects and automate the work as much as possible. By splitting models file you will be forced to build your own builder options to tell the generator how you want to generate. That needs just finds a method how to do it with less work as possible and simple as possible.
@Prn-Ice Personal question. It would be good to run the generator by saving the file models.jsonc
after edit. (build on save)? Or is it not useful maybe?
@iamarnas that would be very useful, but only if I don't have to delete all the previously generated models first.
Currently, whenever I add a new model to my models.jsonc and run build models
, I get a pop-up warning me that one of the old models already exists.
I have to delete all the previous models and re-run just to see the new one.