jacobdekeizer / json-to-php-generator

Generate PHP classes from json
https://jacobdekeizer.github.io/json-to-php-generator
MIT License
63 stars 18 forks source link

Duplicate classes #40

Open dbannik opened 1 year ago

dbannik commented 1 year ago

Source

{
    "elements": {
        "test": 1,
        "elements": [
            {
                "elements": {
                    "test": 1,
                    "elements": []
                }
            }
        ]
    }
}

Result

final class RootObject
{
    public Elements $elements;

}

final class Elements
{
    public int $test;
    /** @var Elements[] */
    public array $elements;

}

final class Elements
{
    public Elements $elements;

}

final class Elements
{
    public int $test;
    public array $elements;

}
jacobdekeizer commented 1 year ago

Hi,

Thank you for reporting this issue. I think we should add incrementing suffixes to nested classes with the same name to make it clear which object is being used. It's hard to determine which nested classes are of the same type, so we can't just merge the classes with the same name.

spatelwearpact commented 4 months ago

I ran into this as well. The duplicated files are identical and if they are they can be rendered only once.