Skip to content

dirty workaround found(?) for bug with oneOf validation #101

Description

@LukasGoTom

Describe the bug
workaround fix here: 5abb006

the issue will probably remain if its a merged property?

oneOf: validator tries to hand over originalModelData to function to create $modifiedValues. But the function expects the argument to be of type array, leading to a php runtime exception.

it's about this code:

$modifiedValues = array_merge($modifiedValues, $this->{{ modifiedValuesMethod }}($originalModelData, $value));

Expected behavior
Well no runtime exception. Optimally understand why the runtime exception happens.

Schema

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "/schemas/core/product.json",
    "title": "Product",
    "description": "Represents available advertising inventory",
    "type": "object",
    "properties": {
        "pricing_options": {
            "type": "array",
            "description": "Available pricing models for this product",
            "items": {
                "oneOf": [
                    {
                        "type": "object",
                        "properties": {
                            "min_spend_per_package": {
                                "type": "number",
                                "description": "Minimum spend requirement per package using this pricing option, in the specified currency",
                                "minimum": 0
                            }
                        }
                    },
                    {
                        "type": "object",
                        "properties": {
                            "pricing_option_id": {
                                "type": "string",
                                "description": "Unique identifier for this pricing option within the product (e.g., 'cpm_usd_auction')"
                            }
                        }
                    }
                ]
            },
            "minItems": 1
        }
    }
}

Additionally include custom GeneratorConfiguration settings.

    public function test_oneof_bug(): void
    {
        $namespace = 'Tests\Dto\Generator\WolSoft\ResultOneOfBug';
        $generator = new ModelGenerator(
            (new GeneratorConfiguration())
                ->setNamespacePrefix($namespace)
                ->setImmutable(false)
                ->addFormat('date', new AlwaysHappyValidator())
        );

        $file = __DIR__ . '/bugOneOf';
        $resultDir = __DIR__ . '/ResultOneOfBug';
        $generator->addPostProcessor(new BuilderClassPostProcessor());

        $generator
            ->generateModelDirectory($resultDir)
       

Version:
the improveRef one

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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