[Schema] Support PHPStan/Psalm integer ranges (#422)
This commit is contained in:
parent
43815e38a8
commit
76778a4d9e
2 changed files with 32 additions and 2 deletions
|
|
@ -226,6 +226,21 @@ class SchemaGeneratorFixture
|
|||
): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* PHPStan/Psalm integer ranges should keep their base integer type.
|
||||
*
|
||||
* @param int<0, max> $offset Positive offset
|
||||
* @param int<min, -1> $negative Negative value
|
||||
* @param int<-5, 10> $bounded Bounded value
|
||||
*/
|
||||
public function integerRangeTypes(
|
||||
#[Schema(minimum: 0)]
|
||||
int $offset,
|
||||
int $negative,
|
||||
int $bounded,
|
||||
): void {
|
||||
}
|
||||
|
||||
// ===== ENUM SCENARIOS =====
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -190,6 +190,16 @@ final class SchemaGeneratorTest extends TestCase
|
|||
$this->assertEqualsCanonicalizing(['username', 'priority'], $schema['required']);
|
||||
}
|
||||
|
||||
public function testMapsPhpStanAndPsalmIntegerRangesToBaseIntegerType(): void
|
||||
{
|
||||
$method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'integerRangeTypes');
|
||||
$schema = $this->schemaGenerator->generate($method);
|
||||
|
||||
$this->assertEquals(['type' => 'integer', 'description' => 'Positive offset', 'minimum' => 0], $schema['properties']['offset']);
|
||||
$this->assertEquals(['type' => 'integer', 'description' => 'Negative value'], $schema['properties']['negative']);
|
||||
$this->assertEquals(['type' => 'integer', 'description' => 'Bounded value'], $schema['properties']['bounded']);
|
||||
}
|
||||
|
||||
public function testGeneratesCorrectSchemaForEnumParameters(): void
|
||||
{
|
||||
$method = new \ReflectionMethod(SchemaGeneratorFixture::class, 'enumParameters');
|
||||
|
|
|
|||
Loading…
Reference in a new issue