Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conflict with 2 of the same endpoints with different methods #2947

@silverbackdan

Description

@silverbackdan

API Platform version(s) affected: >4.2.0

Description
When I have defined 2 endpoints with a suffix for a resource,same suffix, different method, only the 2nd method defined now works. The error did not exist in 4.2.0 back on 24th September, but seems to have crept in somewhere in between as my tests now fail and I can confirm by changing the order of my definitions, the bug resolves for one method, and introduces for the other.

How to reproduce
My configuration (don't hate me) in XML

<resources xmlns="https://api-platform.com/schema/metadata/resources-3.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="https://api-platform.com/schema/metadata/resources-3.0
           https://api-platform.com/schema/metadata/resources-3.0.xsd">
    <resource class="Silverback\ApiComponentsBundle\Entity\Component\Form" output="Silverback\ApiComponentsBundle\Entity\Component\Form" provider="Silverback\ApiComponentsBundle\DataProvider\StateProvider\FormStateProvider">
        <operations>
            <operation class="ApiPlatform\Metadata\GetCollection" />
            <operation class="ApiPlatform\Metadata\Post" />
            <operation class="ApiPlatform\Metadata\Get" />
            <operation class="ApiPlatform\Metadata\Delete" />
            <operation class="ApiPlatform\Metadata\Put" />
            <operation class="ApiPlatform\Metadata\Patch" />
            <operation class="ApiPlatform\Metadata\Post"
                       name="_api_/forms/{id}/submit{._format}"
                       method="POST"
                       uriTemplate="/forms/{id}/submit{._format}"
                       read="true"
                       deserialize="false"
                       validate="false"
                       write="false"
                       serialize="true">
                <requirements>
                    <requirement property="id">[^/]+</requirement>
                </requirements>
            </operation>
            <operation class="ApiPlatform\Metadata\Patch"
                       name="_api_/forms/{id}/submit{._format}"
                       method="PATCH"
                       uriTemplate="/forms/{id}/submit{._format}"
                       read="true"
                       deserialize="false"
                       validate="false"
                       write="false"
                       serialize="true">
                <requirements>
                    <requirement property="id">[^/]+</requirement>
                </requirements>
            </operation>
        </operations>
    </resource>
</resources>

Possible Solution
Not sure yet, just discovered.

Additional Context
So the /submit endpoint for this resource in my case will only work for Patch in the example above. Move the Put to below the Patch definition and then Put will work and Patch will 405.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions