-
-
Notifications
You must be signed in to change notification settings - Fork 838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add jms/serializer enum support #2078
Conversation
@theofidry саn you review please? |
I unfortunately have no permissions on this package, only the Alice one. |
@GuilhemN саn you review please? |
Is there any update on this? |
@GuilhemN maybe you can help with review and merge this PR? |
Any updates on this? @GuilhemN could you please take a look at this small fix? |
@javer can you please write test(s) for this new feature? Also please rebase on master 😄 |
3858954
to
448ccb1
Compare
@DjordyKoert Done: rebased on master, added test and even fixed codestyle in master 😄 |
ModelDescriber/JMSModelDescriber.php
Outdated
@@ -282,6 +282,15 @@ public function describeItem(array $type, OA\Schema $property, Context $context) | |||
$property->type = 'string'; | |||
$property->format = 'date-time'; | |||
} else { | |||
// See https://github.com/schmittjoh/serializer/blob/master/src/Metadata/Driver/EnumPropertiesDriver.php#L51 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its better to make this a permalink
if ($this->flags & self::USE_JMS && \PHP_VERSION_ID >= 80100) { | ||
$c->loadFromExtension('jms_serializer', [ | ||
'enum_support' => true, | ||
]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jms_serializer.enum_support
defaults to false
even in PHP 8.1 or higher according to https://github.com/schmittjoh/JMSSerializerBundle/blob/master/Resources/doc/configuration.rst#extension-reference.
enum_support: true # PHP 8.1 Enums support, false by default for backward compatibility
Might be better to test both with false
& true
options by adding an additional flag for this? Gonna leave this one for @GuilhemN to decide if this is needed or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With enum_support: false
test passes even without my change in JMSModelDescriber
, so it would be strange to write a test which is not failing without the fix.
448ccb1
to
0929dc2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LGTM 👍 |
@javer could you rebase the conflicts? Thanks |
0929dc2
to
4adf93e
Compare
4adf93e
to
c6f647f
Compare
Done, rebased on the latest master, and all tests are green. |
Thank you @javer! |
jms/serializer
introduced enum support since v3.20 and added a new type: https://github.com/schmittjoh/serializer/blob/402a12629e3ad6d6897273769808a28c32745309/src/Metadata/Driver/EnumPropertiesDriver.php#L50And since
jms/serializer-bundle
v5.2.1 and schmittjoh/JMSSerializerBundle#919 withjms_serializer.enum_support: true
all existing models with enums got broken, because now enum properties are referenced to the fixed string#/components/schemas/enum
instead of the correct#/components/schemas/EnumClassName
:Before it was:
This PR adds support for enum type going from
jms/serializer
and returns the correct behavior.