Skip to content

[Serializer] Fix XML example of ignoring an attribute #16824

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

Closed
wants to merge 1 commit into from
Closed

[Serializer] Fix XML example of ignoring an attribute #16824

wants to merge 1 commit into from

Conversation

likeuntomurphy
Copy link
Contributor

The XML example for configuring the Serializer to ignore an attribute is incorrect. It shows ignore as a child element of attribute instead of as an attribute of attribute.

This causes the following exception:

In XmlUtils.php line 107:

  [Symfony\Component\Config\Util\Exception\XmlParsingException]
  [ERROR 1871] Element '{http://symfony.com/schema/dic/serializer-mapping}ignore': This element is not expected. Expected is one of ( {http://symfony.com/schema/dic/seri
  alizer-mapping}group, {http://symfony.com/schema/dic/serializer-mapping}context, {http://symfony.com/schema/dic/serializer-mapping}normalization_context, {http://symfo
  ny.com/schema/dic/serializer-mapping}denormalization_context ).

@carsonbot carsonbot added this to the 5.4 milestone May 26, 2022
@likeuntomurphy likeuntomurphy changed the title Change ignore element to attribute in Serializer XML example [Serializer] Change ignore element to attribute in XML example May 26, 2022
@likeuntomurphy likeuntomurphy changed the title [Serializer] Change ignore element to attribute in XML example [Serializer] Fix XML example of ignoring an attribute Jun 5, 2022
@javiereguiluz
Copy link
Member

Thanks for reporting this issue.

We have a linter that checks the validity of code examples ... so this should have been detected. @OskarStark do you know why this wasn't reported by the linter? Thanks!

@OskarStark
Copy link
Contributor

If you mean DOCtor-RST it is only checking for valid XML structure, not the content. Not sure the code examples checker of @Nyholm provide such a feature 🤷

@Nyholm
Copy link
Member

Nyholm commented Jun 6, 2022

Code blocks checks is not active for xml. The main reason is that I had issues before and I haven’t come back to it.

symfony-tools/code-block-checker#17

@HeahDude
Copy link
Contributor

HeahDude commented Jun 7, 2022

symfony/symfony#46594 has been merged, and should at least partially fix the root of the problem.
Let me know if I can do something else to help moving forward on this XML stuff.

@javiereguiluz
Copy link
Member

I'm closing this as fixed because of what @HeahDude said.

If I misunderstood and we still to merge this, please tell me and I'll reopen. Thanks!

@xabbuh
Copy link
Member

xabbuh commented Oct 4, 2022

The linked code change was not related to the serializer configuration and thus does not affect this here, does it?

@HeahDude
Copy link
Contributor

HeahDude commented Oct 4, 2022

Yeah the merged PR allows the checker to do its job, the fix was probably legit though.
A rebase or rerunning the CI would definitely help here.

@HeahDude
Copy link
Contributor

HeahDude commented Oct 4, 2022

@likeuntomurphy
Copy link
Contributor Author

I rebased and force-pushed this morning, but GitHub is asking me to create a new PR. Maybe it will show up if this is reopened — but I also don’t mind running the code checker locally and addressing any other XML issues more comprehensively as new pull requests, if necessary.

@javiereguiluz
Copy link
Member

I cannot reopen 😐

@likeuntomurphy
Copy link
Contributor Author

Ultimately, it looks like there are a number of changes required across the code-checker utility and sample application to actually make it detect this invalid configuration.

First, the first line of the XML sample has to be a comment with the name of a config file that can be created in the sample app.

Secondly, the file path must begin with config/packages.

This doesn’t make sense for the Serializer, because its XML config files go in config/serializer. So the example config path would be config/serializer/App/Model/MyClass.xml. So XML serialization configuration files (and perhaps others?) are currently incompatible with the code checker.

I did create a file at that path in the sample app and even created an App\Model\MyClass class with a $bar property, but cache:warm still wouldn’t register an error — so there may be further required changes to the sample app, but I just gave up at that point. 😅

In light of this, I recreated this PR as #17327.

javiereguiluz added a commit to javiereguiluz/symfony-docs that referenced this pull request Oct 5, 2022
…bute redux (likeuntomurphy)

This PR was merged into the 5.4 branch.

Discussion
----------

[Serializer] Fix XML example of ignoring an attribute redux

This effectively reopens symfony#16824, which could not be reopened because of a rebase after the PR was closed.

Commits
-------

3c0734a Change 'ignore' element to attribute in Serializer XML example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants