Skip to content

Bug in BuilderClassPostProcessor: recursion #96

@LukasGoTom

Description

@LukasGoTom

Error is:

[docker-compose://[/home/lukas/projects/adcp-seller/docker-compose.yml]:app/]:php /app/vendor/phpunit/phpunit/phpunit --configuration /app/phpunit.xml --filter "/(Tests\\WolSoft\\WolSoftBugTester::test_generate_get_products_dtos_request_singlefile)( .*)?$/" --test-suffix WolSoftBugTester.php /app/tests/WolSoft --teamcity
Testing started at 15:18 ...
PHPUnit 11.5.44 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.28
Configuration: /app/phpunit.xml
Generated class MyTestWolsoftTest\App\Tests\WolSoft\Schemas\Schemascoreproductjson_schemascoreformatidjson
Duplicated signature 0c4d37432707e7bd6ab99fe523228230 for class Schemascoreproductjson_schemascoreformatidjson. Redirecting to Schemascoreproductjson_schemascoreformatidjson
Generated class MyTestWolsoftTest\App\Tests\WolSoft\Schemas\Schemascoreproductjson_Manifest692f034d98a4b
Generated class MyTestWolsoftTest\App\Tests\WolSoft\Schemas\Schemascoreproductjson_Product_card692f034d987ec
Duplicated signature e25f1d6b2791870d66f304613d419d12 for class Schemascoreproductjson_Manifest692f034d98e1b. Redirecting to Schemascoreproductjson_Manifest692f034d98a4b
Generated class MyTestWolsoftTest\App\Tests\WolSoft\Schemas\Schemascoreproductjson_Product_card_detailed692f034d98bba
Generated class MyTestWolsoftTest\App\Tests\WolSoft\Schemas\Schemascoreproductjson
Rendered class MyTestWolsoftTest\App\Tests\WolSoft\Schemas\Schemascoreproductjson_schemascoreformatidjson
Rendered class MyTestWolsoftTest\App\Tests\WolSoft\Schemas\Schemascoreproductjson_Manifest692f034d98a4b
Rendered class MyTestWolsoftTest\App\Tests\WolSoft\Schemas\Schemascoreproductjson_Product_card692f034d987ec
Rendered class MyTestWolsoftTest\App\Tests\WolSoft\Schemas\Schemascoreproductjson_Product_card_detailed692f034d98bba
Rendered class MyTestWolsoftTest\App\Tests\WolSoft\Schemas\Schemascoreproductjson

Error: Xdebug has detected a possible infinite loop, and aborted your script with a stack depth of '512' frames
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:127
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:125
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:122
/app/vendor/wol-soft/php-json-schema-model-generator/src/PropertyProcessor/Decorator/TypeHint/TypeHintTransferDecorator.php:27
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:131
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:122
/app/vendor/wol-soft/php-json-schema-model-generator/src/PropertyProcessor/Decorator/TypeHint/TypeHintTransferDecorator.php:27
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:131
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:122
/app/vendor/wol-soft/php-json-schema-model-generator/src/PropertyProcessor/Decorator/TypeHint/TypeHintTransferDecorator.php:27
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:131
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:122
/app/vendor/wol-soft/php-json-schema-model-generator/src/PropertyProcessor/Decorator/TypeHint/TypeHintTransferDecorator.php:27
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:131
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:122
/app/vendor/wol-soft/php-json-schema-model-generator/src/PropertyProcessor/Decorator/TypeHint/TypeHintTransferDecorator.php:27
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:131
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:122
/app/vendor/wol-soft/php-json-schema-model-generator/src/PropertyProcessor/Decorator/TypeHint/TypeHintTransferDecorator.php:27
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:131
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:122
/app/vendor/wol-soft/php-json-schema-model-generator/src/PropertyProcessor/Decorator/TypeHint/TypeHintTransferDecorator.php:27
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:131
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:122
/app/vendor/wol-soft/php-json-schema-model-generator/src/PropertyProcessor/Decorator/TypeHint/TypeHintTransferDecorator.php:27
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:131
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:122
/app/vendor/wol-soft/php-json-schema-model-generator/src/PropertyProcessor/Decorator/TypeHint/TypeHintTransferDecorator.php:27
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:131
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:122
/app/vendor/wol-soft/php-json-schema-model-generator/src/PropertyProcessor/Decorator/TypeHint/TypeHintTransferDecorator.php:27
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:131
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:122
/app/vendor/wol-soft/php-json-schema-model-generator/src/PropertyProcessor/Decorator/TypeHint/TypeHintTransferDecorator.php:27
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:131
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:122
/app/vendor/wol-soft/php-json-schema-model-generator/src/PropertyProcessor/Decorator/TypeHint/TypeHintTransferDecorator.php:27
...
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:131
/app/vendor/wol-soft/php-json-schema-model-generator/src/Model/Property/Property.php:122
/app/vendor/wol-soft/php-json-schema-model-generator/src/Utils/RenderHelper.php:111
/app/vendor/wol-soft/php-json-schema-model-generator/src/SchemaProcessor/PostProcessor/BuilderClassPostProcessor.php:113
/app/vendor/wol-soft/php-json-schema-model-generator/src/SchemaProcessor/PostProcessor/BuilderClassPostProcessor.php:73
/app/vendor/wol-soft/php-json-schema-model-generator/src/SchemaProcessor/RenderQueue.php:52
/app/vendor/wol-soft/php-json-schema-model-generator/src/ModelGenerator.php:119
/app/tests/WolSoft/WolSoftBugTester.php:43

my code (the actual test)

$config = new GeneratorConfiguration();
        $config->addFormat('uri', new AlwaysHappyValidator());
        $config->addFormat('date-time', new AlwaysHappyValidator());
        $config->addFormat('email', new AlwaysHappyValidator());
        $config->addFormat('date', new AlwaysHappyValidator());
        $config->addFormat('jpg', new AlwaysHappyValidator());
        $config->addFormat('mp4', new AlwaysHappyValidator());
        $generator = new ModelGenerator(
            ($config)
                ->setNamespacePrefix('MyTestWolsoftTest')
                ->setImmutable(false)
        );
        $generator->addPostProcessor(new BuilderClassPostProcessor());
        $resultDir = __DIR__ . '/result7builder';


        if (!is_dir($resultDir)) {
            mkdir($resultDir, 0777, true);
        }

        $generator
            ->generateModelDirectory($resultDir)
            ->generateModels(new SingleFileSchemaProvider(__DIR__ . '/schemas/product.json'), $resultDir);

        $this->assertDirectoryExists($resultDir);
        $this->assertTrue(true);

dependencies:

class SingleFileSchemaProvider implements SchemaProviderInterface
{
    private string $sourceDirectoryWithFile;

    /**
     * RecursiveDirectoryProvider constructor.
     *
     * @throws FileSystemException
     */
    public function __construct(string $sourceDirectoryWithFilename)
    {
        if (!is_file($sourceDirectoryWithFilename)) {
            throw new FileSystemException("Source directory with file '$sourceDirectoryWithFilename' doesn't exist");
        }

        $this->sourceDirectoryWithFile = rtrim($sourceDirectoryWithFilename, "\\/");
    }

    /**
     * @inheritDoc
     *
     * @throws SchemaException
     */
    public function getSchemas(): iterable
    {
        $file = $this->sourceDirectoryWithFile;
        $jsonSchema = file_get_contents($file);

        if (!$jsonSchema || !($decodedJsonSchema = json_decode($jsonSchema, true))) {
            throw new SchemaException("Invalid JSON-Schema file $file");
        }

        yield new JsonSchema($file, $decodedJsonSchema);
    }

    /**
     * @inheritDoc
     */
    public function getBaseDirectory(): string
    {
        return $this->sourceDirectoryWithFile;
    }
}

json schemas here:

schemas.zip

quick excerpt:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "/schemas/core/product.json",
    "title": "Product",
    "description": "Represents available advertising inventory",
    "type": "object",
    "properties": {
        "format_ids": {
            "type": "array",
            "description": "Array of supported creative format IDs - structured format_id objects with agent_url and id",
            "items": {
                "$ref": "/schemas/core/formatid.json"
            }
        },
        "product_card": {
            "type": "object",
            "description": "Optional standard visual card (300x400px) for displaying this product in user interfaces. Can be rendered via preview_creative or pre-generated.",
            "properties": {
                "format_id": {
                    "$ref": "/schemas/core/formatid.json",
                    "description": "Creative format defining the card layout (typically product_card_standard)"
                },
                "manifest": {
                    "type": "object",
                    "description": "Asset manifest for rendering the card, structure defined by the format",
                    "additionalProperties": true
                }
            },
            "required": [
                "format_id",
                "manifest"
            ],
            "additionalProperties": false
        },
        "product_card_detailed": {
            "type": "object",
            "description": "Optional detailed card with carousel and full specifications. Provides rich product presentation similar to media kit pages.",
            "properties": {
                "format_id": {
                    "$ref": "/schemas/core/formatid.json",
                    "description": "Creative format defining the detailed card layout (typically product_card_detailed)"
                },
                "manifest": {
                    "type": "object",
                    "description": "Asset manifest for rendering the detailed card, structure defined by the format",
                    "additionalProperties": true
                }
            },
            "required": [
                "format_id",
                "manifest"
            ],
            "additionalProperties": false
        }
    }
}

if I remove format_id from product_card_detailed it will work fine.

It works fine as well when not using BuilderClassPostProcessor

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions