1

We have a rather standard symfony + api-platform project.

A while ago, when a route was created it had a typo in it. I noticed that and want to fix it for the future. The problem is that some of our clients may have implemented it already like that. I want it to still work for a while, without being exposed in documentation. I can take care of the documentation part by overriding the generator service so that's not a problem.

The problem is that I find no way to create an alias in api-platform. Any idea how I may go about that? The item operations definition looks like this:

 *         get"={
 *             "method"="GET",
 *             "path"="/pathWithTypo/{id}",
 *             "requirements"={"id"="[0-9A-Z]+-[0-9A-Z]+"},
 *             "normalization_context"={"groups"={"someGroup"}}
 *         }
3
  • 1
    I would do it in webserver (apache, nginx) configuration, with a RewriteRule. httpd.apache.org/docs/2.4/rewrite/remapping.html Commented Jun 2, 2021 at 7:33
  • Is not a bad idea. Although would've been great to add an alias as you do on controllers etc. Commented Jun 2, 2021 at 7:37
  • Have you tried to put the route in config/routes.yaml ? also with nelmio api doc you can filter out path you dont want to appear in the documentation (path_patterns). Commented Jun 2, 2021 at 7:50

1 Answer 1

4

Just copy "get" operation and name it different:

itemOperations={
    "get"={
        "method"="GET",
        "path"="/pathWithTypo/{id}",
        "requirements"={"id"="[0-9A-Z]+-[0-9A-Z]+"},
        "normalization_context"={"groups"={"someGroup"}}
    },
    "get_without_typo"={
        "method"="GET",
        "path"="/pathWithoutTypo/{id}",
        "requirements"={"id"="[0-9A-Z]+-[0-9A-Z]+"},
        "normalization_context"={"groups"={"someGroup"}}
    }

So, then you can easily remove old get operation and rename get_without_typo to get.

To remove some endpoints from the documentation - I have created my own option - remove_from_docs. I can share it with you.

Sign up to request clarification or add additional context in comments.

1 Comment

I'll give it a shot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.