Coder Social home page Coder Social logo

Comments (5)

marcinkonwiak avatar marcinkonwiak commented on June 5, 2024 1

Had the same problem. Try adding requirements to the first Get() operation.

For example if your IDs are in the UUID format add:
requirements: ['id' => '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}']

Then the 'invoice' part of the url won't be treated as the {id} in that first GET operation.

If you want to apply the same requirement to every operation you can do something like that:

<?php

namespace App\Service;

use Symfony\Component\Config\Loader\Loader;

class RouteRequirementEnforceLoader extends Loader
{
    private $decorated;

    public function __construct(Loader $decorated, ?string $env = null)
    {
        parent::__construct($env);
        $this->decorated = $decorated;
    }


    public function load($resource, string $type = null)
    {
        $routes = $this->decorated->load($resource, $type);

        foreach ($routes as $route) {
            $route->setRequirement('id', '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}');
        }

        return $routes;
    }

    public function supports($resource, string $type = null)
    {
        return $this->decorated->supports($resource, $type);
    }
}

and then add that to the services:

services:
    App\Service\RouteRequirementEnforceLoader:
        decorates: 'routing.loader'
        arguments: [ '@App\Service\RouteRequirementEnforceLoader.inner' ]

from api-platform.

gschafra avatar gschafra commented on June 5, 2024

Re-posted here: api-platform/core#6148. Unfortunately this is quite critical for us, as we want to avoid breaking changes as far as possible. Is there any chance that someone will take care of this problem? Or should we use commercial support?

from api-platform.

GerRubio avatar GerRubio commented on June 5, 2024

Hello. I have spent already like 3 days looking for some solutions to my problem and I think it is related with this issue.

I started a new project and I am using API Platform 3.2 too and PHP 8.2 but instead of getting an 404 error, I am getting an 405 error. This one in particular:

{"class":"Symfony\\Component\\HttpKernel\\Exception\\MethodNotAllowedHttpException","code":405,"message":"No route found for \"POST http://localhost:250/api/v1/users/register\": Method Not Allowed (Allow: GET, PUT, PATCH, DELETE)"}

This endpoint is for user register.

I am not using attributes directly in my PHP code, but I am using .yaml files instead. This my User.yaml file resources:

App\Entity\User:
  attributes:
    normalization_context:
      groups: [user_read]

  collectionOperations:

    # User register
    register:
      method: POST
      path: /users/register
      controller: App\Controller\Action\User\Register
      denormalization_context:
        groups: [user_register]
      openapi_context:
        summary: Register a new user

  itemOperations:
    get:
      method: GET

My question is if this issues is related, if not, I will open a new issue.

Thanks.

EDIT

I tried to downgrade to a previous version (3.0 and 3.1) but the problem is still there.

from api-platform.

nesl247 avatar nesl247 commented on June 5, 2024

If you move the get collection before the get it should fix it.

from api-platform.

soyuka avatar soyuka commented on June 5, 2024

duplicate

from api-platform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.