From 55633e1a25be7c0e42954543359f0a5ebc7bb107 Mon Sep 17 00:00:00 2001 From: Dragos Protung Date: Wed, 29 Nov 2023 14:23:03 +0100 Subject: [PATCH] Support 8.3 & Symfony 7 (#98) --- .github/workflows/build.yml | 1 + composer.json | 16 +++++------ config/phpstan-baseline.neon | 1 - config/phpunit.xml.dist | 6 +++-- .../SymfonyValidatorRequirementsDescriber.php | 27 ++++++++++--------- .../TestSchemaGeneration/Form/TestType.php | 2 +- 6 files changed, 29 insertions(+), 24 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8aa1eae..44458f2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/composer.json b/composer.json index df57c24..a094126 100644 --- a/composer.json +++ b/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": [ @@ -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": { @@ -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" }, diff --git a/config/phpstan-baseline.neon b/config/phpstan-baseline.neon index 537694b..15bd5cf 100644 --- a/config/phpstan-baseline.neon +++ b/config/phpstan-baseline.neon @@ -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 - diff --git a/config/phpunit.xml.dist b/config/phpunit.xml.dist index 8e1e2e4..aceaa60 100644 --- a/config/phpunit.xml.dist +++ b/config/phpunit.xml.dist @@ -1,5 +1,4 @@ - - + ../src + + + diff --git a/src/Describer/Form/SymfonyValidatorRequirementsDescriber.php b/src/Describer/Form/SymfonyValidatorRequirementsDescriber.php index 19a75f5..c4a8f49 100644 --- a/src/Describer/Form/SymfonyValidatorRequirementsDescriber.php +++ b/src/Describer/Form/SymfonyValidatorRequirementsDescriber.php @@ -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) { @@ -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; @@ -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)), diff --git a/tests/Integration/Fixtures/TestSchemaGeneration/Form/TestType.php b/tests/Integration/Fixtures/TestSchemaGeneration/Form/TestType.php index 596d645..8e91e3e 100644 --- a/tests/Integration/Fixtures/TestSchemaGeneration/Form/TestType.php +++ b/tests/Integration/Fixtures/TestSchemaGeneration/Form/TestType.php @@ -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()]])