Fixing using serializer groups along with other parsers #639
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the problem:
Some users (me included) have experienced problems using JMS Serializer groups along with Validation annotations. The problem was that the fields of the class specified as input or output were not filtered properly by the groups whenever the field had some Validation annotation attached to it.
The problem is originated by the fact that the parsers collect all the information available and after that, the results of each parser are added all together. So it doesn´t matter that the JMS Serializer groups skipped some of the fields of the input/output class, if the field was also visited by some other parser, it will be added to the final output result.
That also means that the groups were not working properly in combination with any other parser too, not only with Validation annotations.
Proposed solution:
This pull request proposes adding a new boolean field with key "excluded" to the data outputted by a parser about a input/output class field. That will allow a parser to mark a specific field as excluded and that information then will be shared to decide if the field should appear in the auto-generated docs or not.
The JmsMetadataParser has been modified to now check if a field should be skipped and if it should be skipped instead of just continue it sets "excluded" to true. The rest of the parsers, as they don´t have methods to exclude fields, have been modified to always return "excluded" as false.
The method.twig now check for the "excluded" field before rendering a field.
Tests modified
I have modified all the test related to parsers to expect the "excluded" field to be in the output generated. For the specific case of testing the JmsMetadataParser the tests related with groups have received deeper changes to maintain the new logic of not just skipping the fields that are not in specific groups.
Also the SimpleFormatterTest have been modified to take into account the new "excluded" field.
Looking forward to see your comments about it.
Thanks.