Core: [Regression] 2.0.8 regresssion in resources.xml

Created on 15 May 2017  路  6Comments  路  Source: api-platform/core

I've updated to 2.0.8 just now and got an exception:

[ERROR 1845] Element 'resources': No matching global declaration available for the validation root. (in /app/web/ - line 2, column 0) in . (which is being imported from "/app/app/config/routing.yml").

Root cause was my resources.xml which didn't have a namespace declaration, like this:

<?xml version="1.0" encoding="UTF-8" ?>
<resources>
    <resource class="AppBundle\Entity\User">
        <attribute name="normalization_context">
            <attribute name="groups">
                <attribute>default</attribute>
                <attribute>read</attribute>
            </attribute>
        </attribute>
        <attribute name="denormalization_context">
            <attribute name="groups">
                <attribute>default</attribute>
                <attribute>create</attribute>
                <attribute>update</attribute>
            </attribute>
        </attribute>
    </resource>
</resources>

This works:

<?xml version="1.0" encoding="UTF-8" ?>
<resources xmlns="https://api-platform.com/schema/metadata"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="https://api-platform.com/schema/metadata
           https://api-platform.com/schema/metadata/metadata-2.0.xsd">
    <resource class="AppBundle\Entity\User">
        <attribute name="normalization_context">
            <attribute name="groups">
                <attribute>default</attribute>
                <attribute>read</attribute>
            </attribute>
        </attribute>
        <attribute name="denormalization_context">
            <attribute name="groups">
                <attribute>default</attribute>
                <attribute>create</attribute>
                <attribute>update</attribute>
            </attribute>
        </attribute>
    </resource>
</resources>

Most helpful comment

I would be nice to add a note in the changelog starting by [BC break], WDYT @api-platform/core-team?

All 6 comments

@scollado it is related to #1080. Can you take a look?

Commuting right now, I'll check if we can make namespace declaration optional as soon as I get back to a computer

@dunglas it seems that this is "normal behavior" when the XSD correctly defines elements namespaces.

The same behavior can be triggered with other Symfony components using XML configuration if you have config files without the provided namespace attributes.
I tested with Serializer & Validation components, I get the same error if I omit the namespace declaration in the root element (ex: Element 'serializer': No matching global declaration available for the validation root.)

What would you advise ? reverting XSD namespace declaration ? Adding a not in the Troubleshooting section & reviewing the doc to ensure there is no XML example missing namespace attributes ?

I would be nice to add a note in the changelog starting by [BC break], WDYT @api-platform/core-team?

Yeah, I think it's not a big deal.

I agree too

Was this page helpful?
0 / 5 - 0 ratings

Related issues

theshaunwalker picture theshaunwalker  路  3Comments

breitsmiley picture breitsmiley  路  3Comments

vViktorPL picture vViktorPL  路  3Comments

CvekCoding picture CvekCoding  路  3Comments

rockyweng picture rockyweng  路  3Comments