bogdandm / json2python-models

Generate Python model classes (pydantic, attrs, dataclasses) based on JSON datasets with typing module support
https://pypi.org/project/json2python-models/
MIT License
176 stars 14 forks source link

Keep plural names for objects #41

Open a1d4r opened 2 years ago

a1d4r commented 2 years ago

Describe

Plural names of JSON objects are converted to singular nouns (e.g. details -> Detail, statistics -> Statistic). It is an expected behaviour for JSON arrays but not for objects.

Reproduce

Package version: v0.2.4

JSON data: example.py

{
  "details": {
    "amount": 1,
    "description": "Lorem Ipsum"
  },
  "statistics": {
    "likes": 100,
    "comments": 200
  }
}

json2models -m Example example.json -f pydantic --max-strings-literals 1 > example.py

Desired result

class Example(BaseModel):
    details: 'Details'
    statistics: 'Statistics'

class Details(BaseModel):
    amount: int
    description: str

class Statistics(BaseModel):
    likes: int
    comments: int

Actual result

class Example(BaseModel):
    details: 'Detail'
    statistics: 'Statistic'

class Detail(BaseModel):
    amount: int
    description: str

class Statistic(BaseModel):
    likes: int
    comments: int
bogdandm commented 2 years ago

Thank you for reporting. I agree that it should work as you described. Unfortunately its requires some untrvial changes to the core logic of generator and currently I don't have time to impelement it.