question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can I change {id} to a different name?

See original GitHub issue

I am using api-platform with Symfony 4. It works fine, but I would like to change a GET url from: /booking/{id} to /booking/{bookingId} I’m using my own DTO object and custom data provider (not Doctrine ORM).

Here are the current @ApiResource and @ApiProperty definitions that work fine:

/**
 *
 * @ApiResource(
 *      itemOperations={
 *          "get"={
 *              "path"="/booking/{id}",
 *          },
 *          "api_bookings_get_item"={
 *              "swagger_context"={
 *                  "operationId"="getBookingItem",
 *                  "summary"="Retrieves details on a booking",
 *                  "parameters"= {
 *                      {
 *                          "name"="id",
 *                          "description"="Booking ID",
 *                          "default"="15000",
 *                          "in"="path",
 *                          "required"=true,
 *                          "type"="string"
 *                      }
 *                  },
 *                  "responses"={
 *                      "200"={
 *                          "description"="Results retrieved"
 *                      },
 *                      "404"={
 *                          "description"="Booking not found"
 *                      }
 *                  }
 *              }
 *          }
 *      },
 *      collectionOperations={}
 * )
 */
final class Booking
{
    /**
     * @var string
     * @Assert\NotBlank
     *
     * @ApiProperty(
     *    identifier=true,
     *    attributes={
     *        "swagger_context"={
     *            "description"="Booking ID",
     *            "required"=true,
     *            "type"="string",
     *            "example"="123456"
     *        }
     *     }
     * }
     */
     public $id;

     // other variables

 }

However, if I change all the references from 'id' to 'bookingId' it stops working and I get a 404 error. Here are the changes I made to the above code:

"path"="/booking/{bookingId}"

"name"="bookingId"

public $bookingId;

Is api-platform hard-coded to use 'id' as an identifier? Is there any way to change this?

From what I can tell, it appears to be hard-coded in the extractIdentifiers() function. I’ve been trying to figure out the code, but it is quite complex. I don’t know if making a change there will work or may have unintended consequences.

It seems to me that it should use whatever variable is tagged by the @apiProperty(identifier=true) annotation, but it does not appear to work like this. It appears that the getIdentifiersFromResourceClass() function that checks the identifier annotation is being called AFTER extractIdentifiers(), which does not make sense to me.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
soyukacommented, Apr 22, 2021

Wait what is your full example? You should specify a path and correlation between parameters => [class, property]:

path="/organization/{myCustomName}",
identifiers=["myCustomName" => [Organization::class, "identifier"]]
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Change Your Name on Your Driver's License
To change your name on your driver's license, you first have to change your name legally. When that's done, and you've already changed...
Read more >
Update Information on Your Driver's License or ID Card
Update your personal information on your driver's license or ID card. Change your name, change your address, or change your gender identity.
Read more >
How to change information on DMV documents
Change name · a completed Application for Permit, Driver License or Non-Driver ID Card (PDF) (MV-44) · your current license, permit or non-driver...
Read more >
How to Change Information on Your Driver License or ID Card
Visit any driver license office within 30 days of the change ; and; Provide one of the documents listed below that verifies your...
Read more >
Driver's License Name Change
A duplicate license will only be issued in the same name as currently on file with the SSA. This means you should update...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found