Skip to content

Commit

Permalink
Support 8.3 & Symfony 7 (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragosprotung committed Nov 29, 2023
1 parent aa98a46 commit 55633e1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 24 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Expand Up @@ -16,6 +16,7 @@ jobs:
php-versions:
- 8.1
- 8.2
- 8.3
name: PHP ${{ matrix.php-versions }} checks with ${{ matrix.dependencies }} dependencies
steps:
- name: Checkout code
Expand Down
16 changes: 8 additions & 8 deletions composer.json
@@ -1,6 +1,6 @@
{
"name": "protung/open-api-generator",
"description": "Open Api specification generator.",
"description": "Open Api specification / schema generator.",
"license": "MIT",
"type": "library",
"keywords": [
Expand All @@ -26,16 +26,16 @@
}
],
"require": {
"php": "~8.1.0 || ~8.2.0",
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"ext-json": "*",
"azjezz/psl": "^2.0.1",
"azjezz/psl": "^2.5.0",
"cebe/php-openapi": "^1.7.0",
"jms/serializer": "^3.22.0",
"myclabs/deep-copy": "^1.10",
"phpstan/phpdoc-parser": "^1.5.1",
"symfony/form": "^5.4 || ^6.0",
"symfony/routing": "^5.4 || ^6.0",
"symfony/validator": "^5.4 || ^6.0",
"symfony/form": "^6.4 || ^7.0",
"symfony/routing": "^6.4 || ^7.0",
"symfony/validator": "^6.4 || ^7.0",
"webmozart/assert": "^1.10"
},
"require-dev": {
Expand All @@ -51,8 +51,8 @@
"phpunit/phpunit": "^10.4.2",
"psalm/plugin-phpunit": "^0.18.4",
"roave/security-advisories": "dev-master",
"symfony/config": "^5.4 || ^6.2.5",
"symfony/var-dumper": "^5.4 || ^6.2.5",
"symfony/config": "^6.4 || ^7.0",
"symfony/var-dumper": "^6.4 || ^7.0",
"thecodingmachine/phpstan-strict-rules": "^1.0.0",
"vimeo/psalm": "^5.16.0"
},
Expand Down
1 change: 0 additions & 1 deletion config/phpstan-baseline.neon
Expand Up @@ -19,4 +19,3 @@ parameters:
message: "#^Property Protung\\\\OpenApiGenerator\\\\Tests\\\\Integration\\\\Fixtures\\\\TestSchemaGeneration\\\\Model\\\\JMS\\\\ComplexObject\\:\\:\\$unknownProperty has no type specified\\.$#"
count: 1
path: ../tests/Integration/Fixtures/TestSchemaGeneration/Model/JMS/ComplexObject.php

6 changes: 4 additions & 2 deletions config/phpunit.xml.dist
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.readthedocs.io/en/10.0/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../vendor/phpunit/phpunit/phpunit.xsd"
Expand All @@ -16,10 +15,13 @@
</testsuite>
</testsuites>

<coverage>
<source>
<include>
<directory>../src</directory>
</include>
</source>

<coverage>
<report>
<text outputFile="php://stdout" showOnlySummary="true"/>
</report>
Expand Down
27 changes: 15 additions & 12 deletions src/Describer/Form/SymfonyValidatorRequirementsDescriber.php
Expand Up @@ -185,14 +185,14 @@ private function describeConstraints(array $constraints, Schema $schema, FormInt

break;
case $constraint instanceof DivisibleBy:
$schema->multipleOf = $constraint->value;
$schema->multipleOf = Psl\Type\num()->coerce($constraint->value);
break;
case $constraint instanceof GreaterThan:
$schema->minimum = $constraint->value;
$schema->minimum = Psl\Type\num()->coerce($constraint->value);
$schema->exclusiveMinimum = true;
break;
case $constraint instanceof GreaterThanOrEqual:
$schema->minimum = $constraint->value;
$schema->minimum = Psl\Type\num()->coerce($constraint->value);
break;
case $constraint instanceof Length:
if ($constraint->min !== null) {
Expand All @@ -205,19 +205,19 @@ private function describeConstraints(array $constraints, Schema $schema, FormInt

break;
case $constraint instanceof LessThan:
$schema->maximum = $constraint->value;
$schema->maximum = Psl\Type\num()->coerce($constraint->value);
$schema->exclusiveMaximum = true;
break;
case $constraint instanceof LessThanOrEqual:
$schema->maximum = $constraint->value;
$schema->maximum = Psl\Type\num()->coerce($constraint->value);
break;
case $constraint instanceof Range:
if ($constraint->min !== null) {
$schema->minimum = $constraint->min;
$schema->minimum = Psl\Type\num()->coerce($constraint->min);
}

if ($constraint->max !== null) {
$schema->maximum = $constraint->max;
$schema->maximum = Psl\Type\num()->coerce($constraint->max);
}

break;
Expand All @@ -226,13 +226,16 @@ private function describeConstraints(array $constraints, Schema $schema, FormInt
break;
case $constraint instanceof Regex:
// we need to remove the delimiters but ignoring the modifiers
$schema->pattern = Psl\Str\slice(
Psl\Type\non_empty_string()->coerce(Psl\Str\before_last_ci($constraint->pattern, $constraint->pattern[0])),
1,
);
if ($constraint->pattern !== null) {
$schema->pattern = Psl\Str\slice(
Psl\Type\non_empty_string()->coerce(Psl\Str\before_last_ci($constraint->pattern, $constraint->pattern[0])),
1,
);
}

break;
case $constraint instanceof File:
if ($constraint->mimeTypes !== null && $constraint->mimeTypes !== []) {
if ($constraint->mimeTypes !== '' && $constraint->mimeTypes !== []) {
$schema->description = SpecificationDescriber::updateDescription(
$schema->description,
Psl\Str\format('Allowed mime types: %s', implode(', ', (array) $constraint->mimeTypes)),
Expand Down
Expand Up @@ -66,7 +66,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
['widget' => 'choice'],
)
->add('paramDateTimeSingleText', DateTimeType::class, ['widget' => 'single_text', 'years' => range(2015, 2025)])
->add('paramDateTimeChoice', DateTimeType::class, ['years' => range(2015, 2025)])
->add('paramDateTimeChoice', DateTimeType::class, ['widget' => 'choice', 'years' => range(2015, 2025)])
->add('paramTimeSingleText', TimeType::class, ['widget' => 'single_text'])
->add('paramTimeChoice', TimeType::class, ['widget' => 'choice', 'hours' => range(0, 15), 'minutes' => [10, 20, 50]])
->add('paramEmail', EmailType::class, ['constraints' => [new Unique()]])
Expand Down

0 comments on commit 55633e1

Please sign in to comment.