swaggest / php-json-schema

High definition PHP structures with JSON-schema based validation
MIT License
438 stars 50 forks source link

Failed to assign "const" value in ClassStructure definition #119

Closed vearutop closed 3 years ago

vearutop commented 3 years ago

Evaluation of the following class fails with error:

use Swaggest\JsonSchema\Constraint\Properties;
use Swaggest\JsonSchema\Schema;
use Swaggest\JsonSchema\Structure\ClassStructure;

class WithConst extends ClassStructure
{
    /** @var string */
    public $foo;

    /**
     * @param Properties|static $properties
     * @param Schema $ownerSchema
     */
    public static function setUpProperties($properties, Schema $ownerSchema)
    {
        $properties->foo = Schema::string();
        $properties->foo->const = "abc";

        $ownerSchema->type = Schema::OBJECT;
    }
}
Error : Call to undefined method stdClass::out()

Related to https://github.com/swaggest/php-code-builder/issues/40.