Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best practice for configuring JSON objects in the models.jsonc file #65

Open
iamarnas opened this issue Sep 28, 2021 · 7 comments
Open
Labels
enhancement New feature or request

Comments

@iamarnas
Copy link
Collaborator

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.

@iamarnas iamarnas pinned this issue Sep 28, 2021
@Prn-Ice
Copy link

Prn-Ice commented Sep 28, 2021

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.

@iamarnas
Copy link
Collaborator Author

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?

@Prn-Ice
Copy link

Prn-Ice commented Sep 29, 2021

@iamarnas that would be very useful, but only if I don't have to delete all the previously generated models first.

@iamarnas
Copy link
Collaborator Author

@iamarnas that would be very useful, but only if I don't have to delete all the previously generated models first.

@Prn-Ice It would not override generated models it would add only the new models. Json to Dart Model generator not override models and not remove generated models.

@Prn-Ice
Copy link

Prn-Ice commented Sep 29, 2021

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.

@iamarnas
Copy link
Collaborator Author

@Prn-Ice It would add only new object from the jsonc file. You get warning only when dublicates found. Looks like be changing path to the every json object not work as aspected.

@Prn-Ice
Copy link

Prn-Ice commented Sep 29, 2021

@iamarnas I see, it reads the models.jsonc file from top to bottom thats why.
I didnt add the new model to the top of the list.

@iamarnas iamarnas added the enhancement New feature or request label Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants