Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when generating typescript for an endpoint named "resource" #389

Open
kmcluckie opened this issue Nov 15, 2024 · 0 comments
Open

Error when generating typescript for an endpoint named "resource" #389

kmcluckie opened this issue Nov 15, 2024 · 0 comments

Comments

@kmcluckie
Copy link

API Platform version(s) affected: 4.0.8

Description
When generating typescript types using the command npm init @api-platform/client http://localhost apiTypes -- --generator typescript I get the following error:

Error: Cannot find the class related to http://localhost:8095/docs.jsonld#Entrypoint/resource.

This only occurs if I have an ApiResource/Entity named 'Resource'. Renaming it resolves the error.

How to reproduce
Create an API resource as below, and then runnpm init @api-platform/client http://localhost apiTypes -- --generator typescript:

namespace App\Entity;

use ApiPlatform\Metadata\ApiResource;
use App\Repository\ResourceRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;

#[ORM\Entity(repositoryClass: ResourceRepository::class)]
#[ApiResource]
class Resource
{
    #[ORM\Id]
    #[ORM\Column(type: 'uuid', unique: true)]
    private ?Uuid $id;

    #[ORM\Column(length: 255)]
    private ?string $name = null;

    #[ORM\Column]
    private ?\DateTimeImmutable $createdAt;

    public function getId(): ?Uuid
    {
        return $this->id;
    }

    public function __construct()
    {
        $this->id = Uuid::v4();
        $this->createdAt = new \DateTimeImmutable();
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): static
    {
        $this->name = $name;

        return $this;
    }

    public function getCreatedAt(): ?\DateTimeImmutable
    {
        return $this->createdAt;
    }

    public function setCreatedAt(\DateTimeImmutable $createdAt): static
    {
        $this->createdAt = $createdAt;

        return $this;
    }
}

Changing the shortname resolves the issue:

#[ApiResource(
    shortName: 'Res'
)]
> npm init @api-platform/client http://localhost apiTypes -- --generator typescript

Interface for the "Res" resource type has been generated!
Interface for the "User" resource type has been generated!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant