-
-
Notifications
You must be signed in to change notification settings - Fork 895
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
[Swagger] Undefined array key "$ref" since 3.1.6 #5501
Comments
I get the same error on a decorated service, i.e: final readonly class JwtDecorator implements OpenApiFactoryInterface
{
public function __construct(
private OpenApiFactoryInterface $decorated,
private UrlGeneratorInterface $router
) {
}
public function __invoke(array $context = []): OpenApi
{
$openApi = ($this->decorated)($context); // <- This triggers the error.
... |
Hi, same problem since 3.1.6 with PHP 8.2.4 and Symfony 6.2.7. |
Same problem here |
Same problem here. This happens only for some schemas as far as I can tell, they are created in
without the $ref: https://i.imgur.com/0xVVun6.png Maybe related to Resources that have no (exposed) endpoints and thus no definition (yet)?
Also: I'm very suprised about the introduced BC break with that patch version: |
The problem exist in "dev" environment and not in "prod". |
I can confirm downgrading to 3.1.5 (PHP 8.1.11, Symfony 6.2.7) fix the problem. |
Hi, not sure from where the problem occurs: Can someone check if your use case breaks after introducing this commit? Also please send me a full stack trace!
My fault, I'll reintroduce this I shouldn't have removed it. |
Here is the stack trace I have for my part Warning: Undefined array key "$ref"
|
Is the patch e471622 the problem? I'd also like the resources you use or a way to reproduce to fix this asap |
@soyuka: I'm virtually certain it's that patch, but I'm in the middle of a code change and can't easier test it (I don't trust my git shelve changes skills...), but I checked before and I had the problem with 3.1.6 and not when I rolled back to 3.1.5. I suspect it's not the way that most people triggered the issue, but I was doing this: If you replace the ApiResource attribute on any Entity with I suspect declaring an Entity with only GetCollection operations would also show it - and be more realistic. |
@soyuka A simple resource having The simplest entity doc I tried to create which causes the bug looks like this #[ApiResource(
operations: [
new Metadata\GetCollection(
routeName: 'api_get_activitySector',
openapi: new Model\Operation(
responses: [
Response::HTTP_UNAUTHORIZED => new Model\Response(ResponseMessage::UNAUTHORIZED),
],
),
),
formats: ['json'],
normalizationContext: ['groups' => 'activitySector-read', 'swagger_definition_name' => 'Read'],
denormalizationContext: ['groups' => 'activitySector-write', 'swagger_definition_name' => 'Write'],
],
)] Whatever you put inside your entity does not matter. Maybe if you want to test it on a dummy API, you should put an id & a name. It should be enought. Also notice that - and as @cyrilverloop pointed out - I can confirm that the bug only appears in |
@soyuka After some digging & xdebug, it seems that the error occurs here core/src/JsonSchema/TypeFactory.php Lines 146 to 157 in ccef472
Because I would suggest something like this instead return ['$ref' => $subSchema->offsetExists('$ref') ? $subSchema->offsetGet('$ref') : null]; |
Odd. It definitely triggers it for me, but maybe we have something else different in our setups. Your example is definitely a more realistic one though. |
/edit: patch is no good Also can someone with the problem ping me on the Symfony slack? I still can't reproduce a failing test case and it's hard for me to find the correct fix. Just using an empty |
Is there a better way removing operations? |
I've a reproducer thanks to @paullallier, trying to release a patch by the end of the day! |
fixes api-platform#5501 The locations relation inside BrokenDocs is a Resource (named Related) but its only operation is a NotExposed. Still, serializer groups are set, and therefore it is a "readableLink" so we actually want to compute the schema, even if it's not accessible directly, it is accessible through that relation.
fixes api-platform#5501 The locations relation inside BrokenDocs is a Resource (named Related) but its only operation is a NotExposed. Still, serializer groups are set, and therefore it is a "readableLink" so we actually want to compute the schema, even if it's not accessible directly, it is accessible through that relation.
fixes #5501 The locations relation inside BrokenDocs is a Resource (named Related) but its only operation is a NotExposed. Still, serializer groups are set, and therefore it is a "readableLink" so we actually want to compute the schema, even if it's not accessible directly, it is accessible through that relation.
expect a release in the hour |
3.1.7 seems to fix the problem for me. Thanks ! |
API Platform version(s) affected: 3.1.6
Description
Since this new version, it is impossible to acces my swagger documentation via /api
For instance for a simple entrypoint like this one
causes a 500 error
Additional Context
I'm working on MacOs, Php 8.1, Symfony 6.2.7, doctrine-bundle 2.9.
Everything is working fine on 3.1.5
The text was updated successfully, but these errors were encountered: