8000 Impossible to set identifier on upper cased attribute · Issue #1026 · api-platform/core · GitHub
[go: up one dir, main page]

Skip to content
Impossible to set identifier on upper cased attribute #1026
@insekticid

Description

@insekticid

Upper Case attribute name example, that doesn't work:
Btw, there is no mention about @ApiProperty(identifier=true) in docs :/ !

    /**
     * @ApiProperty(identifier=true)
     */
    protected $Id;

Resource:

     AppBundle\Entity\Project:
         itemOperations:
                get:
                    method: 'GET'
                    path: '/project/{id}'

Request
curl -X GET --header 'Accept: application/ld+json' 'http://127.0.0.1:81/project/48'
Response:

{
  "@context": "/contexts/Error",
  "@type": "hydra:Error",
  "hydra:title": "An error occurred",
  "hydra:description": "Parameter \"id\" for route \"api_projects_get_item\" must match \"[^/]++\" (\"\" given) to generate a corresponding URL.",
"trace": [
    {
      "namespace": "",
      "short_class": "",
      "class": "",
      "type": "",
      "function": "",
      "file": "/srv/api-platform/vendor/symfony/symfony/src/Symfony/Component/Routing/Generator/UrlGenerator.php",
      "line": 163,

temporary solution is to define lower case attribute :

    /**
     * @var int
     */
    protected $Id = null;

    /**
     * @ApiProperty(identifier=true)
     * @var int
     */
    protected $id = null;

Why I had to use upper case name? Because of bad SOAP service naming convention from vendor

What about to define identifier in resource.yml?

AppBundle\Entity\Project:
         identifier: id
         itemOperations:
                get:
                    method: 'GET'
                    path: '/project/{id}'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0