php-code-builder icon indicating copy to clipboard operation
php-code-builder copied to clipboard

Undefined variable error if description contains a dollar sign

Open mrbig opened this issue 11 months ago • 0 comments

Hello!

Thanks for the great package! Unfortunately I've encountered an error building a complex schema.

Given the following json schema:

{
  "type": "object",
  "description": "Description with $dollar sign",
  "properties": {
    "foo": {
      "type": "string"
    }
  }

The generated code fails with the following error: Undefined variable: dollar

The reason behind this is that the dollar sign is not escaped:

    public static function setUpProperties($properties, Schema $ownerSchema)
    {
        $properties->foo = Schema::string();
        $ownerSchema->type = Schema::OBJECT;
        $ownerSchema->description = "Description with $dollar sign";
    }

Excepted output would look similar to this:

    public static function setUpProperties($properties, Schema $ownerSchema)
    {
        $properties->foo = Schema::string();
        $ownerSchema->type = Schema::OBJECT;
        $ownerSchema->description = "Description with \$dollar sign";
    }

mrbig avatar Feb 15 '25 15:02 mrbig