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

plural class name #44

Closed Miamoto-Musashi closed 3 years ago

Miamoto-Musashi commented 3 years ago

Describe the bug models from array struct are generated in plural forms

To Reproduce given the json

{
    "__className": "Document",
    "title": "INSURANCE",
    "ownerOrganizationKey": "778a69f7-d98c-4464-859c-f700c7a33162",
    "status": "approved",
    "pages": [
      {
        "key": "5621f8a9-f05a-4469-bddf-0cdb56b24771-3",
        "image": null,
        "local_uri": "/var/mobile/Containers/Data/Application/2D3D40E2-4DBD-4364-A9D5-3F50732A63A0/Documents/camera/pictures/CAP_8C794E18-11AE-43CE-B8A8-B8395ED1F06A.jpg",
        "documentTitle": "INSURANCE",
        "documentKey": "5621f8a9-f05a-4469-bddf-0cdb56b24771"
      }
]
}

and using json generation the model generated is

class Pages{
....
}

Expected behavior Class name should be Page

Screenshots If applicable, add screenshots to help explain your problem.

Version 3.2.5

Json see above

Additional context using Jsonc file generation

iamarnas commented 3 years ago

@Miamoto-Musashi Hi.

I would not say that it's a bug. In this case JSON key pages for list object used for value name for type names as List<Pages> and for unnamed list object inside the pages list Pages. It possible to remove s letter but I don't know if not defect names and I'm not sure if all plural words have s at the end? Need to test.

Miamoto-Musashi commented 3 years ago

yes Is in the middle from a bug and an enhancement, let's say the expected behavior is to have List objects in the array not Pages, probably a simple implementation can start removing s at the end but then you need to consider noun like man/men, child/children and so on.

Probably introducing references between objects (see task #45 ) can solve both

Best

iamarnas commented 3 years ago

@Miamoto-Musashi I have consulted with a friend who speaks English. And he said that it would work 99% to remove only s at the end for the rest 1% he not garante 😁 From which word to delete s, the list value will say that word are the plural. I will fix it as soon as possible.

Ascenio commented 3 years ago

Just would like to add that there's some cases where trimming s isn't enough. Imagine countries for example, it should be changed to country, but then there might be i18n issues because I'm not sure if replacing ies by y always solves the problem.

iamarnas commented 3 years ago

Just would like to add that there's some cases where trimming s isn't enough. Imagine countries for example, it should be changed to country, but then there might be i18n issues because I'm not sure if replacing ies by y always solves the problem.

@Ascenio Thanks for the correction. You are right.