api-platform icon indicating copy to clipboard operation
api-platform copied to clipboard

When read operations are explicitly defined, the documentation schema cannot be parsed by the admin panel

Open zpi12lmm opened this issue 10 months ago • 2 comments

API Platform version(s) affected: 4.1.1

Description
When I try to define the operations I need in the ApiResource attribute, the following error occurs on the admin panel side:

Error: Cannot fetch API documentation:
Cannot find the class related to https://localhost/docs.jsonld#Entrypoint/greeting.
Have you verified that CORS is correctly configured in your API?

How to reproduce
The easiest way to reproduce this error is to simply use this repository (clone it, or use it as a template), and modify the existing Greeting class, this is enough to get this error, for example, by default, the ApiResource attributes in the Greeting class are defined like this:

#[ApiResource(mercure: true)]

and I'm trying to define the following operations:

#[ApiResource(
    operations: [new GetCollection(), new Get()],
    mercure: true,
)]

Possible Solution
Probably, the problem is in the generation of the scheme for Hydra, because if you add the new Post() operation, then this error disappears. (I tried disabling the create action on the list page from the admin panel, but it had no effect)

Additional Context
I have another project based on ApiPlatform, where I first encountered this problem, but I have a fairly large ecosystem of technologies there, and the use of third-party libraries, so I thought it was caused by something else, so I first tried to investigate the problem there, I came to the conclusion that the error occurs at the stage of parsing the Hydra documentation.

zpi12lmm avatar Apr 05 '25 12:04 zpi12lmm

Hi, I would like to work on this issue. Could you please assign it to me?

asmadallaji avatar May 17 '25 11:05 asmadallaji

@asmadallaji yes, of course (I can only edit text in this issue, I can't assign)

zpi12lmm avatar May 18 '25 18:05 zpi12lmm